OpenGL Rotation

Matt Mitchell picture Matt Mitchell · Aug 23, 2008 · Viewed 26.9k times · Source

I'm trying to do a simple rotation in OpenGL but must be missing the point. I'm not looking for a specific fix so much as a quick explanation or link that explains OpenGL rotation more generally.

At the moment I have code like this:

glPushMatrix();
  glRotatef(90.0, 0.0, 1.0, 0.0);
  glBegin(GL_TRIANGLES);        
    glVertex3f( 1.0, 1.0, 0.0 );        
    glVertex3f( 3.0, 2.0, 0.0 );        
    glVertex3f( 3.0, 1.0, 0.0 );        
  glEnd();
glPopMatrix();

But the result is not a triangle rotated 90 degrees.

Edit Hmm thanks to Mike Haboustak - it appeared my code was calling a SetCamera function that use glOrtho. I'm too new to OpenGL to have any idea of what this meant but disabling this and rotating in the Z-axis produced the desired result.

Answer

spate picture spate · Aug 23, 2008

Ensure that you're modifying the modelview matrix by putting the following before the glRotatef call:

glMatrixMode(GL_MODELVIEW);

Otherwise, you may be modifying either the projection or a texture matrix instead.