/* * Wyatt Carss * 0603838 * 717 Scottsdale Dr. * wcarss@uoguelph.ca * * This is my Assignment 1 for the W10 run of 4800: Graphics. The code is mostly copied and pasted bits of examples from the web, thrown into a basic OpenGL program format. I wrote code myself, but really, not much, as it didn't make sense to. granger.cis.uoguelph.ca:/home/courses/cs4800/sampleGL is the source of the examples I was using. */ #include #include #include #include #include int glWindow = 0; GLfloat light0_ambient[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_specular[] = {1.0f, 1.0f, 1.0f, 1.0f}; GLfloat light0_position[] = {1.0f, 1.0f, 0.4f, 0.0f}; void Idle() { /* According to the GLUT specification, the current window is undefined during an idle callback. So we need to explicitly change it if necessary */ if ( glutGetWindow() != glWindow ) glutSetWindow(glWindow); glutPostRedisplay(); } void Draw() { GLfloat red[] = {1.0, 0.0, 0.0, 1.0}; GLfloat grey[] = {0.5, 0.5, 0.5, 1.0}; GLfloat white[] = {1.0, 1.0, 1.0, 1.0}; GLfloat green[] = {0.0, 1.0, 0.0, 1.0}; glClearColor( .0f, .0f, .0f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glMaterialf(GL_FRONT, GL_SHININESS, 30.0); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, grey); glMaterialfv(GL_FRONT, GL_SPECULAR, white); glPushMatrix(); glTranslatef(-1,0,0); glScalef(0.01,2,0.01); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(1,0,0); glScalef(0.01,2,0.01); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(0,-1,0); glScalef(2,0.01,0.01); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(0,1,0); glScalef(2,0.01,0.01); glutSolidCube(1); glPopMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); glMaterialfv(GL_FRONT, GL_SPECULAR, white); glPushMatrix(); glTranslatef(0.5,0.5,0); glutSolidSphere(0.1,15,15); glPopMatrix(); glutSwapBuffers(); } void Initialize() { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.1, 1.1, -1.1, 1.1, -1, 1); } int main(int iArgc, char **cppArgv) { glutInit(&iArgc, cppArgv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1000, 800); glutInitWindowPosition(200, 200); glWindow = glutCreateWindow("Simple GLUI App"); Initialize(); glutDisplayFunc(Draw); /****************************************/ /* Set up OpenGL lights */ /****************************************/ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); // Normals need to be turned on glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); /****************************************/ /* Enable z-buferring */ /****************************************/ glEnable(GL_DEPTH_TEST); /****************************************/ /* Here's the GLUI code */ /****************************************/ GLUI *glui = GLUI_Master.create_glui( "GLUI" ); GLUI_Panel *panel1 = new GLUI_Panel(glui, "Main View" ); new GLUI_Button(glui, "Exit", 0, (GLUI_Update_CB)exit ); (new GLUI_Spinner( panel1, "Ambient Red:", &light0_ambient[0] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Diffuse Red:", &light0_diffuse[0] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Specular Red:", &light0_specular[0] )) ->set_int_limits( 0, 1); new GLUI_Column( panel1, false) ; (new GLUI_Spinner( panel1, "Ambient Green:", &light0_ambient[1] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Diffuse Green:", &light0_diffuse[1] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Specular Green:", &light0_specular[1] )) ->set_int_limits( 0, 1); new GLUI_Column( panel1, false) ; (new GLUI_Spinner( panel1, "Ambient Blue:", &light0_ambient[2] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Diffuse Blue:", &light0_diffuse[2] )) ->set_int_limits( 0, 1); (new GLUI_Spinner( panel1, "Specular Blue:", &light0_specular[2] )) ->set_int_limits( 0, 1); new GLUI_Column( panel1, false) ; glui->set_main_gfx_window( glWindow ); /* We register the idle callback with GLUI, *not* with GLUT */ GLUI_Master.set_glutIdleFunc( Idle ); glutMainLoop(); return EXIT_SUCCESS; }