PDA

View Full Version : glMatrixMode( GL_TEXTURE )



jleffelm
03-10-2003, 07:55 AM
I had a quick question that I was hoping someone could help shed some light on. I recently found out how to use glMatrixMode( GL_TEXTURE ) to rotate a texture. From what I had been reading, it sounds like I should be able to produce a translation of the texture also, but I can't seem to get that to work(or it is working, and I am expecting something else to happen).

What I have right now, is a plane, with a texture on it, and when I do:


glMatrixMode( GL_TEXTURE );
glRotatef( angle, 0.0, 0.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
DrawPlane();
I get the texture to rotate, and it appears to be rotating around the (s,t)(0,0) corner of the texture(at least that is what I think I am seeing). Then I figured I would try adding a glTranslatef( x, y, z ) when GL_TEXTURE is set, and nothing happens. I was going to try and figure out a way to rotate the texture around the center point of the plane that I was creating. Can anyone explain how to do this, and possibly what glTranslate() does to the texture when called when GL_TEXTURE is set. Thanx.

-Drew

Deiussum
03-10-2003, 08:06 AM
Try this:




glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
glTranslatef(-0.5, -0.5, 0.0);
glMatrixMode(GL_MODELVIEW);
DrawPlane();


Edit: Added the glLoadIdentity so that on re-draw the translates/rotates don't become cumulative. This could also be avoided with appropriate usage of glPushMatrix/glPopMatrix

[This message has been edited by Deiussum (edited 03-10-2003).]

jleffelm
03-10-2003, 09:07 AM
Originally posted by Deiussum:
Try this:




glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5, 0.5, 0.0);
glRotatef(angle, 0.0, 0.0, 1.0);
glTranslatef(-0.5, -0.5, 0.0);
glMatrixMode(GL_MODELVIEW);
DrawPlane();


Edit: Added the glLoadIdentity so that on re-draw the translates/rotates don't become cumulative. This could also be avoided with appropriate usage of glPushMatrix/glPopMatrix

[This message has been edited by Deiussum (edited 03-10-2003).]

Thanx for the reply, I will try this later, is there any chance you could tell me what the translate, rotate, translate is doing to the texture so I can understand why this would work?

-Drew

Deiussum
03-10-2003, 09:51 AM
The same thing that it does for vertices.

TexCoords will be multiplied by the texture matrix before being applied. So if you do a translate of 0.5, 0.5, 0.0 it will add 0.5 to both the s and t parameters of glTexCoord2D.

It's possible that when you were testing it, you had the mode set to GL_REPEAT and were trying to translate by whole numbers.

Since (0,0) - (1,1) would be the same as (1,1) - (2,2) or (126,126) - (127,127) when you have repeating textures, it would have appeared to not do anything for you.