/*************************************/ /* A Simple OpenGL Example */ /*************************************/ // this code just creates a window and draws three rectangles in it #include #include #include // set up projection void init() { glClearColor(0.0, 0.0, 0.0, 0.0); // clear -> black R,G,B,A = 0 (A=alpha channel) glMatrixMode(GL_PROJECTION); // applies subsequent matrix ops to // projection matrix glLoadIdentity(); glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0); // view box glMatrixMode(GL_MODELVIEW); // all matrix operations that follow apply to modelview matrix } // display content (called automatically in main loop) void display() { glClear(GL_COLOR_BUFFER_BIT); // clear color buffer // big green rectangle at a certain z coordinate glColor3f(0.0, 1.0, 0.0); // green //float z = 11; // clipped (outside box) float z = 5; // visible // draw quad first glBegin(GL_QUADS); glVertex3f(-10.0, 10.0, z); glVertex3f(-10.0, -10.0, z); glVertex3f( 10.0, -10.0, z); glVertex3f( 10.0, 10.0, z); glEnd(); // big red rectangle at z=0 glColor3f(1.0, 0.0, 0.0); // red glRectf(-8.0, 8.0, 8.0, -8.0); // draw rectangle // small blue rectangle at z=0 glColor3f(0.0, 0.0, 1.0); // blue glRectf(-5.0, 5.0, 5.0, -5.0); // draw rectangle glutSwapBuffers(); // bring draw buffer to front } int main (int argc, char **argv) { // setup window glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); // double buffering, rbg mode glutInitWindowSize(250, 250); glutInitWindowPosition(100, 100); glutCreateWindow("My First OpenGL Application"); init(); // register call-back function glutDisplayFunc(display); // glut takes over - calling display() repeatedly glutMainLoop(); return 0; }