Computer Graphics Course
(Handout and Project Report)
Written by: Sadi Evren SEKER Home Page
Instructor: Ali Vahit Sahiner
1. Installation Issues
1.1. Installation guide for Linux
Mesa is one of the most powerful open GL libraries under Linux. It is included in installation files for RedHat 7.0 and Caldera. They are in rpm (Redhat Packet Management) format and can be installed by using "rpm -i mesa.rpm" command string (if not installed).
Installed version can be queried by using "rpm -q mesa".
There are 2 different packages mesa-devel for development and library parts.
Mesa package, for examples and applications.
Default directory for installation is /usr/X11R6/lib/mesa (which contains examples, demos, and applications on book)
Library files are uncompressed to /usr/X11R6/lib folder.
By the way GL and GLUT files are installed to Linux system
1.2. Installation guide for Windows
Glut can be downloaded from www.opengl.org.
Unfortunately opengl can only run over visual studio. To complete installation glut.dll has to be compiled. There is a readme for steps of installation. There is a dip file for visual studio workspace. It should be loaded from visual studio and in project menu all should be selected to make all.
2. Compiling and Executing
2.1. Compile under Linux
To compile a code (e.g. sadi3.c) the following command should be entered from command line. This command line will be output a binary executable file called sadi3.
gcc sadi3.c -o sadi3 -lglut -lGL -lGLU -L/usr/X11R6/lib -lXmu –lm
2.2. Compile under windows
To compile a code (e.g. sadi3.c) under windows, file should be opened by visual studio (visual c). Compilation is done when build option is selected from build menu. sadi3.exe file will be created under debug directory from current location of file.
2.3. Execution under Linux
To execute a compiled open GL file it is necessary to initialize an X environment. It is not important to run an environment manager (like KDE or GNOME) but X server should be executed.
By the way on the graphical user interface by only typing the executable file name out put will be created on the screen. So you should go to location of file you want to execute and type it name. (e.g. to run a file under /mesa/odevler I will type cd /mesa/odevler and give the execute command ./sadi3 to run file)
2.4. Execution under windows
To execute a compiled file you should go to the location of file and than the subdirectory debug to see filename.exe. Rest is simple to execute only a double click over the executable file is enough. If you want to run under visual studio environment. You should select the run option under debug menu.
3. Model programs
Both windows and Linux environments has example codes after installation (for Linux you should install mesa packet to see examples).
5.1. Statement of Purpose
I have wanted to code a program to rotate, translate and scale a cube.
5.2. Analyze of project
For this project there has to be a matrix form of cube to implement functions over the cube. So I have used polygon implementation in open GL libraries. By the way cube is displayed as a smooth object else it would be displayed as a wired cube.
Next analyze in the project is the light, view port and color of the object. So there has to be static view-port and a light source to see the object.
After the drawing of object scaling translating and rotating should be designed.
5.3. Design of project
Design of cube is simple; there is an array, which keeps the coordinates of point of cube. There are 8 points for a cube and each point has 3 float number to keep coordinates (x,y,z axises) so I have a 3 by 8 array.
Design of color and light is again very simple I have implemented them inside an array. Color has 3 parameters Red, Green, Blue. For implementation of the color there has to be a 4th parameter for the diffuse of color. Design of light is done by using an array again, 3 parameters for coordinates of light (x,y,z axises) and the range of light is inserted in 4th parameter of light array.
There are 2 different rotating algorithms; 1st algorithm rotates on a scalar origin and object rotates around this origin, 2nd algorithm rotates the object around itself. For the case rotating around itself is more complex, so I have implemented 2nd algorithm.
Translating and scaling is implemented by using scalar addition and scalar subtraction. For example zoom in will add some scalar values to each coordinates of cube or zoom out will subtract some scalar values form coordinates of points which builds cube. Same algorithms used for translating, for example for moving cube in z direction all z values of points should be increased (or decreased, relative to the direction of move).
5.4. Implementation of project
Implementation of cube is done by using the following array.
So this v array is 8 by 3 array (as discussed in design phase) and initial values of each coordinates are implemented related to origin. So center of my cube is in origin.
Implementation of color and light is done by the following statements in the program.
In array named light_diffuse you can see only first parameter is 1.0 this means only red value is on (remember the order of this values are red, green, blue).
In array named light_position x, y and z values are 1 so our light source is located in 1,1,1 point and range of light is infinite (which is declared on last parameter by the value of 0.0)
The variables above are the teta degree of rotation. So I use 3 teta angle for 3 dimension so there may be 3 mutually exclusive rotation. I have used 2 different teta values for a simple rotation that’s why I have to convert the teta degree to teta radian.
Implementation of given functions over this array is done by mathematical operations.
So the above code is used to rotate cube on x axis. That’s implemented by using the formula:
After the calculation operation we have to increase the value of teta (for this example we keep degree value of teta in ty variable) for continuous rotation. The rest of the code is printing out the value of matrix for debug.
For translation operation we have wanted to move the object on any given axis.
That’s the code I have used for both outputting the value of matrix and increasing the value of all matrices by 0.01 (This value is selected for slowly translation, increasing or decreasing this value will yield different changes on the object).
For scaling operations we have wanted to make the cube smaller or greater. So I have used the coefficients 1.1 for increasing the scale of cube or 0.9 for decreasing the scale of cube.
This code is implemented to increase the scale of matrix (in reference point it is decreased so you see cube greater) and output the new value of matrix to screen.
During this project and all applications written for open GL I have learned how to implement mathematical formulas over geometric shapes by using the language C.
The whole background of computer graphics depends on mathematical operations. And these operations should be transferred to computer world by using a language. We have selected C for this mission and used the libraries of open GL. So this makes easier to output shapes to screen by using C.
I think this implementation of graphics can be easily used in any design tool.