(From diagram in OpenGL course notes from Siggraph 97)
Number of Components | Data Type | Vector |
2 - (x, y) | b - byte | omit "v" for scalar form |
3 - (x, y, z) | ub - unsigned byte | (e.g. glVertex2f(x, y); ) |
4 - (x, y, z, w) | s - unsigned short | |
us - unsigned short | ||
i - int | ||
ui - unsigned int | ||
f - float | ||
d - double |
(Table from Siggraph 97 OpenGL Course Notes.)
Viewing
Transformation, 2 matrices
Backface culling - no need to draw hidden facets
Clipping - to viewing frustum
Depth testLighting
Diffuse, specular, ambient
Multiple lights
Depends on normal vectors -- glNormalShading
Based on light position, materials, normals
Calculated for each vertex, interpolated to fill polygon (Gouraud shading)
object (world) coordinates
=> modelview
viewing (positioning and aiming camera): gluLookAt
model: glRotate, glTranslate, glScale
=> eye (camera) coordinates
=> projection (fov, projection: glOrtho, gluPerspective, glFrustum)
=> clip coordinates
=> perspective division (by w)
=> normalized device coordinates
=> viewport transformation (size and position of image)
=> screen coordinates.
glLoadIdentity - set current matrix to identity
(most commands: current matrix * specified matrix)
glMatrixMode - chooses between modelview and projection matrix stacks.
General transformations: glMultMatrix, glLoadMatrix
Note: matrix m[4][4] - C array. Then m[i][j] - ith column and jth row of OGL transformation matrix. C stores arrays in row-major order, while OpenGL expect column-major matrices.glPushMatrix, glPopMatrix
Vertices, polygons, glBegin/glEnd as before
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);clear depth buffer when clearing frame buffer
glEnable (GL_DEPTH_TEST), glDepthFunc
Enabling texture modes
Enable texturing - glEnable (GL_TEXTURE_2D)
Bind texture to context, make it current (avoid downloading texture multiple times) - glBindTexture
Download texture - glTexImage2D
Alternatively, build mipmaps and load the texture - gluBuild2DMipmaps
Set filtering options - glTexParameteri
Specifying texture coordinates
By hand glTexCoord*
Automatically generate texture coordinates based on the position of each vertex- glTexGen
glBegin(GL_TRIANGLES);
glArrayElement(2);
glArrayElement(3);
glArrayElement(4);
glEnd();
/* Later on... */
glCallList(1);
Mipmaps - power of 2 size is best.
Hardware vs. software
make small reversible changes to your code until you get a feel for what does what
OpenGL Web page
http://www.opengl.org/
Review session notes from 1999
http://graphics.stanford.edu/courses/cs248-99/OpenGLSession/248opengl.html