Here is my code. My goal is to display a triangle and a square and have them both rotating. When I run the code, the triangle is displayed but the square is not and neither of them are rotating. Please help!
#include <gl\glut.h>
GLfloat rtri;
GLfloat rquad;
void Initialize()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
return;
}
void Reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return;
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5f, 0.0f, -6.0f);
glRotatef(rtri, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
glLoadIdentity();
glTranslatef(3.0f, 0.0f, 0.0f);
glRotatef(rquad, 1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glEnd();
glFlush();
rtri += 0.2f;
rquad -= 0.15f;
return;
}
void Keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27: exit(0);
break;
}
return;
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("");
glutFullScreen();
glutSetCursor(GLUT_CURSOR_NONE);
Initialize();
glutReshapeFunc(Reshape);
glutKeyboardFunc(Keyboard);
glutDisplayFunc(Display);
glutMainLoop();
glutSetCursor(GLUT_CURSOR_LEFT_ARROW);
return 0;
}