A detailed look at implementing graphically demanding games in OpenGL with Java, using the JOGL library

Wednesday, February 11, 2009

Quick hint - Texture matrix

Just a quick note stemming from a week long bug hunt. The GL_TEXTURE matrix is per texture unit, so if you are using multiple texture units, be sure to get the right one active before pushing, popping or loading a new matrix! e.g.


gl.glMatrixMode(GL.GL_TEXTURE);
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glPushMatrix();
gl.glLoadIdentity();

...

gl.glPopMatrix();


Misunderstanding this feature can also easily lead to stack under flow if you change the active texture in between push and pop pairs.
Of course in retrospect, it's obvious that each texture unit needs its own matrix, but it's just one of those little details that's not well described in the man pages.

1 comment: