Newbie OpenGL Problem


I just started programming in OpenGL. And I decided to write a short little program which has two colored squares and rotates only one of them. This is for Win98 by the way. The thing is, as I am just a beginner, I don’t know how to make only one polygon rotate! Here is the code I am using:

void Display()

glRotatef(1.0, 1.0, 1.0, 0.0);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(-2.0, 2.0, 0.0);
glVertex3f(0.0, 2.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(-2.0, 0.0, 0.0);

glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(2.0, 0.0, 0.0);
glVertex3f(2.0, -2.0, 0.0);
glVertex3f(0.0, -2.0, 0.0);



This will make both polygons rotate, but I only want the second one to. Someone suggested putting a glLoadIdentity() before the rotate function, but this only produced a GPF on my system. I am using Borland C++ 4.5 on Win98. Hopefully, someone can shed light on a newbie and show me how to make only polygon rotate.

If you only want to rotate object 2:

–set up whatever projection you will use

I don’t know why you got a GPF, but Make sure you set the matrix mode.

Nope, no good.
Putting glLoadIdentity in my code causes an 10H exception in module nv30gl.dll

You MUST put a glLoadIdentity(). What do you think glRotatef will modify, if you don’t set the matrix before ? If you get an error, either your driver is bad, or your program as errors. As nickels said, make sure you set the matrix mode. If you don’t set glMartixMode(), nobody can tell what is going to happen. And for transforming objects, call glMatrixMode(GL_MODELVIEW);
Also notice that if you put glRotate before the 2 cubes without glLoadIdentity between the first and the second cube, both will rotate. If you wanna rotate only the first, load the identity matrix, call glRotate, draw your cube, then reload the identity and draw the second. If you want to rotate the second, call glLoadIdentity() at first, draw the cube, call glRotatef and then draw the second cube.