Computer Engineering 519 Project 1 Page

Computer Engineering 519 (Graphics) Project 1 Page

This project was meant as a general, quick introduction to OpenGL programming. It introduced many of the very basic OpenGL functions. It also served as an introduction to using the SGI RapidApp tool to develop motif-based user-interfaces. This project helped me discover many of the weird intracies of OpenGL program, especially with respect to Motif. I will discuss some of the problems I encountered in the project further in this description.

This project also helped introduce some of the basic computer graphics ideas, such as translation. Since we weren't really supposed to use the OpenGL matrix functions, it became relatively obvious how useful OpenGL can be in simple graphics operations.

The basic premise of this project was to draw four objects on the screen and then manipulate them with the mouse. Three of the shapes were pre-determined: a triangle, a square/rectangle, and a circle. For the fourth shape, I chose a regular hexagon.

The manipulations included being able to move the objects and change their colors. Also, there needed to be an exit function and the ability to reset the shapes' colors and locations in the event that things got messed up beyond simple repairs.

Figure 1: The Initial Program Appearance (click to enlarge)

Figure 2: Program Appearance after maniupulations (click to enlarge)

The program is relatively simple to use. The left mouse button controls all moving of on-screen objects. The right mouse button will reset the shapes to their original locations and colors. There is also a button to reset the shapes and a menu option. To exit the program, click the exit button or select Exit from the File menu.

The middle mouse button is responsible for changing the colors of the objects. There are two similar ways of doing this. If the RGB sliders on the right side are adjusted to a color and the middle button is clicked on a shape, the shape will change to that color. Once a shape has been selected with the middle mouse button the RGB sliders will allow adjusting the color. This makes it easy to change all of the shapes to one color. It also makes it somewhat easy to change to red, green, or blue, or the simple mixtures of them (purple, cyan, yellow, black, and white).

Non-RapidApp Generated Code

The code is fairly straightforward and easy to follow, at least I think so. One of the more interesting (in my opinion) things I chose to do was the draw_reg_poly() function. Since the circle, square, and triangle can all be formed as regular polygons (and I chose to do a regular hexagon as my fourth shape), this function made it quite easy to draw all of the shapes. The function takes a structure defining a 3-point vector for the center of the shape, a pointer to a regular polygon structure (more later), a radius, the number of sides, and another 3-point vector for the color information. The function uses trig functions to approximate a circle and draw the 3 other regular polygons. For quick reference, the function is here I don't think the method is very efficient, but it certainly works for this project. Treating all of the objects as regular polygons also made the mouse-pointer-in-shape question somewhat easier. However, it is also somewhat in-accurate. I basically check to see if the mouse is in a box centered at the shape's center and extending the 'radius' on both sides. This allows for a great deal of space that isn't necessarily part of the shape to be considered part of the shape. However, it reduces checking from many, many if conditions to just 4. Using one of the standard image collision type algorithms would have made this job simpler too, but since they haven't been introduced, I decided to use this method.

When the user moves an object, the new object position is calculated and the new shape is drawn, along with the unchanged objects. Then, the GL drawing buffers are swapped. I tried this process in my color changing routines but discovered that GL calls don't work well in the Motif widget callback functions. To fix this, I call the GL drawScene callback in the RGB scale drag callbacks. This seems to work much better.

In developing the code for this project, I had some difficulty at first with the RapidApp program. I am not a C++ programmer and I had never used RapidApp before. I actually wrote the program and had it about 80% working with GLUT a week ago, but spent of this week dealing with RapidApp. I actually might write the next project with Motif but without using RapidApp. The RapidApp/OpenGL combination also seems to be poorly documented. I was unable to figure out some important properties of the OpenGL drawing area, such as the Y height from the widgets. However, this was quite a fun project. I really enjoyed doing it. Hopefully the next ones will go well also.