http://www.opengl.org OpenGL Open Graphics Library Graphics API Delivered with UNIX, Win9x/2000/Me/Nt/Xp, Mac OS Direct3D (DirectX) is only Windows Utilizes the window system and event handling of the OS Often hardware supported (graphic cards) Derivative of Silicon Graphics GL library Language bindings to C, C++, Java, Fortran, Perl, Toolkits GLU OpenGL Utility Library Support for NURBS, Quadrics, etc. Delivered with OpenGL GLUT OpenGL Utility Toolkit Simplifies window handling User interface functions Header and library can be downloaded OpenGL Extensions allows new hardware innovations to be accessible through OpenGL 1
MESA http://www.mesa3d.org/ Mesa is a 3-D graphics library with an API which is very similar to that of OpenGL. Mesa is OpenGL in all respects except the name. Distributed under the XFree86 license, Mesa is not a licensed implementation of OpenGL and has not been tested by the OpenGL conformance tests. You can consider Mesa to be OpenGL; you can use OpenGL documentation, for example. Goals for OpenGL Industry-wide acceptance Consistent implementations Innovative implementations Scalable Long life High quality Non-goals for OpenGL Making graphics programming easy OpenGL is a power tool Easy to use for skilled programmers 2
Why/Why not OpenGL + Supporting O.S. + Open (kind of) + Free versions (Mesa) - Can be hard to use in structured programming. State machine. ( OpenGL is the assembler of computer graphics ) The Open GL Rendering Pipeline Vertex operations Transforms, projections, texture coordinates, lighting, clipping, Pixel operations Unpack (RGB, RGBA, LUMINANCE, ), scale, clamp, image processing Send to framebuffer or texture memory 3
The Open GL Rendering Pipeline Rasterization Fragment ~ pixel Consider line width, point size, shading model Color and depth are assigned for each fragment Fragment operations Alter or even throw out fragments Blending, anti-aliasing, depth-buffer OpenGL State machine Set a state remains the same until changed Example: The current color glcolor3f(1.0,0.0,0.0); Every object will be red until new call Many, many state variables can be set glenable, gldisable 4
Defining primitives in OpenGL OpenGL is using a right hand system Vertices are defined using glvertex*() Primitive defining statements all starts with glbegin(<primitive_type>) and ends with glend() Some primitive types GL_POINTS GL_LINES GL_LINESTRIP GL_TRIANGLES GL_QUADS GL_POLYGON Example (2D) glbegin(gl_line_loop); glvertex2f(-0.5,-0.5); glvertex2f( 0.5,-0.5); glvertex2f( 0.5, 0.5); glvertex2f(-0.5, 0.5); glend(); 5
glbegin(gl_line_strip); glvertex2f(-0.5,-0.5); glvertex2f( 0.5,-0.5); glvertex2f( 0.5, 0.5); glvertex2f(-0.5, 0.5); glend(); Another example (2D) The Camera Model Position Direction (look at) View up vector Projection Matrix (orthographic, perspective, etc..) glfrustum( ); gluperspective( ); glortho( ); Three matrix stacks GL_PROJECTION Camera (projection) matrix and window to viewport GL_MODELVIEW Model and View matrix GL_TEXTURE Texture transform matrix glmatrixmode(gl_modelview) glpushmatrix() / glpopmatrix() Transformations glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(4.0, 5.0, 6.0); glrotatef(45.0, 1.0, 2.0, 3.0); gltranslatef(-4.0, -5.0, -6.0); The rule in OpenGL is: The transformation specified most recently is the one applied first. C=T(4.0,5.0,6.0)R(45)T(-4.0,-5.0,-6.0) q=cp 6
OpenGL (glut) Callback Functions Used for Input and Interaction The user submits a pointer to a function which OpenGL calls when the corresponding event occurs. glutmousefunc(function); // click glutmotionfunc(function); // drag glutreshapefunc(function); // window resize glutkeyboardfunc(function); // keyboard glutidlefunc(function); // animation glutdisplayfunc(function); // draw primitives OpenGL Applications Open Inventor Maya Milkshape VRML viewers (Cosmo Player) Doom, Halflife, Medal of Honor, Quake Useful links OpenGL.org - www.opengl.org Red Book Online - http://www.dcc.unicamp.br/~lmarcos/cours es/mc603/redbook/ NeHe Tutorials - http://nehe.gamedev.net/ 7