1. Installation Issues

1.1. Installation report on 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 report on Windows

Glut can be downloaded from

Unfortunately opengl can only run over visual studio. To complete installation glut.dll has to be compiled. There is a read me 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. Example programs

Both windows and Linux environments has example codes after installation (for Linux you should install mesa packet to see examples).


5. Project

5.1. Introduction

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.

v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;

v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;

v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;

v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;

v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;

v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;

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.

GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */

GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */

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)