Java Code Examples for org.lwjgl.opengl.GL11#glDrawArrays()

The following examples show how to use org.lwjgl.opengl.GL11#glDrawArrays() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GL33Helper.java    From ldparteditor with MIT License 7 votes vote down vote up
public static void drawLinesRGB_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_LINES, 0, vertices.length);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 2
Source File: vboWithRGBA.java    From ldparteditor with MIT License 6 votes vote down vote up
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }
    
    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    
    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);
    
    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL30.glBindVertexArray(0);
    
    canvas.swapBuffers();
}
 
Example 3
Source File: GL33Helper.java    From ldparteditor with MIT License 6 votes vote down vote up
public static void drawTriangleVAO_GeneralSlow(float[] vertices) {
    int VAO_general = GL30.glGenVertexArrays();
    int VBO_general = GL15.glGenBuffers();
    GL30.glBindVertexArray(VAO_general);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);

    GL30.glBindVertexArray(0);
    GL30.glDeleteVertexArrays(VAO_general);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 4
Source File: VAOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Flush the currently cached data down to the card 
 */
private void flushBuffer() {	
	if (vertIndex == 0) {
		return;
	}
	if (currentType == NONE) {
		return;
	}
	
	if (vertIndex < TOLERANCE) {
		GL11.glBegin(currentType);
		for (int i=0;i<vertIndex;i++) {
			GL11.glColor4f(cols[(i*4)+0], cols[(i*4)+1], cols[(i*4)+2], cols[(i*4)+3]);
			GL11.glTexCoord2f(texs[(i*2)+0], texs[(i*2)+1]);
			GL11.glVertex3f(verts[(i*3)+0], verts[(i*3)+1], verts[(i*3)+2]);
		}
		GL11.glEnd();
		currentType = NONE;
		return;
	}
	vertices.clear();
	colors.clear();
	textures.clear();
	
	vertices.put(verts,0,vertIndex*3);
	colors.put(cols,0,vertIndex*4);
	textures.put(texs,0,vertIndex*2);
	
	vertices.flip(); 
	colors.flip(); 
	textures.flip(); 
	
	GL11.glVertexPointer(3,0,vertices);     
	GL11.glColorPointer(4,0,colors);     
	GL11.glTexCoordPointer(2,0,textures);     
	
	GL11.glDrawArrays(currentType, 0, vertIndex);
	currentType = NONE;
}
 
Example 5
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
private void renderCurve(int from, int to, int mirror) {
	// since there are len*2-1 points, subtract mirror index
	if (from > 0) {
		from -= mirror;
	}
	to -= mirror;
	for (int i = from; i < to - 1; ++i) {
		if (spliceFrom <= i && i <= spliceTo) {
			continue;
		}
		final int index = i + curve.length * mirror;
		GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, index * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
	}
}
 
Example 6
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
private void renderCurve(int mirror) {
	Iterator<Integer> iter = pointsToRender.iterator();
	while (iter.hasNext()) {
		for (int i = iter.next(), end = iter.next(); i < end; ++i) {
			final int index = i + curve.length * mirror;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, index * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
}
 
Example 7
Source File: GL33HelperPrimitives.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawLinesRGB_Line(float[] vertices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_line);
    GL15.glBufferSubData(GL15.GL_ARRAY_BUFFER, 0, vertices);
    
    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4
   
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    
    GL11.glDrawArrays(GL11.GL_LINES, 0, 2);
}
 
Example 8
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public void drawLinesRGB_General(float[] vertices) {
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 0);

    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, RGB_STRIDE, 12); // 3 * 4

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_LINES, 0, vertices.length);
}
 
Example 9
Source File: GL33Helper.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void drawTriangle_GeneralSlow(float[] vertices) {
    int VBO_general = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO_general);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STREAM_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 12, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL15.glDeleteBuffers(VBO_general);
}
 
Example 10
Source File: LwjglMesh.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void draw(final float xOffset, final float yOffset, final float zOffset)
{
	if (vertices == null)
		return;
	
	assert (numVertices > 0);
	
//	if (hasDisplayList)
	{
//		GL11.glCallList(displayList);
	}
//	else
	{
//		org.lwjgl.opengl.Util.checkGLError();
		
	//	displayList = GL11.glGenLists(1);
		
	//	GL11.glNewList(displayList, GL11.GL_COMPILE);
		{
			GL11.glPushMatrix();
			GL11.glTranslatef(xOffset, yOffset, zOffset);
			
			GL11.glDrawArrays(GL11.GL_QUADS, 0, numVertices);
			
			GL11.glPopMatrix();
		}
	//	GL11.glEndList();
		
	//	GL11.glCallList(displayList);
		
	//	hasDisplayList = true;
		
	//	org.lwjgl.opengl.Util.checkGLError();
	}
}
 
Example 11
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 12
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int to) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform4f(staticState.colLoc, color.r, color.g, color.b, color.a);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);

	float lastSegmentX = to == 0 ? curve[1].x - curve[0].x : curve[to].x - curve[to-1].x;
	float lastSegmentY = to == 0 ? curve[1].y - curve[0].y : curve[to].y - curve[to-1].y;
	float lastSegmentInvLen = 1.f/(float)Math.hypot(lastSegmentX, lastSegmentY);
	GL20.glUniform4f(staticState.endPointLoc, curve[to].x, curve[to].y, lastSegmentX * lastSegmentInvLen, lastSegmentY * lastSegmentInvLen);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);

	GL11.glColorMask(false,false,false,false);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glColorMask(true,true,true,true);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glDepthFunc(GL11.GL_EQUAL);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, pointIndices[to]);
	GL11.glDepthFunc(GL11.GL_LESS);

	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 13
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
public void drawTrianglesWithTextureColored(TextureHandle textureid, GeometryHandle shapeHandle, GeometryHandle colorHandle, int offset, int lines, int width, int stride, float x, float y) {
	bindTexture(textureid);
	int starti = offset < 0 ? (int)Math.ceil(-offset/(float)stride) : 0;

	if(lsz != -1) GL11.glPopMatrix();
	GL11.glPushMatrix();
	GL11.glTranslatef(x, y, -.1f);
	GL11.glScalef(1, 1, 0);
	GL11.glMultMatrixf(heightMatrix);

	if(!tex_coord_on) {
		GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
		tex_coord_on = true;
	}

	bindGeometry(shapeHandle);
	GL11.glVertexPointer(3, GL11.GL_FLOAT, 5 * 4, 0);
	GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 5 * 4, 3 * 4);

	bindGeometry(colorHandle);
	GL11.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, 0);

	GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
	for (int i = starti; i != lines; i++) {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, (offset + stride * i) * 3, width * 3);
	}
	GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);

	GL11.glPopMatrix();
	lsz = -1;
}
 
Example 14
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
public void draw2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) {
	if(lx != x || ly != y || lz != z || lsx != sx || lsy != sy || lsz != sz) {
		if(lsz != -1) GL11.glPopMatrix();
		GL11.glPushMatrix();
		if(x != 0 || y != 0 || z != 0) GL11.glTranslatef(x, y, z);
		if(sx != 1 || sy != 1 || sz != 1) GL11.glScalef(sx, sy, sz);
		lx = x; lsx = sx;
		ly = y; lsy = sy;
		lz = z; lsz = sz;
	}

	if(color != null) {
		float r = color.red*intensity;
		float g = color.green*intensity;
		float b = color.blue*intensity;
		float a = color.alpha;
		if(lr != r || lg != g || lb != b || la != a) GL11.glColor4f(lr=r, lg=g, lb=b, la=a);
	} else {
		if(lr != lg || lr != lb || lr != intensity || la != 1) GL11.glColor4f(intensity, intensity, intensity, 1);
		lr = lg = lb = intensity;
		la = 1;
	}

	bindTexture(texture);
	bindGeometry(geometry);
	EGeometryFormatType format = geometry.getFormat();

	if(format.getTexCoordPos() == -1) GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

	specifyFormat(format);
	GL11.glDrawArrays(primitive, offset * vertices, vertices);

	if(format.getTexCoordPos() == -1) GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
}
 
