The programming assignments for this course will use OpenGL graphics library. Using such a tool relieves us of having to deal with the hardware directly. It also implements standard graphics facilities. For most of the assignments, some facilities of OpenGL will be "off-limits" so that you can learn through doing some of the basic graphics processing which is normally handled for you behind the scenes.
OpenGL does not provide commands for performing windowing tasks or for obtaining user input. These commands are provided by GLUT (the OpenGL Utility Toolkit). GLUT provides commands to create windows, subwindows, and menus; and to handle input from a variety of devices via a callback mechanism. Documentation is available in pdf or postscript form.
[ I have now modified the program from the originally posted version to have dimensions which are 1 more than those give to glutInitWindowSize. Students quite reasonbly followed this model for Assignment 1, and then noticed anomalies in some lines. My best guess is that the dimensions given to gluOrtho2D represent the width of all the pixels, and since counting starts at zero, a window with a horizontal dimension of 400 is actually 401 pixels wide. ]
The program starts up a graphics window with a triangle in it. To exit, enter a "q" in the graphics window. I have added double buffering, mouse handling (you click on the left mouse button and drag to move the triangle around), and a menu example (right click to change the color of the triangle).
Note that program is not very sophisticated--it is only meant to help get you started. In order to handle a more complex collection of tasks, it is advisable to give careful thought to your design. Also, a real program would check that the first mouse click was inside the triangle.
The program compiles on graphics lab machines with:
cc triangle.c -o triangle -lGL -lGLU -lglut -lm
In this course we will be requiring a makefile with every programming assignment which builds your program. Here are example makefiles for the triangle program:
For Red Hat Linux on the graphics lab machines
For Debian Linux on the open lab (G-S, second floor) machines
For SunOS on lectura (I have copied the libraries to a temporary location. Updated libraries will be put in a more canonical location, but regardless, lectura is not recomended (too slow, no access to a console). For SunOS, you will need to add the library location to LD_LIBRARY_PATH.
Use "man". As far as I can tell, man on the graphics lab machines have no trouble finding the OpenGL pages, but if you run into touble, you could try adding /usr/X11R6/man:/usr/share/man to your MANPATH environment variable.
For GLUT, there is an intro page ("man glut"). If you like to guess which man pages might be useful, here is the results of "/bin/ls -1 glut*" in dicrectory /usr/share/man/man3 and "/bin/ls -1 gl*" in directory /usr/X11R6/man/man3" on one of the graphics machines. Ingore the dot and everything after it. For example, the second glut entry below is a hint that "man glutAddMenuEntry" might be fruitful.
/bin/ls -1 /usr/share/man/man3/glut* glut.3xglut.gz glutAddMenuEntry.3xglut.gz glutAddSubMenu.3xglut.gz glutAttachMenu.3xglut.gz glutBitmapCharacter.3xglut.gz glutBitmapLength.3xglut.gz glutBitmapWidth.3xglut.gz glutButtonBoxFunc.3xglut.gz glutChangeToMenuEntry.3xglut.gz glutChangeToSubMenu.3xglut.gz glutCopyColormap.3xglut.gz glutCreateMenu.3xglut.gz glutCreateSubWindow.3xglut.gz glutCreateWindow.3xglut.gz glutDestroyMenu.3xglut.gz glutDestroyWindow.3xglut.gz glutDetachMenu.3xglut.gz glutDeviceGet.3xglut.gz glutDialsFunc.3xglut.gz glutDisplayFunc.3xglut.gz glutEnterGameMode.3xglut.gz glutEntryFunc.3xglut.gz glutEstablishOverlay.3xglut.gz glutExtensionSupported.3xglut.gz glutForceJoystickFunc.3xglut.gz glutFullScreen.3xglut.gz glutGameModeGet.3xglut.gz glutGameModeString.3xglut.gz glutGet.3xglut.gz glutGetColor.3xglut.gz glutGetMenu.3xglut.gz glutGetModifiers.3xglut.gz glutGetWindow.3xglut.gz glutHideOverlay.3xglut.gz glutHideWindow.3xglut.gz glutIconifyWindow.3xglut.gz glutIdleFunc.3xglut.gz glutIgnoreKeyRepeat.3xglut.gz glutInit.3xglut.gz glutInitDisplayMode.3xglut.gz glutInitDisplayString.3xglut.gz glutInitWindowPosition.3xglut.gz glutJoystickFunc.3xglut.gz glutKeyboardFunc.3xglut.gz glutKeyboardUpFunc.3xglut.gz glutLayerGet.3xglut.gz glutLeaveGameMode.3xglut.gz glutMainLoop.3xglut.gz glutMenuStatusFunc.3xglut.gz glutMotionFunc.3xglut.gz glutMouseFunc.3xglut.gz glutOverlayDisplayFunc.3xglut.gz glutPassiveMotionFunc.3xglut.gz glutPopWindow.3xglut.gz glutPositionWindow.3xglut.gz glutPostOverlayRedisplay.3xglut.gz glutPostRedisplay.3xglut.gz glutPushWindow.3xglut.gz glutRemoveMenuItem.3xglut.gz glutRemoveOverlay.3xglut.gz glutReportErrors.3xglut.gz glutReshapeFunc.3xglut.gz glutReshapeWindow.3xglut.gz glutSetColor.3xglut.gz glutSetCursor.3xglut.gz glutSetIconTitle.3xglut.gz glutSetKeyRepeat.3xglut.gz glutSetMenu.3xglut.gz glutSetWindow.3xglut.gz glutSetWindowTitle.3xglut.gz glutShowOverlay.3xglut.gz glutShowWindow.3xglut.gz glutSolidCone.3xglut.gz glutSolidCube.3xglut.gz glutSolidDodecahedron.3xglut.gz glutSolidIcosahedron.3xglut.gz glutSolidOctahedron.3xglut.gz glutSolidSphere.3xglut.gz glutSolidTeapot.3xglut.gz glutSolidTetrahedron.3xglut.gz glutSolidTorus.3xglut.gz glutSpaceballButtonFunc.3xglut.gz glutSpaceballMotionFunc.3xglut.gz glutSpaceballRotateFunc.3xglut.gz glutSpecialFunc.3xglut.gz glutSpecialUpFunc.3xglut.gz glutStrokeCharacter.3xglut.gz glutStrokeLength.3xglut.gz glutStrokeWidth.3xglut.gz glutSwapBuffers.3xglut.gz glutTabletButtonFunc.3xglut.gz glutTabletMotionFunc.3xglut.gz glutTimerFunc.3xglut.gz glutUseLayer.3xglut.gz glutVisibilityFunc.3xglut.gz glutWarpPointer.3xglut.gz glutWireCone.3xglut.gz glutWireCube.3xglut.gz glutWireDodecahedron.3xglut.gz glutWireIcosahedron.3xglut.gz glutWireOctahedron.3xglut.gz glutWireSphere.3xglut.gz glutWireTeapot.3xglut.gz glutWireTetrahedron.3xglut.gz glutWireTorus.3xglut.gz /bin/ls -1 /usr/X11R6/man/man3/gl* glAccum.3x.gz glActiveTextureARB.3x.gz glAlphaFunc.3x.gz glAreTexturesResident.3x.gz glArrayElement.3x.gz glBegin.3x.gz glBindTexture.3x.gz glBitmap.3x.gz glBlendColor.3x.gz glBlendEquation.3x.gz glBlendFunc.3x.gz glCallList.3x.gz glCallLists.3x.gz glClear.3x.gz glClearAccum.3x.gz glClearColor.3x.gz glClearDepth.3x.gz glClearIndex.3x.gz glClearStencil.3x.gz glClientActiveTextureARB.3x.gz glClipPlane.3x.gz glColor3b.3x.gz glColor3bv.3x.gz glColor3d.3x.gz glColor3dv.3x.gz glColor3f.3x.gz glColor3fv.3x.gz glColor3i.3x.gz glColor3iv.3x.gz glColor3s.3x.gz glColor3sv.3x.gz glColor3ub.3x.gz glColor3ubv.3x.gz glColor3ui.3x.gz glColor3uiv.3x.gz glColor3us.3x.gz glColor3usv.3x.gz glColor.3x.gz glColor4b.3x.gz glColor4bv.3x.gz glColor4d.3x.gz glColor4dv.3x.gz glColor4f.3x.gz glColor4fv.3x.gz glColor4i.3x.gz glColor4iv.3x.gz glColor4s.3x.gz glColor4sv.3x.gz glColor4ub.3x.gz glColor4ubv.3x.gz glColor4ui.3x.gz glColor4uiv.3x.gz glColor4us.3x.gz glColor4usv.3x.gz glColorMask.3x.gz glColorMaterial.3x.gz glColorPointer.3x.gz glColorSubTable.3x.gz glColorTable.3x.gz glColorTableParameter.3x.gz glColorTableParameterfv.3x.gz glColorTableParameteriv.3x.gz glConvolutionFilter1D.3x.gz glConvolutionFilter2D.3x.gz glConvolutionParameter.3x.gz glCopyColorSubTable.3x.gz glCopyColorTable.3x.gz glCopyConvolutionFilter1D.3x.gz glCopyConvolutionFilter2D.3x.gz glCopyPixels.3x.gz glCopyTexImage1D.3x.gz glCopyTexImage2D.3x.gz glCopyTexSubImage1D.3x.gz glCopyTexSubImage2D.3x.gz glCopyTexSubImage3D.3x.gz glCullFace.3x.gz glDeleteLists.3x.gz glDeleteTextures.3x.gz glDepthFunc.3x.gz glDepthMask.3x.gz glDepthRange.3x.gz glDisable.3x.gz glDisableClientState.3x.gz glDrawArrays.3x.gz glDrawBuffer.3x.gz glDrawElements.3x.gz glDrawPixels.3x.gz glDrawRangeElements.3x.gz glEdgeFlag.3x.gz glEdgeFlagPointer.3x.gz glEdgeFlagv.3x.gz glEnable.3x.gz glEnableClientState.3x.gz glEnd.3x.gz glEndList.3x.gz glEvalCoord1d.3x.gz glEvalCoord1dv.3x.gz glEvalCoord1fv.3x.gz glEvalCoord2d.3x.gz glEvalCoord2dv.3x.gz glEvalCoord2f.3x.gz glEvalCoord2fv.3x.gz glEvalCoord.3x.gz glEvalMesh1.3x.gz glEvalMesh2.3x.gz glEvalMesh.3x.gz glEvalPoint1.3x.gz glEvalPoint2.3x.gz glEvalPoint.3x.gz glFeedbackBuffer.3x.gz glFinish.3x.gz glFlush.3x.gz glFog.3x.gz glFogf.3x.gz glFogfv.3x.gz glFogi.3x.gz glFogiv.3x.gz glFrontFace.3x.gz glFrustum.3x.gz glGenLists.3x.gz glGenTextures.3x.gz glGet.3x.gz glGetBooleanv.3x.gz glGetClipPlane.3x.gz glGetColorTable.3x.gz glGetColorTableParameter.3x.gz glGetColorTableParameterfv.3x.gz glGetColorTableParameteriv.3x.gz glGetConvolutionFilter.3x.gz glGetConvolutionParameter.3x.gz glGetDoublev.3x.gz glGetError.3x.gz glGetFloatv.3x.gz glGetHistogram.3x.gz glGetHistogramParameter.3x.gz glGetIntegerv.3x.gz glGetLight.3x.gz glGetLightfv.3x.gz glGetLightiv.3x.gz glGetMap.3x.gz glGetMapdv.3x.gz glGetMapfv.3x.gz glGetMapiv.3x.gz glGetMaterial.3x.gz glGetMaterialfv.3x.gz glGetMaterialiv.3x.gz glGetMinmax.3x.gz glGetMinmaxParameter.3x.gz glGetPixelMap.3x.gz glGetPixelMapfv.3x.gz glGetPixelMapuiv.3x.gz glGetPixelMapusv.3x.gz glGetPointerv.3x.gz glGetPolygonStipple.3x.gz glGetSeparableFilter.3x.gz glGetString.3x.gz glGetTexEnv.3x.gz glGetTexEnvfv.3x.gz glGetTexEnviv.3x.gz glGetTexGen.3x.gz glGetTexGendv.3x.gz glGetTexGenfv.3x.gz glGetTexGeniv.3x.gz glGetTexImage.3x.gz glGetTexLevelParameter.3x.gz glGetTexLevelParameterfv.3x.gz glGetTexLevelParameteriv.3x.gz glGetTexParameter.3x.gz glGetTexParameterfv.3x.gz glGetTexParameteriv.3x.gz glHint.3x.gz glHistogram.3x.gz glIndex.3x.gz glIndexd.3x.gz glIndexdv.3x.gz glIndexf.3x.gz glIndexfv.3x.gz glIndexi.3x.gz glIndexiv.3x.gz glIndexMask.3x.gz glIndexPointer.3x.gz glIndexs.3x.gz glIndexsv.3x.gz glIndexub.3x.gz glIndexubv.3x.gz glInitNames.3x.gz glInterleavedArrays.3x.gz glIsEnabled.3x.gz glIslist.3x.gz glIsTexture.3x.gz glLight.3x.gz glLightf.3x.gz glLightfv.3x.gz glLighti.3x.gz glLightiv.3x.gz glLightModel.3x.gz glLightModelf.3x.gz glLightModelfv.3x.gz glLightModeli.3x.gz glLightModeliv.3x.gz glLineStipple.3x.gz glLineWidth.3x.gz glListBase.3x.gz glLoadIdentity.3x.gz glLoadMatrix.3x.gz glLoadMatrixd.3x.gz glLoadMatrixf.3x.gz glLoadName.3x.gz glLogicOp.3x.gz glMap1.3x.gz glMap1d.3x.gz glMap1f.3x.gz glMap2.3x.gz glMap2d.3x.gz glMap2f.3x.gz glMapGrid1d.3x.gz glMapGrid1f.3x.gz glMapGrid2d.3x.gz glMapGrid2f.3x.gz glMapGrid.3x.gz glMaterial.3x.gz glMaterialf.3x.gz glMaterialfv.3x.gz glMateriali.3x.gz glMaterialiv.3x.gz glMatrixMode.3x.gz glMinmax.3x.gz glMultiTexCoord1dARB.3x.gz glMultiTexCoord1dvARB.3x.gz glMultiTexCoord1fARB.3x.gz glMultiTexCoord1fvARB.3x.gz glMultiTexCoord1iARB.3x.gz glMultiTexCoord1ivARB.3x.gz glMultiTexCoord1sARB.3x.gz glMultiTexCoord1svARB.3x.gz glMultiTexCoord2dARB.3x.gz glMultiTexCoord2dvARB.3x.gz glMultiTexCoord2fARB.3x.gz glMultiTexCoord2fvARB.3x.gz glMultiTexCoord2iARB.3x.gz glMultiTexCoord2ivARB.3x.gz glMultiTexCoord2sARB.3x.gz glMultiTexCoord2svARB.3x.gz glMultiTexCoord3dARB.3x.gz glMultiTexCoord3dvARB.3x.gz glMultiTexCoord3fARB.3x.gz glMultiTexCoord3fvARB.3x.gz glMultiTexCoord3iARB.3x.gz glMultiTexCoord3ivARB.3x.gz glMultiTexCoord3sARB.3x.gz glMultiTexCoord3svARB.3x.gz glMultiTexCoord4dARB.3x.gz glMultiTexCoord4dvARB.3x.gz glMultiTexCoord4fARB.3x.gz glMultiTexCoord4fvARB.3x.gz glMultiTexCoord4iARB.3x.gz glMultiTexCoord4ivARB.3x.gz glMultiTexCoord4sARB.3x.gz glMultiTexCoord4svARB.3x.gz glMultiTexCoordARB.3x.gz glMultMatrix.3x.gz glMultMatrixd.3x.gz glMultMatrixf.3x.gz glNewList.3x.gz glNormal3b.3x.gz glNormal3bv.3x.gz glNormal3d.3x.gz glNormal3dv.3x.gz glNormal3f.3x.gz glNormal3fv.3x.gz glNormal3i.3x.gz glNormal3iv.3x.gz glNormal3s.3x.gz glNormal3sv.3x.gz glNormal.3x.gz glNormalPointer.3x.gz glOrtho.3x.gz glPassThrough.3x.gz glPixelMap.3x.gz glPixelMapfv.3x.gz glPixelMapuiv.3x.gz glPixelMapusv.3x.gz glPixelStore.3x.gz glPixelStoref.3x.gz glPixelStorei.3x.gz glPixelTransfer.3x.gz glPixelTransferf.3x.gz glPixelTransferi.3x.gz glPixelZoom.3x.gz glPointSize.3x.gz glPolygonMode.3x.gz glPolygonOffset.3x.gz glPolygonStipple.3x.gz glPopAttrib.3x.gz glPopClientAttrib.3x.gz glPopMatrix.3x.gz glPopName.3x.gz glPrioritizeTextures.3x.gz glPushAttrib.3x.gz glPushClientAttrib.3x.gz glPushMatrix.3x.gz glPushName.3x.gz glRasterPos2d.3x.gz glRasterPos2dv.3x.gz glRasterPos2f.3x.gz glRasterPos2fv.3x.gz glRasterPos2i.3x.gz glRasterPos2iv.3x.gz glRasterPos2s.3x.gz glRasterPos2sv.3x.gz glRasterPos3d.3x.gz glRasterPos3dv.3x.gz glRasterPos3f.3x.gz glRasterPos3fv.3x.gz glRasterPos3i.3x.gz glRasterPos3iv.3x.gz glRasterPos3s.3x.gz glRasterPos3sv.3x.gz glRasterPos.3x.gz glRasterPos4d.3x.gz glRasterPos4dv.3x.gz glRasterPos4f.3x.gz glRasterPos4fv.3x.gz glRasterPos4i.3x.gz glRasterPos4iv.3x.gz glRasterPos4s.3x.gz glRasterPos4sv.3x.gz glReadBuffer.3x.gz glReadPixels.3x.gz glRect.3x.gz glRectd.3x.gz glRectdv.3x.gz glRectf.3x.gz glRectfv.3x.gz glRecti.3x.gz glRectiv.3x.gz glRects.3x.gz glRectsv.3x.gz glRenderMode.3x.gz glResetHistogram.3x.gz glResetMinmax.3x.gz glRotate.3x.gz glRotated.3x.gz glRotatef.3x.gz glScale.3x.gz glScaled.3x.gz glScalef.3x.gz glScissor.3x.gz glSelectBuffer.3x.gz glSeparableFilter2D.3x.gz glShadeModel.3x.gz glStencilFunc.3x.gz glStencilMask.3x.gz glStencilOp.3x.gz glTexCoord1d.3x.gz glTexCoord1dv.3x.gz glTexCoord1f.3x.gz glTexCoord1fv.3x.gz glTexCoord1i.3x.gz glTexCoord1iv.3x.gz glTexCoord1s.3x.gz glTexCoord1sv.3x.gz glTexCoord2d.3x.gz glTexCoord2dv.3x.gz glTexCoord2f.3x.gz glTexCoord2fv.3x.gz glTexCoord2i.3x.gz glTexCoord2iv.3x.gz glTexCoord2s.3x.gz glTexCoord2sv.3x.gz glTexCoord3d.3x.gz glTexCoord3dv.3x.gz glTexCoord3f.3x.gz glTexCoord3fv.3x.gz glTexCoord3i.3x.gz glTexCoord3iv.3x.gz glTexCoord3s.3x.gz glTexCoord3sv.3x.gz glTexCoord.3x.gz glTexCoord4d.3x.gz glTexCoord4dv.3x.gz glTexCoord4f.3x.gz glTexCoord4fv.3x.gz glTexCoord4i.3x.gz glTexCoord4iv.3x.gz glTexCoord4s.3x.gz glTexCoord4sv.3x.gz glTexCoordPointer.3x.gz glTexEnv.3x.gz glTexEnvf.3x.gz glTexEnvfv.3x.gz glTexEnvi.3x.gz glTexEnviv.3x.gz glTexGen.3x.gz glTexGend.3x.gz glTexGendv.3x.gz glTexGenf.3x.gz glTexGenfv.3x.gz glTexGeni.3x.gz glTexGeniv.3x.gz glTexImage1D.3x.gz glTexImage2D.3x.gz glTexImage3D.3x.gz glTexParameter.3x.gz glTexParameterf.3x.gz glTexParameterfv.3x.gz glTexParameteri.3x.gz glTexParameteriv.3x.gz glTexSubImage1D.3x.gz glTexSubImage2D.3x.gz glTexSubImage3D.3x.gz glTranslate.3x.gz glTranslated.3x.gz glTranslatef.3x.gz gluBeginCurve.3x.gz gluBeginPolygon.3x.gz gluBeginSurface.3x.gz gluBeginTrim.3x.gz gluBuild1DMipmaps.3x.gz gluBuild2DMipmaps.3x.gz gluCylinder.3x.gz gluDeleteNurbsRenderer.3x.gz gluDeleteQuadric.3x.gz gluDeleteTess.3x.gz gluDisk.3x.gz gluEndCurve.3x.gz gluEndPolygon.3x.gz gluEndSurface.3x.gz gluEndTrim.3x.gz gluErrorString.3x.gz gluGetNurbsProperty.3x.gz gluGetString.3x.gz gluGetTessProperty.3x.gz gluLoadSamplingMatrices.3x.gz gluLookAt.3x.gz gluNewNurbsRenderer.3x.gz gluNewQuadric.3x.gz gluNewTess.3x.gz gluNextContour.3x.gz gluNurbsCallback.3x.gz gluNurbsCallbackDataEXT.3x.gz gluNurbsCurve.3x.gz gluNurbsProperty.3x.gz gluNurbsSurface.3x.gz gluOrtho2D.3x.gz gluPartialDisk.3x.gz gluPerspective.3x.gz gluPickMatrix.3x.gz gluProject.3x.gz gluPwlCurve.3x.gz gluQuadricCallback.3x.gz gluQuadricDrawStyle.3x.gz gluQuadricNormals.3x.gz gluQuadricOrientation.3x.gz gluQuadricTexture.3x.gz gluScaleImage.3x.gz gluSphere.3x.gz gluTessBeginContour.3x.gz gluTessBeginPolygon.3x.gz gluTessCallback.3x.gz gluTessEndContour.3x.gz gluTessEndPolygon.3x.gz gluTessNormal.3x.gz gluTessProperty.3x.gz gluTessVertex.3x.gz gluUnProject.3x.gz glVertex2d.3x.gz glVertex2dv.3x.gz glVertex2f.3x.gz glVertex2fv.3x.gz glVertex2i.3x.gz glVertex2iv.3x.gz glVertex2s.3x.gz glVertex2sv.3x.gz glVertex3d.3x.gz glVertex3dv.3x.gz glVertex3f.3x.gz glVertex3fv.3x.gz glVertex3i.3x.gz glVertex3iv.3x.gz glVertex3s.3x.gz glVertex3sv.3x.gz glVertex.3x.gz glVertex4d.3x.gz glVertex4dv.3x.gz glVertex4f.3x.gz glVertex4fv.3x.gz glVertex4i.3x.gz glVertex4iv.3x.gz glVertex4s.3x.gz glVertex4sv.3x.gz glVertexPointer.3x.gz glViewport.3x.gz glXChooseVisual.3x.gz glXCopyContext.3x.gz glXCreateContext.3x.gz glXCreateGLXPixmap.3x.gz glXDestroyContext.3x.gz glXDestroyGLXPixmap.3x.gz glXFreeContextEXT.3x.gz glXGetClientString.3x.gz glXGetConfig.3x.gz glXGetContextIDEXT.3x.gz glXGetCurrentContext.3x.gz glXGetCurrentDisplay.3x.gz glXGetCurrentDrawable.3x.gz glXImportContextEXT.3x.gz glXIntro.3x.gz glXIsDirect.3x.gz glXMakeCurrent.3x.gz glXQueryContextInfoEXT.3x.gz glXQueryExtension.3x.gz glXQueryExtensionsString.3x.gz glXQueryServerString.3x.gz glXQueryVersion.3x.gz glXSwapBuffers.3x.gz glXUseXFont.3x.gz glXWaitGL.3x.gz glXWaitX.3x.gz