PG 5
PG 5
PG 5
h>
// Function declarations
void init();
void display();
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);
// Set up OpenGL
init();
// Register callbacks
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
return 0;
}
void init() {
// Set up the viewport
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void display() {
// Clear the color and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Reset transformations
glLoadIdentity();
// Apply transformations
glTranslatef(translateX, translateY, translateZ);
glScalef(scale, scale, scale);
glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
// Swap buffers
glutSwapBuffers();
}