I’m new to OpenGL. I’ve successfully drawn cubes, and tried to improve the code, came up with this, but this only draws the first face of the cube:
glPushMatrix();
glColor3d(1,0,0);
glRotatef(45,0,1,0);
glTranslatef(0,0,3);
for(int i=0;i<6;i++){
glBegin(GL_QUADS);
glVertex3f(0,0,0);
glVertex3f(3,0,0);
glVertex3f(3,3,0);
glVertex3f(0,3,0);
glEnd();
if(i<4)
glRotatef(90,0,1,0);
if(i=4)
glRotatef(90,1,0,0);
if(i=5)
glRotatef(180,1,0,0);
}
glRotatef(90,1,0,0);
glPopMatrix();
The iteration doesn’t seem to work at all! Am I missing something basic about the way how OpenGL works?
First answer is: You’re using an archaic version of OpenGL. Nowadays you don’t send vertices one by one, but instead:
glDrawArraysorglDrawElements.Try it sometime, works drastically faster 🙂
And on what’s wrong with your example- Did you perhaps mean this…?
and
Please enable your compiler warnings so that you’ll catch that. (I didn’t see it either, by the way – my compiler did :-))