DOC PREVIEW
U of U CS 5610 - An Interactive Introduction to OpenGL Programming

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

An Interactive Introduction to OpenGL Programming1An Interactive Introduction to OpenGL ProgrammingAn Interactive Introduction to OpenGL ProgrammingDave ShreinerDave ShreinerEd AngelEd AngelVicki ShreinerVicki Shreiner2What You’ll See TodayWhat You’ll See Today••General OpenGL IntroductionGeneral OpenGL Introduction••Rendering PrimitivesRendering PrimitivesOpenGL and GLUT OverviewOpenGL and GLUT OverviewVicki ShreinerVicki Shreiner4OpenGL and GLUT OverviewOpenGL and GLUT Overview••What is OpenGL & what can it do for me?What is OpenGL & what can it do for me?••OpenGL in windowing systemsOpenGL in windowing systems••Why GLUTWhy GLUT••A GLUT program templateA GLUT program template5What Is OpenGL?What Is OpenGL?••A State Machine!A State Machine!6What Is OpenGL?What Is OpenGL?••Graphics rendering APIGraphics rendering API•high-quality color images composed of geometric and image primitives• window system independent• operating system independentAn Interactive Introduction to OpenGL Programming27OpenGL ArchitectureDisplayListPolynomialEvaluatorPer VertexOperations &PrimitiveAssemblyRasterizationPer FragmentOperationsFrameBufferTextureMemoryCPUPixelOperations8OpenGL as a RendererOpenGL as a Renderer••Geometric primitivesGeometric primitives•points, lines and polygons••Image PrimitivesImage Primitives•images and bitmaps• separate pipeline for images and geometry• linked through texture mapping••Rendering depends on stateRendering depends on state•normals, colors, materials, light sources, etc.9Related APIsRelated APIs••AGL, GLX, WGLAGL, GLX, WGL•glue between OpenGL and windowing systems••GLU (OpenGL Utility Library)GLU (OpenGL Utility Library)•part of OpenGL• NURBS, tessellators, quadric shapes, etc.••GLUT (OpenGL Utility Toolkit)GLUT (OpenGL Utility Toolkit)•portable windowing API• not officially part of OpenGL10OpenGL and Related APIsGLUTGLUGLGLX, AGLor WGLX, Win32, Mac O/Ssoftware and/or hardwareapplication programOpenGL Motifwidget or similar11PreliminariesPreliminaries••Headers FilesHeaders Files• #include <GL/gl.h>• #include <GL/glu.h>• #include <GL/glut.h>••LibrariesLibraries••Enumerated TypesEnumerated Types•OpenGL defines numerous types for compatibility– GLfloat, GLint, GLenum, etc.12GLUT BasicsGLUT Basics••Application StructureApplication Structure•Configure and open window• Initialize OpenGL state• Register input callback functions• render• resize• input: keyboard, mouse, etc.• Enter event processing loopAn Interactive Introduction to OpenGL Programming313Sample ProgramSample Programvoid main( int argc, char** argv )void main( int argc, char** argv ){{int mode = GLUT_RGB|GLUT_DOUBLE; int mode = GLUT_RGB|GLUT_DOUBLE; glutInitDisplayMode( mode );glutInitDisplayMode( mode );glutCreateWindow( argv[0] );glutCreateWindow( argv[0] );init();init();glutDisplayFunc( display );glutDisplayFunc( display );glutReshapeFunc( resize ); glutReshapeFunc( resize ); glutKeyboardFunc( key );glutKeyboardFunc( key );glutIdleFunc( idle );glutIdleFunc( idle );glutMainLoop();glutMainLoop();}}14OpenGL InitializationOpenGL Initialization••Set up whatever state you’re going to useSet up whatever state you’re going to usevoid init( void )void init( void ){{glClearColor( 0.0, 0.0, 0.0, 1.0 );glClearColor( 0.0, 0.0, 0.0, 1.0 );glClearDepth( 1.0 );glClearDepth( 1.0 );glEnable( GL_LIGHT0 );glEnable( GL_LIGHT0 );glEnable( GL_LIGHTING );glEnable( GL_LIGHTING );glEnable( GL_DEPTH_TEST );glEnable( GL_DEPTH_TEST );}}15GLUT Callback FunctionsGLUT Callback Functions••Routine to call when something happensRoutine to call when something happens•window resize or redraw• user input• animation••“Register” callbacks with GLUT“Register” callbacks with GLUTglutDisplayFunc( display );glutIdleFunc( idle );glutKeyboardFunc( keyboard );16Rendering CallbackRendering Callback•Do all of your drawing hereglutDisplayFunc( display );void display( void ){glClear( GL_COLOR_BUFFER_BIT );glBegin( GL_TRIANGLE_STRIP );glVertex3fv( v[0] );glVertex3fv( v[1] );glVertex3fv( v[2] );glVertex3fv( v[3] );glEnd();glutSwapBuffers();}••Do all of your drawing hereDo all of your drawing hereglutDisplayFunc(glutDisplayFunc(display display ););void display( void )void display( void ){{glClear( GL_COLOR_BUFFER_BIT );glClear( GL_COLOR_BUFFER_BIT );glBegin( GL_TRIANGLE_STRIP );glBegin( GL_TRIANGLE_STRIP );glVertex3fv( v[0] );glVertex3fv( v[0] );glVertex3fv( v[1] );glVertex3fv( v[1] );glVertex3fv( v[2] );glVertex3fv( v[2] );glVertex3fv( v[3] );glVertex3fv( v[3] );glEnd();glEnd();glutSwapBuffers();glutSwapBuffers();}}17Idle CallbacksIdle Callbacks••Use for animation and continuous updateUse for animation and continuous updateglutIdleFunc( glutIdleFunc( idleidle););void idle( void )void idle( void ){{t += dt;t += dt;glutPostRedisplay();glutPostRedisplay();}}18User Input CallbacksUser Input Callbacks•Process user inputglutKeyboardFunc( keyboard );void keyboard( char key, int x, int y ){switch( key ) {case ‘q’ : case ‘Q’ :exit( EXIT_SUCCESS );break;case ‘r’ : case ‘R’ :rotate = GL_TRUE;break;}}••Process user inputProcess user inputglutKeyboardFunc( glutKeyboardFunc( keyboardkeyboard););void keyboard( char key, int x, int y )void keyboard( char key, int x, int y ){{switch( key ) {switch( key ) {case ‘q’ : case ‘Q’ :case ‘q’ : case ‘Q’ :exit( EXIT_SUCCESS );exit( EXIT_SUCCESS );break;break;case ‘r’ : case ‘R’ :case ‘r’ : case ‘R’ :rotate = GL_TRUE;rotate = GL_TRUE;break;break;}}}}An Interactive Introduction to OpenGL Programming4Elementary RenderingElementary RenderingVicki ShreinerVicki Shreiner20Elementary Rendering•Geometric Primitives• Managing OpenGL State• OpenGL Buffers••Geometric PrimitivesGeometric Primitives••Managing OpenGL StateManaging OpenGL State••OpenGL BuffersOpenGL Buffers21OpenGL Geometric Primitives•All geometric primitives are specified by vertices••All geometric primitives are specified by All geometric primitives are specified by verticesverticesGL_QUAD_STRIPGL_QUAD_STRIPGL_POLYGONGL_POLYGONGL_TRIANGLE_STRIPGL_TRIANGLE_STRIPGL_TRIANGLE_FANGL_TRIANGLE_FANGL_POINTSGL_POINTSGL_LINESGL_LINESGL_LINE_LOOPGL_LINE_LOOPGL_LINE_STRIPGL_LINE_STRIPGL_TRIANGLESGL_TRIANGLESGL_QUADSGL_QUADS22Valid Polygons vs Invalid PolysValid Polygons vs Invalid Polys23Simple Examplevoid drawRhombus( GLfloat color[] ){glBegin(


View Full Document

U of U CS 5610 - An Interactive Introduction to OpenGL Programming

Download An Interactive Introduction to OpenGL Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view An Interactive Introduction to OpenGL Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view An Interactive Introduction to OpenGL Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?