What does this code in a textureloader do?


		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
		GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

I saw this code being used after a texture ID was generated and bound, and before the texture ID is returned to where it’ll be rendered. Whatever it is, it works, and the texture doesn’t show without it. Can someone please explain what it means? I’d rather not use it without knowing what it actually is.

The first two lines describe how to handle texture coordinates outside of the range [0 - 1], and the following two lines describe how to handle filtering on minification (scaling down) and magnification (scaling up). The example here uses “nearest neighbour” filtering which means hard edges will be preserved (i.e. nice for “8bit retro” effect). An alternative would be GL_LINEAR which results in a smoother scaling.

Since texture wrap uses GL_CLAMP_TO_EDGE (notice it requires OpenGL 1.2), texcoords outside of the [0-1] range will use the nearest edge color.

You can change these parameters after creating your texture, e.g. if you wanted to change the filtering.

As for why the texture won’t show without this code – that’s because, by default, the minification filter expects mipmaps, and since you haven’t defined/generated any, the texture will be invalid (and thus won’t render). If you aren’t using mipmaps, then you need to use GL_NEAREST or GL_LINEAR for your min/mag filters.

More info:
http://www.flipcode.com/archives/Advanced_OpenGL_Texture_Mapping.shtml

Wow, flipcode. Now those were the days. Really sad that the site closed down :frowning: