Search code examples
javaopengllwjgl

Texture error when using glScale


Im drawing using immediate mode in LWJGL to draw quads(yes I know its deprecated and VBO's are a better alternative) but when using glScaled to zoom in certain textures are cut off the bottom or the sides and a line is drawn above them. It is only visible when zoomed in and is more prevalent the farther zoomed All the images I use are made as a power of 2 i.e. 64 128 etc

Hopefully from this image you can see more clearly what I mean:

Texture Error Image
Texture Error Image


Solution

  • Your screenshot looks like the texture coordinate is wrapped.

    Try calling glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); and same for GL_TEXTURE_WRAP_T. Or, depending on the OpenGL version, you might need GL_CLAMP_TO_EDGE value instead, again, for both GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T texture parameters. The correct moment to set texture parameters is after glActiveTexture & glBindTexture but before glBegin.

    You probably didn’t change these two parameters, the default for them is GL_REPEAT, and that’s what causes the artifact.