Example 15
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void drawTrianglesWithTextureColored(TextureHandle textureid, GeometryHandle shapeHandle, GeometryHandle colorHandle, int offset, int lines, int width, int stride, float x, float y) {
	bindTexture(textureid);

	if(backgroundVAO == -1) {
		if(glcaps.GL_ARB_vertex_array_object) {
			backgroundVAO = ARBVertexArrayObject.glGenVertexArrays();
			bindFormat(backgroundVAO);
		}
		GL20.glEnableVertexAttribArray(0);
		GL20.glEnableVertexAttribArray(1);
		GL20.glEnableVertexAttribArray(2);

		bindGeometry(shapeHandle);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 5 * 4, 0);
		GL20.glVertexAttribPointer(1, 2, GL11.GL_FLOAT, false, 5 * 4, 3 * 4);

		bindGeometry(colorHandle);
		GL20.glVertexAttribPointer(2, 1, GL11.GL_FLOAT, false, 0, 0);

		setObjectLabel(GL11.GL_VERTEX_ARRAY, backgroundVAO, "background-vao");
		setObjectLabel(KHRDebug.GL_BUFFER, shapeHandle.getInternalId(), "background-shape");
		setObjectLabel(KHRDebug.GL_BUFFER, colorHandle.getInternalId(), "background-color");
	}
	int starti = offset < 0 ? (int)Math.ceil(-offset/(float)stride) : 0;

	useProgram(prog_background);

	GL20.glUniform2f(prog_background.ufs[TRANS], x, y);

	bindFormat(backgroundVAO);
	for (int i = starti; i != lines; i++) {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, (offset + stride * i) * 3, width * 3);
	}
}
 
