Rotating a texture

Hi

This should be rather simple, but i can’t get it to work.
Supose i have a quad, and i want the texture wich is binded to that quad to rotate, but the rotation should be done on the center of the quad.What i’m doing is the following :

glMatrixMode(GL_TEXTURE);
glTranslatef(0.5f,0.5f,0.0f);
glRotatef(angle,0,0,1.0f);
glTranslatef(-0.5f,-0.5f,0.0f);
glMatrixMode(GL_MODELVIEW);

What am i doing wrong ?

thanks,

Bruno

Switch the two glTranslatef instructions.
OpenGL matrices are left-multiplied, so the last matrix change is applied first.
And to prohibit matrix degeneration by applying the same angle over and over again, I’d suggest to call glLoadIdentity first and let the angle increase (modulo 360.0):

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

I really have nothing to say about this. It was a simple question with a simple answer.

And yes the matrices are all left multiplied in opengl. Meaning as said, the last matrix operation gets applied first. This is actually better when concatenated matrices for complex hierarchies for animation and the like.

****** I just wanted to clarify what I meant by better. Being left multiplied as it was put is what allows you to build a MODELVIEW matrix that converted everything to eye/camera space and then apply local transforms for the object on top of that matrix. A lot of books talk about having a separate local to world transform, then the world to camera/eye and then the projection. In this case the local to world is used for animation hierarchies and then the world to camera is applied on top of this. I believe directX/3d operates in this manner. In the end it really doesn’t make much difference. The end result should be the same. Opengl I believe simply believed that having one less matrix (and matrix stack) would be more efficient, and I believe they are right in that thinking.

Devulon

[This message has been edited by Devulon (edited 04-12-2002).]

Thanks guys, but it’s still not working…
I was told by a friend that the second translate should take into account the rotation that was made, but i still can’t figure it out…

I tried this too :

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(-0.5,-0.5,0.0);
glRotated(rot,0.0f,0.0f,1.0f);
glGetFloatv(GL_TEXTURE_MATRIX, m);
glTranslatef(0.5-m[3],0.5-m[7],0);
glMatrixMode(GL_MODELVIEW);

but…, still not working

Bruno,

This one will work,

glTranslatef( 0.5f, 0.5f, 0.0f );
glRotatef( AngleTime, 0.0f, 0.0f, 1.0f );
glTranslatef( -0.5f, -0.5f, 0.0f );

if(rotate_texture1)
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef( .5f, .5f, 0);
glRotatef(tx1rot, 0, 0, 1);
//glScalef(.7f, .7f,1);
glTranslatef(-.5f,-.5f, 0);
glMatrixMode(GL_MODELVIEW);
glActiveTextureARB(GL_TEXTURE0_ARB);
}

taken from there: http://developer.nvidia.com/view.asp?IO=Simple_Multitexturing_ogl

wich is what you want, don’t you?

it will work. bug is somewhere else… we’ll take a look this evening

see ya

I seem to remember that any changes to the texture matrix don’t actually happen unless texturing is enabled - ie. unless you’ve issued this command before doing your texture matrix manipulation:-
glEnable(GL_TEXTURE_2D);
…on the desired texture unit (if you’re doing multitexturing).

Don’t quote me on this, but I’m almost sure it’s true.
Maybe this is your problem?

Doh, sorry 'bout that, I take my first half of the answer back. Seems as if I confused deltas and coordinates.