PDA

View Full Version : rotating texture bigger than viewport



pfmaynard
04-29-2004, 02:14 PM
When I rotate my texture in a rectangular viewport, for most of the time (0 degrees and 180 degrees) the texture map deforms to fit the viewport. I think I know why this is happening - I've even tried my own simple attempts to adjust the texture coordinates using some trig, and nothing I've tried has fixed it - usually it just makes it look worse.

Is there an example, an algorithm, or a straight forward explanation of how to do this?

Thanks in advance

plasmonster
04-30-2004, 02:18 PM
I know of 2 ways to rotate an image. One way is to manipulate the texture matrix. The other method involves rotating the geometry instead.

Rotating the image with the texture matrix can lead to undesirable artifacts, unless the image is symmetric, or small in image space.

Your texture matrix method might look like this:

glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glTranslate( .5, .5, 0 );
glRotatef( angle, 0,0,1 );
glTranslatef( -.5, -.5, 0 );
// now draw a quad somewhere on the screen
// with unit tex coords (0,0) (0,1), (1,1) (1,0)

The geometric approach is usually better, as it avoids the problems above:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glTranslatef( quadX, quadY, 0 );
glRotatef( angle, 0,0,1 );
// now draw a quad centered at (0,0)
// with unit tex coords (0,0) (0,1), (1,1) (1,0)
...
glPopMatrix();

It all depends on the effect you're after.