用GLUT库创建基本OpenGL窗口经典程序

////////////////////////////////////////////////////////////////////////// // File: main.cpp // Disc: This program creates a baisc OpenGL window within which there's a white square using glut library // Author: Simon Leung, SouthGIS ////////////////////////////////////////////////////////////////////////// // Header files needed #include #include void CreateSquare() { glBegin(GL_QUADS); glVertex3f(-1, -1, 0); glVertex3f(1, -1, 0); glVertex3f(1, 1, 0); glVertex3f(-1, 1, 0); glEnd(); } // Display function void MyDisplay() { // Set clear color glClearColor(0.0, 0.0, 0.0, 1.0); // Black // Clear the buffer glClear(GL_COLOR_BUFFER_BIT); // Clear color buffer // Reset the matrix to identity glLoadIdentity(); // Set camera properties gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); CreateSquare(); // Enable OpenGL to draw glFlush(); } void MyReshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat)w /(GLfloat) h, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); } void MyKeyboard(unsigned char key, int x, int y) { switch(key) { case 27: // When pressed escape key exit(0); break; default: break; } } // Application entry int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE); glutInitWindowPosition(200, 200); glutInitWindowSize(800, 600); glutCreateWindow("A Basic OpenGL Window [SouthGIS Inc.]"); glutDisplayFunc(MyDisplay); glutReshapeFunc(MyReshape); glutKeyboardFunc(MyKeyboard); glutMainLoop(); return 0; }

你可能感兴趣的:(OpenGL,buffer,properties,application,matrix,basic,header)