# glRotatef in ortho perspective

Hi all,
I had aspired to use ortho perspective but I’ve discovered that rotation about the x axis doesn’t work properly on my system. Is this to be expected?
Sample code:

``````
theta += 2;
glPushMatrix ();
glTranslatef (50,50,0);
glRotatef (theta,1,0,0);
glBegin (GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2d(0.0,0.0);
glVertex2d(100,0.0);
glVertex2d(100,100);
glColor3f(0.0, 100, 0.0);
glVertex2d(0.0,0.0);
glVertex2d(0.0,100);
glVertex2d(100,100);
glEnd();
glPopMatrix ();
``````

[QUOTE=question2;1266802]Hi all,
I had aspired to use ortho perspective but I’ve discovered that rotation about the x axis doesn’t work properly on my system.[/quote]

In what way does it not “work properly”?

The rectangle (two triangles) appears only at certain angles, e.g. -15 to 15 degrees. Otherwise it completely disappears. If you wanted I could make a video and upload that somewhere.

It would probably simpler to just post the rest of your code, i.e. the part where the bug is (there’s nothing wrong with the fragment you posted).

Other than that there is only initialization code. But I think I see what the problem is. Consider the code below. I change the vertex coordinates to be on both sides of the X and Y axes.
However when I rotate about the x-axis, it actually seems to be rotating about a line that is 50 points below the X axis i.e. y=-50. You can try for yourself.

When I change the axis of rotation to Y, a similar thing occurs: glRotatef rotates about a line that is not the Y axis but is maybe x=50.

``````
void draw_scene ()
{
glMatrixMode (GL_PROJECTION);
glOrtho(0.0f, width, height, 0.0f, 0.0f, 1.0f);
glMatrixMode (GL_MODELVIEW);

glDisable(GL_CULL_FACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_BLEND);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glColor3f (1.0, 1.0, 1.0);
glClear (GL_COLOR_BUFFER_BIT);

//  draw the rectangle
glPushMatrix ();
glTranslatef (100,100,0);
glRotatef (theta,1,0,0);
glScalef (2,2,1);
glBegin (GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex2d(-50.0,-50.0);
glVertex2d(50,-50.0);
glVertex2d(50,50);
glColor3f(1, 1, 0.0);
glVertex2d(-50.0,-50.0);
glVertex2d(-50.0,50);
glVertex2d(50,50);
glEnd();
glPopMatrix ();

glutSwapBuffers ();
}
``````

[QUOTE=question2;1266808]Other than that there is only initialization code.

``````
glOrtho(0.0f, width, height, 0.0f, 0.0f, 1.0f);

``````

[/QUOTE]
The rectangle is 100 units across, but the near and far planes are only one unit apart, and the rotation axis is coincident with the near plane. Except when the rectangle is almost exactly vertical, most of it is being clipped away by the near and far planes. Try:

``````
glOrtho(0.0f, width, height, 0.0f, -100.0f, 100.0f);

``````

[QUOTE=GClements;1266813]The rectangle is 100 units across, but the near and far planes are only one unit apart, and the rotation axis is coincident with the near plane. Except when the rectangle is almost exactly vertical, most of it is being clipped away by the near and far planes. Try:

``````
glOrtho(0.0f, width, height, 0.0f, -100.0f, 100.0f);

``````

[/QUOTE]

That fixed it! Thanks.