Assignment 4: Intro to OpenGL

by asperling on March 3, 2015

This assignment is due Friday, March 13. It is meant to give you the opportunity to see an OpenGL program in action and expand on it.

Objectives

The goal of this assignment is to make sure that you are ready for the first project: That you have the mechanics in place (access to the compiler and library), can get partially written programs from us, and read through them to understand them. You’ll also get some exposure to OpenGL and C++. For the projects, you will get a large amount of framework code to start. Here, we’re giving you something smaller to play around with.

Setup

Part of this assignment is also to make sure your computing environment is set up correctly. You will need Visual Studio, FLTK, and GLM. See the previous tutorials for help getting those programs and setting them up. My project is configured so that it will run on the lab computers without any additional modifications. If you plan on working both at home and in the lab, I recommend matching your home setup to the lab’s, and make sure there are no naming conflicts with the programs.

My project and your task

My project was to give you a program where you can experiment with angles of rotation, as well as see some different ways objects are drawn in OpenGL.

You can download my program HERE. The project is set up to build and run on the lab computers without any additional changes.

The code itself has very few comments. It would probably score a 0 if we were grading comments. This was done on purpose. It might be useful to comment the code yourself as you understand what happens in each section.

Your task is to use this sample program to enhance your understanding of OpenGL. Exactly what you do is up to you. All of the concepts from class and SVG translate to OpenGL pretty well. If you get completely stuck, I suggest looking at the resources posted on Piazza, especially the “Legacy Tutorials” from nehe.gamedev.net (if you haven’t already.)

Here are some ideas to try:

  1. Right now, the program only supports object rotation. You should add sliders for scale and translation too.
  2. Add a button to change the duck or balloon to a random color (or a color you can choose.)
  3. Design a new object and draw it. Use hierarchical modeling to make it easy on yourself. I recommend making a train engine. (You’ll need one later.)
  4. Draw more than one object at once.
  5. For a challenge: make the program completely object oriented. Right now, everything is drawn within the a4_GL_Window class, but this is not ideal. In a more complex program, every object would have its own class with its own draw() function. The classes would keep track of additional attributes such as color, position, velocity, etc. depending on what you need. Having everything in one class is simple, but it leads to messy code, which you can probably see already.

What to turn in:

Please turn in a zip file with several screenshots showing any changes you made to the program. Also, please describe your changes and anything else you learned/liked/disliked in the Moodle text box.

Grading:

Check/No Check

More questions to think about:

You do not have to turn these in. They are from last semester, when we did not have students actually make changes to the program. (Some of the questions were answered in class already!)

  1. In class, we commented how with Euler Angles, you can have very different angles but get things that are close to each other in terms of the results. (so getting from one place to another is hard – a phenomenon called gimbal lock). Give 2 sets of angles (3 numbers) that give the same rotations (or very similar ones), but are far apart – for the type of Euler Angles used in Adam’s program. Confirm that these two sets of angles do indeed look the same in Adam’s program. Take a screen shot of one of those configurations. (note: your answer is 2 sets of 3 numbers – plus the screenshot). Avoid answers where the difference is on a single axis (e.g. +/- 180 degrees on any axis is the same rotation with very far away numbers).
  2. In class, we mentioned how physicists like to use ZXZ Euler angles (rather than the XYZ ones used in my program). What lines of code would you need to change in order to switch to ZXZ Euler angles and how would you change them?
  3. The slider callback for the rotation angles has a function call to “damageMe”. What does this do?
  4. The cube  has a red side. How would you change it to blue?
  5. Describe what you would add to the program in order to change the size of the triangle?
  6. What is the significance of the calls to glPushMatrix() and glPopMatrix() when drawing the duck? What happens when some (or all) of those calls are removed?
  7. Notice how the different objects don’t know where they get drawn – they just assume that the coordinate system was set up correctly. What assumptions do they make about the coordinate system they are being drawn in?
  8. Suppose you wanted to draw all objects at the same time, next to each other. How would you change the program?

 

 

Previous post:

Next post: