90 likes | 102 Views
Learn about OpenGL, an alternative to Direct3D, for 3D graphics rendering. OpenGL is platform-independent and can be mixed with non-DirectX graphics parts. Explore its data types, functions, and matrix operations distinct from Direct3D.
E N D
GAM666 – Introduction To Game Programming Introduction to OpenGL • OpenGL is an alternative to Direct3D for 3D graphics rendering • Originally developed by Silicon Graphics Inc (SGI), turned over to multi-vendor group (OpenGL Architecture Review Board) in 1992 • Unlike DirectX, OpenGL is platform independent, with implementations in Linux, Unix and Mac as well as Windows • Can be mixed and matched with non-DirectX Graphics parts of DirectX such as DirectInput and DirectX Audio
GAM666 – Introduction To Game Programming Introduction to OpenGL • Even though OpenGL is platform independent, the framework from which you call it is very much platform determined • GLUT provides a platform independent framework from which you can call OpenGL, but isn't intended to be full featured • GLUT should not be confused with GLU, which are some helper functions to assist with using OpenGL, similar to Direct3D's D3DX functions • The Windows functions wglCreateContext() and wglMakeCurrent() get OpenGL started in a normal Windows framework
GAM666 – Introduction To Game Programming Introduction to OpenGL • OpenGL has its own data types, e.g. • GLfloat (float) • GLint (int) • GLuint (unsigned int) • OpenGL functions begin with gl, e.g. • glClear() • glDrawArrays() • GLU functions begin with glu, e.g. • gluLookAt() • gluPerspective()
GAM666 – Introduction To Game Programming Introduction to OpenGL • The end of function names often have meaning as well: • A name ending with f usually has GLfloat parameters, while the same name only, ending with i, has GLint parameters • A name ending with, e.g., f may take a number of GLfloat parameters while the same name, only ending with fv, will take an array (vector) of GLfloat values
GAM666 – Introduction To Game Programming Introduction to OpenGL The OpenGL view is similar but different from the Direct3D view: • The z axis comes out from the screen rather than going into it • A point or vector is represented with a 4x1 matrix rather than a 1x4, and all matrix operations are reversed • Matrices are stored in column major format rather than the regular C-style row major format (i.e. matrices are transposed)
GAM666 – Introduction To Game Programming Introduction to OpenGL The OpenGL view is similar but different from the Direct3D view: • Vertex information is stored as a series of parallel arrays in system memory rather than an array of structures somewhere else • Triangle culling normally disabled by default, and if you turn it on, it draws the counter-clockwise side rather than the clockwise side by default
GAM666 – Introduction To Game Programming Introduction to OpenGL OpenGL is state-based, so you usually set a few states then do something, rather than pass a whole bunch of parameters with each operation, e.g. • There are two transformation matrices rather than three (Projection and Model/View), and to change one: • first set the matrix state, e.g. glMatrixMode(GL_PROJECTION) • then change that matrix, e.g. glLoadMatrixf(array)
GAM666 – Introduction To Game Programming Introduction to OpenGL • Each type of transformation matrix has a stack of matrices, where the top of the stack is the current active one • glPushMatrix() duplicates the current active matrix, putting the copy onto the top of the stack • glPopMatrix() gets rid of the current active matrix, restoring the previous one to active duty • The GL_PROJECTION stack is at least 2 deep, the GL_MODELVIEW stack is at least 32 deep
GAM666 – Introduction To Game Programming Introduction to OpenGL • Since the Model/View matrix replaces the purpose of both the View and World matrices of Direct3D, the usual drawing technique is: • Set the Model/View to the view matrix, then for each object • Push a copy of the Model/View matrix onto the top of the stack • Multiply by the object's world matrix • Draw the object • Pop the stack (restoring the view matrix) thereby getting ready for the next object