//IN BOOK - #include "OpenGL.h" #include "../common/openglsb.h" void RenderScene() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 0.0f); glRectf(-25.0f, 25.0f, 25.0f, -25.0f); // glutSwapBuffers(); glFlush(); } void SetupRC() { glClearColor(0.0f, 0.0f, 1.0f, 1.0f); } void ChangeSize(GLsizei width, GLsizei height) { GLfloat aspectRatio; // Prevent a divide by zero if (height == 0) height = 1; // Set viewport to window dimensions glViewport(0, 0, width, height); // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); aspectRatio = (GLfloat) width / (GLfloat) height; if (width <= height) glOrtho(-100.0, -100.0, -100 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0); else glOrtho(-100.0 * aspectRatio, -100.0 * aspectRatio, -100, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // glutInitWindowSize(800, 600); glutCreateWindow("Rect"); glutDisplayFunc(RenderScene); // glutReshapeFunc(ChangeSize); SetupRC(); glutMainLoop(); return 0; }