CISC 3620
Computer Graphics
Case Study for Chapter 2 - A Cube
Version 1 - Just a Bunch of Lines
- Bare minimum - defaults wherever possible
- Harcoded vertices
GL_LINE_LOOP
- Things to watch out for:
- The order in which the vertices are specified
- GL_LINES, GL_LINE_STRIP
Version 2 - Change the View
- Add an
init
function
- Changing the view is a model-view transformation, so we have to
specify we want to modify the model view matrix
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
initializes the model view matrix for us
gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz)
- Things to watch out for:
- Remember the default is orthographic viewing, with a 2x2x2 cube with the eye at the center
- You thus see things behind you
- Move the eye away from the origin and things might no longer be within your clipping volume
- Forgetting to set the matrix mode to
GL_MODELVIEW
- Forgetting to call
glLoadIdentity
-- GIGO
Version 3 - Add Some Color
glClearColor(r, g, b, a)
- sets 'clear' color (i.e., background) for the color buffer
glClear(buffer bitmask)
- sets one or more buffers to the value for each buffer
glColornt[v]
- sets current color
- Things to watch out for:
- Make sure you color is different than your clear color (duh)
Version 4 - Specify Vertices Using Vectors (Arrays)
- Use
typedef
to define a POINT3 type
- Use the
GLfloat
data type
- Respecify the each vertex as an array of 3 (x, y, z) coordinates
Version 5 - Turn it into an Array of Vertices
- Basically have a 2-dimensional array
- Each vertex is an array of 3 coordinates
- Have an array of vertices
Version 6 - Specify Window Size and Position
glutInitWindowSize(width, height)
glutInitWindowPosition(x, y)
- Things to watch out for:
- The aspect ratios of the window size and clipping volume should match, or you'll
get distortion of the image
Version 7 - Change Clipping Volume
- Clipping volume in orthographic projection is a cube
glOrtho(left, right, top, bottom, near, far);
- relative to the eye (at 0, 0, 0)
- negative values for near/far are behind the eye
- Affects the projection matrix
- Things to watch out for:
- Forgetting to set the matrix mode to
GL_PROJECTION
- Forgetting to initiali the matrix using
glLoadIdentity
- Miscalculating distance to object(s) being viewed
Version 8 - Polygons
- Change the
GL_LINE_LOOP
to GL_POLYGON
- Polygons have faces which by default are filled with the current color
- Face filling can be controlled with
glPolygonMode(face, fillMode)
- Things to watch out for:
- If it's not specified as a polygon, it's has no face and is not filled.
Version 9 - Specifying all the Polygons
- Change the
GL_LINE_LOOP
to GL_POLYGON
- Polygons have faces which by default are filled with the current color
- Face filling can be controlled with
glPolygonMode(face, fillMode)
- We'll specify a different color for each face
- Things to watch out for:
- If it's not specified as a polygon, it's has no face and is not filled.
Version 10 - Hidden Surface Removal
- Normally lines are drawn/rendered/rasterized in the order specified
- By default no depth information is used.
- Introducing depth testing provides hidden surface removal
- Objects closer to the eye hide objects behind them
- To use depth testing, you must:
- Specify that a depth buffer is to be used
glutInitDisplayMode(GLUT_DEPTH)
- Usually placed in
main
- Enable depth testing (using the buffer)
glEnable(GL_DEPTH_TEST)
- Usually placed in
init
- Clear the depth buffer prior to display
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- Things to watch out for:
- Forgetting to vlear the depth buffer bit-- buffer will contain data (probably garbage) from last display
Version 11 - Parameterizing the Image
- Makes handling resizing the image easier
- Can also simplify specifying the image in the first place
Version 12 - Handling Window Resizing by Adjusting Clipping Volume
- The clipping volume is mapped onto the viewport which is mapped onto the window
- This can introduce distortion of the aspect ratios don't match
- This can occur if user resizes the window
- This can also cause clipping since the viewport hasn't changed
- Must maintain match between aspect ratios
- One way to accomplish this is to adjust the clipping volume when window is resized
Version 12 - Handling Window Resizing by the Viewport
- The clipping volume is mapped onto the window
- This can introduce distortion of the aspect ratios don't match
- This can occur if user resizes the window
- Must maintain match between aspect ratios
- One way to accomplish this is to adjust the clipping volume when window is resized