// Lahde: http://www.cs.uct.ac.za/Courses/CS300W/ICG/Resources/OpenGL/quick.html #include "GL/glaux.h" #include "GL/gl.h" #include "GL/glu.h" /* We will fill in this function later. */ void myinit(void) { /* Red ambient light source */ GLfloat light_ambient[] = { 1.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_CULL_FACE); } /* This draws the scene, using the convenient functions supplied by the auxiliary library */ void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); glRotatef (20.0, 1.0, 0.0, 0.0); glPushMatrix (); glTranslatef (-0.75, -0.5, 0.0); glRotatef (270.0, 1.0, 0.0, 0.0); auxWireCone (1.0, 2.0); glPopMatrix (); glPushMatrix (); glTranslatef (-0.75, 0.5, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); auxWireTorus (0.275, 0.85); glPopMatrix (); glPopMatrix (); glFlush(); } /* This sets the perspective, and is called once initially and then whenever the window is resized. */ void myReshape(long w, long h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-2.5, 2.5, -2.5*(GLfloat)h/(GLfloat)w, 2.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0); else glOrtho (-2.5*(GLfloat)w/(GLfloat)h, 2.5*(GLfloat)w/(GLfloat)h, -2.5, 2.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); } /* Main Loop */ int main(int argc, char** argv) { auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH); auxInitPosition (0, 0, 500, 500); auxInitWindow (argv[0]); myinit(); auxReshapeFunc (/*(AUXRESHAPEPROC)*/ myReshape); /* Note the explicit type-casting */ auxMainLoop(/*(AUXMAINPROC)*/ display); return 1; }