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 3 of 3

Thread: Texture rotation in glsl, opengl.

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    7

    Question Texture rotation in glsl, opengl.

    Hi, how to make a turn around the center of the texture, use glsl + opengl ? In old interface work this code
    Code :
      glPushAttrib(GL_TRANSFORM_BIT);
      glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glTranslatef(0.5, 0.5, 0);
      glRotatef(90, 0, 0, 1);
      glTranslatef(-0.5, -0.5, 0);
      glPopAttrib();
     
     
        glBegin(GL_QUADS);
          glTexCoord2d(0.0, 1.0);  glVertex2d(x1, y1);
          glTexCoord2d(0.0, 0.0);  glVertex2d(x2, y2);
          glTexCoord2d(1.0, 0.0);  glVertex2d(x3, y3);
          glTexCoord2d(1.0, 1.0);  glVertex2d(x4, y4);
        glEnd();

    In new interface i use matrix, but work only then x = y, then x != y texture resized.
    Matrix4 m1;
    m1.identity();

    m1.rotate(90, 0,0,1);
    Only 1 matrix, how rotate picture in original size? Rotate in z axis.

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,967
    This looks about right. If texture is scaled then you are rotating around the wrong axis, but 90 degrees would make it zero width so that's not it.

    Try LoadIdentity() on teh texture stack first and then change matrixmode back to GL_MODELVIEW when done.
    Also try translate -.5 then rotate then +.5 instead of the other way around.

    Note that this will rotate the texture on your quad but that texture will clip and clamp/repeat due to rasterization on the quad for anything other than 90 degree increments.

    Note that you are not rotating around the Z axis you are rotating around the r axis in tangent space.

  3. #3
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,967
    OK I think you are saying the old stuff worked and the new stuff doesn't....?

    Well to that I say that you are rotating about the origin, not the 0.5 0.5 center.
    Also your software math library would have to be compatible with your gl shaders and take angles in degrees (usually they take quaternions).
    Just because you have one matrix does not mean you are restricted to making one software call to set up that matrix.

Posting Permissions

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