#include "GL/glut.h" #include int width=500,height=500; void init(); void display(); void reshape(int w, int h); main(int argc, char* argv[]) { /* set up window */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE ); glutInitWindowSize(width,height); glutInitWindowPosition(100,100); glutCreateWindow("My OpenGL Program"); /* initialize state */ init(); /* register call back functions */ glutDisplayFunc(display); glutReshapeFunc(reshape); /* wait until something happens */ glutMainLoop(); return 1; } void init() { /* clear color is black */ glClearColor(0.0,0.0,0.0,0.0); /* define the viewing system */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10.0, 10.0, -10.0, 10.0, 10.0, 50.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glLoadIdentity(); // GL_MODELVIEW is current matrix gluLookAt(0.0,0.0,10.0,0.0,0.0,-1.0, 0.0, 1.0, 0.0); //viewing xfm glTranslatef(0.0,0.0,-20.0); // modeling xfm glutWireCube(5.0); // object glutSwapBuffers(); } void reshape(int w, int h) { /* width and height store current window dimensions */ width = w; height = h; /* map the projection plane to the entire window */ glViewport(0,0,w,h); }