Example 16
Source File: IslandGenerator.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static Texture[][] blendTextures(OffscreenRendererFactory factory, int chunks_per_colormap, BlendInfo[] blend_infos, int alpha_size, int structure_size, int scale) {
		boolean use_pbuffer = Settings.getSettings().usePbuffer();
		boolean use_fbo = Settings.getSettings().useFBO();
		OffscreenRenderer offscreen = factory.createRenderer(TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, new PixelFormat(Globals.VIEW_BIT_DEPTH, 0, 0, 0, 0), Settings.getSettings().use_copyteximage, use_pbuffer, use_fbo);
		GL11.glColor4f(1f, 1f, 1f, 1f);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0f, TEXELS_PER_CHUNK, 0, TEXELS_PER_CHUNK, -1f, 1f);

		GL11.glMatrixMode(GL11.GL_TEXTURE);
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glLoadIdentity();
		GLState.activeTexture(GL13.GL_TEXTURE0);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glLoadIdentity();
		GL11.glMatrixMode(GL11.GL_MODELVIEW);

		float alpha_texel_size = 1f/(alpha_size*scale);
		float structure_texel_size = 1f/structure_size;
		float structure_texels_per_chunk_border = Globals.TEXELS_PER_CHUNK_BORDER*structure_texel_size;
		float structure_offset = TEXELS_PER_CHUNK*structure_texel_size - 2*structure_texels_per_chunk_border;
		float structure_length = structure_offset + 2*structure_texels_per_chunk_border;

		float alpha_texels_per_chunk_border = Globals.TEXELS_PER_CHUNK_BORDER*alpha_texel_size;
		float alpha_offset = TEXELS_PER_CHUNK*alpha_texel_size;
		float alpha_length = alpha_offset + 2*alpha_texels_per_chunk_border;

		Texture[][] chunk_maps = new Texture[chunks_per_colormap][chunks_per_colormap];
		FloatBuffer coordinates = BufferUtils.createFloatBuffer(4*3);
		coordinates.put(new float[]{0f, 0f, 0f,
									TEXELS_PER_CHUNK, 0f, 0f,
									TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, 0f,
									0f, TEXELS_PER_CHUNK, 0f});
		coordinates.rewind();
		FloatBuffer structure_tex_coords = BufferUtils.createFloatBuffer(4*2);
		FloatBuffer alpha_tex_coords = BufferUtils.createFloatBuffer(4*2);
		GLStateStack.switchState(GLState.VERTEX_ARRAY | GLState.TEXCOORD0_ARRAY | GLState.TEXCOORD1_ARRAY);
		GL11.glVertexPointer(3, 0, coordinates);
		GL11.glTexCoordPointer(2, 0, structure_tex_coords);
		GLState.clientActiveTexture(GL13.GL_TEXTURE1);
		GL11.glTexCoordPointer(2, 0, alpha_tex_coords);
		GLState.clientActiveTexture(GL13.GL_TEXTURE0);
		for (int y = 0; y < chunk_maps.length; y++) {
			for (int x = 0; x < chunk_maps[y].length; x++) {
				chunk_maps[y][x] = new Texture(TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, GL11.GL_LINEAR_MIPMAP_NEAREST, GL11.GL_LINEAR, GL12.GL_CLAMP_TO_EDGE, GL12.GL_CLAMP_TO_EDGE, Globals.NO_MIPMAP_CUTOFF);
				int mip_scale = 1;
				int mip_level = 0;
				int mip_size = TEXELS_PER_CHUNK;
				while (mip_size >= 1) {
					GL11.glLoadIdentity();
					GL11.glScalef(1f/mip_scale, 1f/mip_scale, 1f);
					GL11.glEnable(GL11.GL_BLEND);

					for (int i = 0; i < blend_infos.length; i++) {
						blend_infos[i].setup();
						float structure_offset_u = x*structure_offset - structure_texels_per_chunk_border;
						float structure_offset_v = y*structure_offset - structure_texels_per_chunk_border;
						float alpha_offset_u = x*alpha_offset - alpha_texels_per_chunk_border;
						float alpha_offset_v = y*alpha_offset - alpha_texels_per_chunk_border;
						structure_tex_coords.put(0, structure_offset_u).put(1, structure_offset_v);
						structure_tex_coords.put(2, structure_offset_u + structure_length).put(3, structure_offset_v);
						structure_tex_coords.put(4, structure_offset_u + structure_length).put(5, structure_offset_v + structure_length);
						structure_tex_coords.put(6, structure_offset_u).put(7, structure_offset_v + structure_length);
						alpha_tex_coords.put(0, alpha_offset_u).put(1, alpha_offset_v);
						alpha_tex_coords.put(2, alpha_offset_u + alpha_length).put(3, alpha_offset_v);
						alpha_tex_coords.put(4, alpha_offset_u + alpha_length).put(5, alpha_offset_v + alpha_length);
						alpha_tex_coords.put(6, alpha_offset_u).put(7, alpha_offset_v + alpha_length);
						GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
						blend_infos[i].reset();
					}
/*if (mip_level == 0)
offscreen.dumpToFile("colormap-" + x + "-" + y);*/
					offscreen.copyToTexture(chunk_maps[y][x], mip_level, Globals.COMPRESSED_RGB_FORMAT, 0, 0, mip_size, mip_size);
					mip_scale <<= 1;
					mip_level++;
					mip_size >>= 1;
				}
			}
		}
		boolean succeeded = offscreen.destroy();
		if (!succeeded) {
/*			for (int y = 0; y < chunk_maps.length; y++)
				for (int x = 0; x < chunk_maps[y].length; x++)
					chunk_maps[y][x].delete();*/
			return null;
		} else
			return chunk_maps;
	}
 
Example 17
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void drawUnified2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, boolean image, boolean shadow, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity) {
	useProgram(prog_unified);
	bindTexture(texture);

	if(image) {
		float r, g, b, a;
		if (color != null) {
			r = color.red * intensity;
			g = color.green * intensity;
			b = color.blue * intensity;
			a = color.alpha;
		} else {
			r = g = b = intensity;
			a = 1;
		}

		if(ulr != r || ulg != g || ulb != b || ula != a) {
			ulr = r;
			ulg = g;
			ulb = b;
			ula = a;
			GL20.glUniform4f(prog_unified.ufs[COLOR], r, g, b, a);
		}
	}

	if(ulim != image || ulsh != shadow || uli != intensity) {
		GL20.glUniform3f(prog_unified.ufs[UNI_INFO], image?1:0, shadow?1:0, intensity);
		ulim = image;
		ulsh = shadow;
		uli = intensity;
	}

	GL20.glUniform3fv(lastProgram.ufs[TRANS], new float[] {x, y, z, sx, sy, sz});

	if(glcaps.GL_ARB_vertex_array_object) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GL11.glDrawArrays(primitive, offset*vertices, vertices);
}
 
