Java Code Examples for org.lwjgl.opengl.GL12#GL_CLAMP_TO_EDGE

The following examples show how to use org.lwjgl.opengl.GL12#GL_CLAMP_TO_EDGE . 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: TextureAttachment.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
private void setTextureParams(){
	int filterType = nearestFiltering ? GL11.GL_NEAREST : GL11.GL_LINEAR;
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filterType);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filterType);
	int wrapType = clampEdges ? GL12.GL_CLAMP_TO_EDGE : GL11.GL_REPEAT;
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, wrapType);
	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, wrapType);
}
 
Example 2
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 3
Source File: Texture.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static int bestWrap(int wrap) {
	if (wrap == GL12.GL_CLAMP_TO_EDGE && !GLContext.getCapabilities().OpenGL12) {
		return GL11.GL_CLAMP;
	} else
		return wrap;
}
 
Example 4
Source File: Texture.java    From mapwriter with MIT License 4 votes vote down vote up
public Texture(int w, int h, int fillColour) {
	this(w, h, fillColour, GL11.GL_LINEAR, GL11.GL_NEAREST, GL12.GL_CLAMP_TO_EDGE);
}