CS 455
Syllabus
Policies
Projects
Calendar
Slides
 
Project Overview
   Project 1
   Project 2
   Project 3
   Project 4
   Project 5
 
Old Quizzes
 
 

Project 1: Setting up your environment

This project has no elective functionality. Instead, it is aimed at helping you start out on the right foot to minimize future difficulties. That said, it might take some time. If you get it running, you get 100 points. If not, you will not be able to do any of the following projects.

Part 1: Select an environment

You may work on any operating system using any programming language you want. The only requirements are that:
  • You can open up a window rendered by OpenGL.
  • You can show the TA your work—that is, it either has to run in one of the basement CS computers or on your notebook computer.
  • See language notes at the end of the page
A good starting place would be the first few NeHe OpenGL tutorials, particularly the list of language implementations at the end of NeHe tutorial 2, which includes basic code for most major languages and all common operating systems, with several different versions for the most common languages. Note that Nehe's C# OpenGL is rather kludgey; you might try Tao if you want a cleaner interface.

Part 2: Setting up the interface

Using whatever language you picked, you will want to do the following:
  1. Create a window rendered by OpenGL and some way of listening to keyboard events. The NeHe code should do this for you. Make the OpenGL viewable area be 640 pixels wide and 480 pixels tall. Get rid of all other OpenGL calls except "glViewport". Right after the call to "glViewport" add the following:
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
    
  2. Create (globally visible to your code) an array (or its equivalent for your language) of 640*480*3 floating-point numbers named "raster" and an integer named "drawmode".
  3. In the keyboard event listener, if '1' is typed set "drawmode := 1" and if '2' is typed set "drawmode := 2". We will use 1 to be the built-in OpenGL and 2 to be your implementation. When either of those keys is pressed, tell the window to redraw itself.
  4. Initialize the floating-point array so that "raster[i] := float(i)/(640*480*3)".
  5. You draw method, for now, should contain the following OpenGL calls (syntax may change with different languages):
         void draw() {
            glClearColor(1,0,0,1);  // Set the clear color
            // Clear the screen to the clear color (i.e. if the clear color
            // is red, the screen turns red);
            glClear(GL_COLOR_BUFFER_BIT);
            
            if (drawmode == 2) {
                // Save the old state so that you can set it back after you draw
                GLint oldmatrixmode;
                GLboolean depthWasEnabled = glIsEnabled(GL_DEPTH_TEST);
                glDisable(GL_DEPTH_TEST);
                glGetIntegerv(GL_MATRIX_MODE,&oldmatrixmode);
                glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity();
                glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity();
                
                // Draw the array of pixels (This is where you draw the values
                // you have stored in the array 'raster')
                glRasterPos2f(-1,-1);
                glDrawPixels(640,480,GL_RGB,GL_FLOAT,raster);
                
                //Set the state back to what it was
                glPopMatrix();
                glMatrixMode(GL_MODELVIEW); glPopMatrix();
                glMatrixMode(oldmatrixmode);
                if (depthWasEnabled)
                  glEnable(GL_DEPTH_TEST);
            }
            glFlush();
    
    	//If you are using glut, you will need to add the following call:
    	//glutSwapBuffers();
         }
    
    When you run this it should show solid red screen when you hit "1" and a black-to-white gradient when you hit "2".

Part 3: Data structures

You will need to have a 4-by-4 matrix structure and a 4-vector structure, as well as a stack structure capable of holding at least 32 matrices. You are free to write these yourself or use ones others have written.

On this website we will call the coordinates of a vector V by several names:
V[0] = V.x = V.r
V[1] = V.y = V.g
V[2] = V.z = V.b
V[3] = V.w = V.a

Make sure you can

  • Read and write matrices and vectors to simple arrays of floats; do matrices in column major format. Thus,
    	1 2 3 4
    	0 5 6 7   <=>  {1, 0, 0, 0, 2, 5, 0, 0, 3, 6, 8, 0, 4, 7, 9, 0}
    	0 0 8 9
    	0 0 0 0
    
    Why column-major? Because that's what OpenGL expects. Don't ask me why they expect it.
  • Multiply vectors by single numbers, as well as adding and subtracting vectors.
  • Multiply matrices by each other and vectors by matrices. Thus,
    	1 2 3 4       1 0 1 0       1  4 10 20
    	0 5 6 7   *   0 2 0 2   =   0 10 18 38
    	0 0 8 9       0 0 3 0       0  0 24 36
    	0 0 0 0       0 0 0 4       0  0  0  0
    
    and
    	1 2 3 4       2       51
    	0 5 6 7   *   3   =   94
    	0 0 8 9       5      103
    	0 0 0 0       7        0
    
  • Take the inner (also called the dot) product of two vectors.
  • Take the 3D cross product of two vectors (pretend they were 3-vectors by ignoring the w coordinate).
  • Perform matrix inversion. Cramer's rule should work fine, though you can do a more advanced method if you want.
  • Push and pop matrices on a stack.

