#define APP_NAME "Simple Objects" #include #include "glut.h" /* window width and height */ int winW = 640; int winH = 480; void drawScene (void) { // green terrain glColor3f (0.0, 0.4 , 0.0); glBegin(GL_QUADS); glVertex3f(-20,0,20); glVertex3f(-20,0,-20); glVertex3f(20,0,-20); glVertex3f(20,0,20); glEnd; } void drawAxis (void) { glColor3f (0.5, 0.5, 0.5); glBegin (GL_LINES); glColor3f (0.5, 0.0, 0.0); glVertex3f (-20.0, 0.0, 0.0); glVertex3f (20.0, 0.0, 0.0); glColor3f (0.0, 0.5, 0.0); glVertex3f (0.0, 20.0, 0.0); glVertex3f (0.0, -20.0, 0.0); glColor3f (0.0, 0.0, 0.5); glVertex3f (0.0, 0.0, -20.0); glVertex3f (0.0, 0.0, 20.0); glEnd (); } /* ============= glutDisplay ============= The display function. */ void glutDisplay (void) { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); /* move our eye position away */ glTranslatef (0, -10, -25); /* apply rotation */ glRotatef (0, 1.0, 0.0, 0.0); glRotatef (0, 0.0, 1.0, 0.0); drawAxis (); drawScene(); //drawSphere(); glutSwapBuffers(); } void glutResize (int w, int h) { winW = w; winH = h; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, winW, winH); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (90, winW / winH, 1, 9999); glutPostRedisplay (); } void glInit (void) { glEnable (GL_DEPTH_TEST); glClearDepth(1.0); } int main (void) { glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize (winW,winH); glutCreateWindow (APP_NAME); glutDisplayFunc (glutDisplay); glutReshapeFunc (glutResize); glInit (); glutMainLoop(); return 1; }