9
GAM666 – Introduction To Game Programming 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 Introduction to OpenGL

Introduction to OpenGL OpenGL is an alternative to

  • Upload
    others

  • View
    37

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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

Introduction to OpenGL

Page 2: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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

Introduction to OpenGL

Page 3: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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()

Introduction to OpenGL

Page 4: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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

Introduction to OpenGL

Page 5: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

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)

Introduction to OpenGL

Page 6: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

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

Introduction to OpenGL

Page 7: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

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)

Introduction to OpenGL

Page 8: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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

Introduction to OpenGL

Page 9: Introduction to OpenGL OpenGL is an alternative to

GAM666 – Introduction To Game Programming

● 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

Introduction to OpenGL