Passoff:

Have ready two programs: one which alternates between the red and gradient screens when you type "1" and "2", and one that demonstrates to your satisfaction that the matrices, vectors, and the stack structure are working.

Notes:

The computers in the CS labs have all the programs that you need to complete the assignments in this course. That said, the computers in the CS labs do not have every language/toolkit that you might want to use. If you choose to use any program or language that is not on the CS computers, you will have to bring in a notebook computer with the software installed. You are responsible to make sure that your code works on either your notebook computer or the CS computers. The TA will help as much as possible, but do not expect him to know languages/toolkits that are not commonly used. Thus, C++ (see Language Note below) is recommended, but not required.

Notes from the TA:

Compilation:
Sometimes it is difficult to get programs to compile if you don't know what you need to put on the command line. When I took the class, I started working on the CS computers. Then I decided that I wanted to work on my laptop computer instead. I couldn't get my code to compile because the command line arguments were a little different for Windows. I finally found a forum that had the solution on it, and I was able to compile my code. To save time, I have included here what I found. If you are using a different language or toolkit, feel free to tell me what you used to compile it so that I can post it here and save others time.
  • Linux
    • C++ with GLUT
      g++ lab1.cpp -l glut -o lab1
  • Mac OS X
    • C++ with GLUT
      #include <GLUT/glut.h>
      g++ lab1.cpp -framework OpenGL -framework GLUT -o lab1
  • Windows
    • C++ with GLUT (using Cygwin)
      g++ lab1.cpp -l glut32 -l glu32 -l opengl32 -o lab1
Language Notes:
  • ASM(Assembly)
    • Most whole-heartedly not recommended. Not only would you go crazy, but you probably wouldn't finish the projects on time, and any social life you may have had before will be gone. Even if you think you are the assembly master, you will probably have to deal with 2, 3, and maybe even 4 dimensional arrays. That would be your worst debugging nightmare.
  • C++
    • I have found C++ to be easier to use "out of the box" than Java, especially if you use a toolkit like GLUT that takes care of creating the window and using keyboard/mouse input. Of course, you then have to code the rest of the projects in C++. However, if you want a job in the game industry, C++ is your language of choice.
  • Java
    • On the NeHe page for Lesson 2 (mentioned above as a good starting point), there are 2 links for examples in Java. The link "Java" uses a library called "gl4java". It is somewhat difficult to find this library, but it can be found. You may have to check out the source code and compile it if you wish to use it. I would suggest you use the other link for Java ("Java/SWT"); however, if you use this, you will either have to use Eclipse or change the code to use some other SWT. Another option is to use another library called "JOGL" that binds java to the OpenGL api. This is also difficult to get to work. You can find it at https://jogl.dev.java.net/. Someone also implemented the NeHe lessons for JOGL, found at http://pepijn.fab4.be/software/nehe-java-ports/. Note that you will probably have to use ANT to compile the source code in the examples. Also note that since it is a fairly difficult process to use it, I reserve the option to not help students who wish to use this route if other students are waiting to be helped.
    • If you don't want to deal with the problems listed above, you may not want to use Java.
  • Perl
    • If you want to use Perl, you will have to install the OpenGL libraries on your account (or if you are working on Windows, you will have to install it on your laptop). To do so, go to http://search.cpan.org/~bfree/OpenGL-0.56/OpenGL.pod and download the source in a tarball or zip file (Windows-just use the binaries). The links are at the bottom of the page. Unzip or untar the files into your CS account in a place that is easy to specify. Run 'Makefile.PL' by using the command 'perl Makefile.PL'. This will give you a normal Makefile. Then, just type 'make', and it will create the necessary files in a folder called 'blib' in the same folder. Then, you need to include these files in your code. To do so, add the following 2 lines before the 'use OpenGL' call:
      BEGIN{ unshift(@INC,"../path_to_folder/blib/arch");}
      BEGIN{ unshift(@INC,"../path_to_folder/blib/lib");}
      After that, you should be good to go.
  • Python
    • Download the PyOpenGL package at http://sourceforge.net/projects/pyopengl/ and put it somewhere in your cs account. Then, from inside the first folder (where setup.py is), enter the following:
      python setup.py install --install-lib ~/path_to_folder/
      If you set your project folder as the path to install, then you are good to go.
    • If you decide that you would rather have the Python OpenGL package outside of your project folder, you can do so by adding the following lines of code:
      import sys
      sys.path.insert(0,"/users/guest/username_beginning_letter/username/path_to_folder")
      You can check your path using "pwd". Note that you cannot use "~/path_to_folder". It doesn't work.
  • Ruby
    • Ruby is also easy to use "out of the box". It also uses GLUT and can get you up and running quick.
    • Keep in mind that Ruby is an interpreted language, and may be slower than other alternatives.

E-mail: leemhoward@gmail.com