WPI Computer Science Department

Computer Science Department
------------------------------------------

CS 4731, C Term 2011 Homework 3


Homework 3: Due Thursday February 17, 11.59PM

Homework 3 Background

For this project, you are provided miniGL, an object-oriented C++ wrapper of OpenGL. Using miniGL you can either choose to simply run pure OpenGL commands, or run your own homegrown OpenGL functions. For instance, typing ./cs4731 -openGL -gears runs the miniGL bounce example using pure OpenGL. By using the -openGL switch of miniGL, you can call the pure OpenGL commands. E.g. the function mgl.mglRotate is simply a call to glRotate and mgl.mglTranslate simply calls glTranslate when you run the cs4731 executable using the -openGL command-line option. In this project, we are trying to explore implementations of portions of the graphics pipeline in the absence of openGL. In this homework, you will be required to use the -cs4731GL option instead of -openGL, which should call your own command implementations. Specifically, you will be required to write your graphics commands like myglScale, myglTranslate, myglRotate which should have the same behavior as glScale, glTranslate and glRotate. To accomplish this you will build and maintain your own matrices for use by your application.

As an implementation note, your implemented commands should have the same "feel" to the user as if they were making openGL calls. So, for example, if the programmer uses mgl.mgltranslate in his/her program, it should have the same exact behavior whether it his/her program is run using the -openGL switch (pure openGL glTranslate) or the -cs4731GL option (your myglTranslate). The examples provided should not exhibit dislocations or any different looks when your implementations are invoked.

MiniGL comes with examples (listed in the README file) which are ready to run. You are not required to do any more modeling. You shall simply write the required OpenGL functions (see below). To keep the project to a manageable size, we will implement only a portion of the pipeline. Specifically, we will implement only commands for selecting matrix modes (e.g. glMatrixMode) or changing the modelview or projection matrices. Thus, while you will implement your versions of some commands, some commands will continue to be handled using pure OpenGL implementations.

Homework 3 Overview

The specific goal of this homework is to work with matrices. You are going to build and maintain your own MODELVIEW_MATRIX and PROJECTION_MATRIX matrix stacks. You will set OpenGL's actual MODELVIEW_MATRIX or PROJECTION_MATRIX whenever your MODELVIEW_MATRIX or PROJECTION_MATRIX changes. The actual transform and rendering operations in OpenGL should work as they did previously since all you are doing is building and maintaining two of OpenGL's matrix stacks. For instance, if you run one of the miniGL examples provided using the -cs4731GL option, then if this example calls mgl.mglTranslate, mgl.mglTranslate should call your myglTranslate (your own implementation). In myglTranslate, you should build the necessary translate matrix and update your MODELVIEW_MATRIX. Before exitting your myglTranslate function, you should then update the actual OpenGL MODELVIEW matrix by calling glLoadMatrixf. See glLoadMatrix reference for more details on using glLoadMatrix.

Note that when you create a 3D model (e.g. glutWireCube), its vertices are "stuffed" into the OpenGL pipeline. In this homework, we will leave these vertices in the pipeline. However, we will simply help build and maintain the MODELVIEW and PROJECTION matrices which OpenGL will apply to the vertices.

You should use the Matrix.cpp and Matrix.h files. You will need to augment or/and change the provided matrix class to construct arbitrary scale, rotate and translate matrices (the translate is provided as an example).

  1. Preparation: Get and compile the code base miniGL which is provided in tar format for unix. The README file may be useful in knowing how things are written and getting things going. A Makefile has also been provided for the UNIX environment in the minigl tar file. For this project, I would advise working exclusively on the CCC machines since porting will just take more time. Simply compile the miniGL code base and try to run it. Look in the README file for what options are available and run the codebase. As I mentioned in class, you may get a warning about the performance of freeglut. This is just a performance warning and minigl will still work well. This warning has to do with the fact that there's no hardware rendering (graphics card) on the CCC server. You may ignore this warning, or just add a -indirect switch at the end of your minigl commands, to make OpenGL use software rendering instead. For instance, a typical call to run the bounce program (with the -indirect option) would be:

    ./cs4731 -openGL -bounce -indirect &

  2. Requirements:

    • Implement glRotate, glScale, glTranslate methods which modify the MODELVIEW_MATRIX stack.
    • Implement glMatrixMode which selects either the MODELVIEW_MATRIX or the PROJECTION_MATRIX and the glPushMatrix, glPopMatrix and glLoadIdentity methods to complete the MODELVIEW_MATRIX stack.
    • You will need to augment the provided matrix class to construct orthographic and perspective transformations. These will replace the remaining pipeline projection calls related to matrices that have been previously done by openGL. You will need to handle any glFrustrum, gluPerspective and glOrtho calls used in the examples provided. Once the basic infrastructure is in place, the difference between glFrustrum and glOrtho is negligible (simply using a different matrix).
    • Everytime you handle any commands (e.g. glTranslate, glRotate, etc) which change your modelview or projection matrices, you should update the actual OpenGL modelview or projection matrix. You simply use the glLoadMatrixf command to update the actual OpenGL matrix whenever your version of the matrices change.
    • Once your methods are working, remove all of the openGL calls you have replaced. Do not comment them out or ifdef them out. Completely delete them from the file. This reduces confusion during grading. In fact, when you submit your code, the only pure OpenGL commands allowed in your command implementations are commands to selec and load (update) the OpenGL matrices.

    HINT: You may need to record and check which matrix mode you are in for each operation!

    HINT: You can determine if your matrices are correct by using the glGet routines to get matrix values constructed by openGL. The values should be approximately the same as yours. Once you have check make sure you remove the openGL calls.

    HINT: You can plug in known values for the matrix operations and test that your matrix operations and multiplications work. For instance, one simple debug strategy may be to call both your myglTranslate and the pure glTranslate, then print and compare both values.

    Note: Use the tar command to archive your implementation and submit. Create documentation for your programs and submit them along with the projects. The documentation should explain briefly what each file does, how to run it and tie things in nicely. You should summarize what you have done and more importantly describe any known shortcomings of your submission to help during grading and avoid excessive loss of points.


    [Feedback] [Search Our Web] [Help & Index]

    [Return to the WPI Homepage] [Return to CS Homepage]

    mailto:emmanuel@cs.wpi.edu