Example 18
Source File: LWJGL20DrawContext.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void draw2D(GeometryHandle geometry, TextureHandle texture, int primitive, int offset, int vertices, float x, float y, float z, float sx, float sy, float sz, AbstractColor color, float intensity){
	boolean changeColor = false;

	float r, g, b, a;
	if(color != null) {
		r = color.red*intensity;
		g = color.green*intensity;
		b = color.blue*intensity;
		a = color.alpha;
	} else {
		r = g = b = intensity;
		a = 1;
	}

	if(texture == null) {
		useProgram(prog_color);
		if(clr != r || clg != g || clb != b || cla != a) {
			clr = r;
			clg = g;
			clb = b;
			cla = a;
			changeColor = true;
		}
	} else {
		bindTexture(texture);
		useProgram(prog_tex);
		if(tlr != r || tlg != g || tlb != b || tla != a) {
			tlr = r;
			tlg = g;
			tlb = b;
			tla = a;
			changeColor = true;
		}
	}

	GL20.glUniform3fv(lastProgram.ufs[TRANS], new float[] {x, y, z, sx, sy, sz});

	if(changeColor) {
		GL20.glUniform4f(lastProgram.ufs[COLOR], r, g, b, a);
	}

	if(glcaps.GL_ARB_vertex_array_object) {
		bindFormat(geometry.getInternalFormatId());
	} else {
		bindGeometry(geometry);
		specifyFormat(geometry.getFormat());
	}
	GL11.glDrawArrays(primitive, offset*vertices, vertices);
}
 
Example 19
Source File: TerrainRenderer.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Renders a terrain to the screen. If the terrain has an index buffer the
 * glDrawElements is used. Otherwise glDrawArrays is used.
 * 
 * @param terrain
 *            - The terrain to be rendered.
 * @param camera
 *            - The camera being used for rendering the terrain.
 * @param light
 *            - The light being used to iluminate the terrain.
 * 
 * @param clipPlane
 *            - The equation of the clipping plane to be used when rendering
 *            the terrain. The clipping planes cut off anything in the scene
 *            that is rendered outside of the plane.
 */
public void render(Terrain terrain, ICamera camera, Light light, Vector4f clipPlane) {
	prepare(terrain, camera, light, clipPlane);
	if (hasIndices) {
		GL11.glDrawElements(GL11.GL_TRIANGLES, terrain.getVertexCount(), GL11.GL_UNSIGNED_INT, 0);
	} else {
		GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, terrain.getVertexCount());
	}
	finish(terrain);
}
 
Example 20
Source File: WaterRenderer.java    From LowPolyWater with The Unlicense 3 votes vote down vote up
/**
 * Renders the water. The render call here is "glDrawArrays" instead of
 * "glDrawElements" because no vertices are shared, so indices would be
 * pointless.
 * 
 * @param water
 *            - The water being rendered.
 * @param camera
 *            - The camera being used to render the water.
 * @param light
 *            - The light in the scene.
 * @param reflectionTexture
 *            - The reflection texture - an image of the scene taken with an
 *            inverted camera. This will be applied to the water's surface
 *            to simulate reflection.
 * @param refractionTexture
 *            - The refraction texture - and image of the scene from the
 *            camera's current position that will be applied to the water
 *            mesh to simulate refraction. A texture is used here so that it
 *            can be distorted, but if no distortion is required then the
 *            same effect could be achieved using alpha blending.
 * @param depthTexture
 *            - An image of the depth buffer for the scene. This is used to
 *            apply depth effects to the water.
 */
public void render(WaterTile water, ICamera camera, Light light, int reflectionTexture, int refractionTexture,
		int depthTexture) {
	prepare(water, camera, light);
	bindTextures(reflectionTexture, refractionTexture, depthTexture);
	GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, water.getVertexCount());
	finish(water);
}