Sign in to follow this  

Rotating a Texture on a Quad

This topic is 3376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'd be ever so grateful if you know and give the answer to this: I'm trying to put a texture image on a quad, then constantly rotating it around the z axis (say a smiley face on a square). But somehow it keeps tiling the image or distorting it. I've bound the texture to a square in a function called drawTexRect() using glTexCoord2f and glVertex3f with every corner of the square being a bit inside the texture i.e., going from 0.2 to 0.8 , I've experimented with other mappings too. and then: float angle = 0.1, glBindTexture(GL_TEXTURE_2D, tex); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glRotatef(angle, 0.0, 0.0, 1.0); glMatrixMode(GL_MODEL_VIEW); drawTexRect(); then the angle become angle+= 0.1 in my animateFunction so that the image keeps rotating. I've even tried glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); but the image kept moving out of the quad. Many thanks

Share this post


Link to post
Share on other sites
>>but the image kept moving out of the quad.
most likely since the rotation happens around 0,0 but u want it to happen at 0.5,0.5 the center of the quad

anyways better if do the rotation yourself

float c = cosf(rot);
float s = sinf(rot);

glTexCoord2f( 0.5+c, 0.5+s );
glTexCoord2f( 0.5+s, 0.5-c );
glTexCoord2f( 0.5-c, 0.5-s );
glTexCoord2f( 0.5-s, 0.5+c );

Share this post


Link to post
Share on other sites
Quote:
Original post by zedz
>>but the image kept moving out of the quad.
most likely since the rotation happens around 0,0 but u want it to happen at 0.5,0.5 the center of the quad


Probably but it's better to use the matrix to deal with animation.

3. glTranslatef(0.5, 0.5, 0.0);
2. glRotatef(angle, 0.0, 0.0, 1.0);
1. glTranslatef(-0.5, -0.5, 0.0);

1. moves the center {0.5, 0.5) at the {0, 0} point.
2. Does the rotation.
3. Restores the translation to where it was.

Share this post


Link to post
Share on other sites

This topic is 3376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this