CS 381 HW3--OpenGL!

This homework is based on the "glsl_bare" program. You can download buildable source and a prebuilt binary for Windows and Linux (Zip, Tar-gzip).  You WILL have to recompile this program to finish this homework, so try out your compilers early! It's been tested with Visual C++ 2003 in the Chapman Lab, Visual C++ 2005 "Express" (download free from Microsoft), Code::Blocks, and Linux.

I'd like you to write ONE program that does the following things:

  1. Set the background color to a nice purple color.
  2. Rather than having a stack of big triangles arranged one behind another, make a little 10-by-10 grid of triangles on the X-Y plane. Each triangle should have its two 0.1-length sides at a right angle. Make triangles of at least two different colors, at at least two different Z values. Triangles of a given color shouldn't overlap.
  3. Compute the transform and projection matrix in C++, and pass it into your vertex shader. The vertex shader uniform mat4 should be called "mF" (matrix--Final). Like the matrix computation already in "vertex.txt", changing "spin_x" and "spin_y" should rotate by one complete revolution about the x and y axes respectively, and the perspective matrix should divide by z+1.5.
  4. Change the reshape routine and projection matrix so that the aspect ratio of the displayed image is square no matter how stretched the window gets. Your 45-45-90 triangles above should actually show up with a 45-degree hypotenuse even in a low, squashed window. No, you can't wimp out and require square windows, or change the glViewport to always display a square--you've got to fill the window!

Here's an example of what I'm looking for overall, although you're free to make something cooler. Problem 1 is finished because the background is now purple. Problem 2 is finished because I've got grids of both red and green triangles, and the green triangles are deeper than the reds (this is tough to see in a static image!). Problem 3 is finished because I do my matrix stuff in C++ (though you can't see it!). Problem 4 is finished because the triangles are square even though the window isn't.
grid of red and green triangles

Turn in your finished C++ "main.cpp" and vertex program "vertex.txt" files via Blackboard. Please do NOT turn in any of the OpenGL libraries included in glsl_bare--I've already got 'em, thanks! Due midnight Thursday, September 28th.  WARNING: If your C++ or vertex programs don't compile, you won't get any points!  Be sure to try them out before submitting them! Even though you turn in a single program, you will get credit for any problems you complete, even if you can't finish all the problems...

If Blackboard doesn't work for you, or you don't have an account, you can email this homework to me at ffosl@uaf.edu.

Back to CS 381 Home Back to CS Home Back to UAF Home