opengl help session cs248 fall 2008 derek chan. opengl needs a windowing system opengl by itself...
Post on 15-Jan-2016
220 views
TRANSCRIPT
![Page 1: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/1.jpg)
OpenGL Help SessionCS248 Fall 2008
Derek Chan
![Page 2: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/2.jpg)
OpenGL needs a windowing system
• OpenGL by itself does not talk to the windowing system/manager by itself.
• Need a toolkit to tell the windowing system that we need an OpenGL window.
• Examples:
• GLUT/ GLUI (used in Project 2)
• SDL (more features: sound, image file loaders)
• wxWidgets, Qt (full fledged widget toolkits, probably overkill for a game)
![Page 3: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/3.jpg)
OpenGL needs a windowing system
• What does the windowing toolkit handle?
• Opening a window in the OS
• Window resizing
• Mouse/ keyboard presses
• Mouse position/movement
• What does OpenGL do? - draw
![Page 4: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/4.jpg)
Drawing
•glBegin():
•GL_POINTS
•GL_LINES
•GL_TRIANGLES
•Etc.
![Page 5: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/5.jpg)
Drawing
•glBegin(GL_LINES);
•glColor3f(r,g,b);
•glNormal3f(x,y,z);
•glTexCoord2d(u,v);
•glVertex3f(x,y,z);
…
•glEnd();
![Page 6: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/6.jpg)
OpenGL function suffixes
•OpenGL functions that take different types of arguments while providing the same functionality will often have a suffix to denote which type of function they are:
•glVertex2i - input is 2 integers
•glVertex3fv - input is 3 floats in an array
•glVertex3f - input is 3 floats
![Page 7: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/7.jpg)
OpenGL Camera
•glFrustrum
•gluPerspective
•glOrtho
•gluOrtho2d
•glViewport
•gluLookAt
![Page 8: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/8.jpg)
OpenGL
•glEnable( )
•glDisable( )
•GL_DEPTH_TEST
•GL_BLEND
•GL_LIGHTING
•GL_LIGHT1
![Page 9: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/9.jpg)
OpenGL
•Find simple tutorials online
•OpenGL does many things which you might not know about
•Display Lists (glGenLists, glCallList)
![Page 10: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/10.jpg)
OpenGL extensions
•Extensions to the OpenGL base system often have their own suffixes. For example:
•glCreateProgramObjectARB(to create a shader program using an ARB extension)
•Use GLEW (OpenGL Extension Wrangler) for easy access to extensions.
![Page 11: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/11.jpg)
Basic OpenGL Game Flowchart
1.Load up an OpenGL window using a toolkit to talk to the windowing system
•Set up projection matrices, shading properties, etc. Load textures, etc.
•Event loop:
•Check for any events or user input and process them
•Redraw the OpenGL scene as necessary
•Wait a small amount of time.
![Page 12: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/12.jpg)
General Programming Advice
1. have a math library
1. use object oriented programming
1. use c++ stl classes (or equivalent)
![Page 13: OpenGL Help Session CS248 Fall 2008 Derek Chan. OpenGL needs a windowing system OpenGL by itself does not talk to the windowing system/manager by itself](https://reader035.vdocuments.site/reader035/viewer/2022070412/56649d795503460f94a5c62b/html5/thumbnails/13.jpg)
Example Pitfalls
• Depth Testing vs blending (transperancies)
• Texture dimensions – power of 2(fixed in more recent implementations of OpenGL)
• Projection matrix should only be used for camera position, etc. It has a shorter stack than the Model-View matrix.