Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: rotating texture bigger than viewport

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    8

    rotating texture bigger than viewport

    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

  2. #2
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: rotating texture bigger than viewport

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •