Beruflich Dokumente
Kultur Dokumente
This time we focus on how to set up OpenGL for your Ubuntu 12.04. For this task freeglut is going to
be used. This is a open source and up to date alternative to the OpenGL Utility Toolkit. The official
description of the freeglut project says that
freeglut is a completely OpenSourced alternative to the OpenGL Utility Toolkit (GLUT)
library. GLUT was originally written by Mark Kilgard to support the sample programs in
the second edition OpenGL 'RedBook'. Since then, GLUT has been used in a wide variety
of practical applications because it is simple, widely available and highly portable.
GLUT (and hence freeglut) allows the user to create and manage windows containing
OpenGL contexts on a wide range of platforms and also read the mouse, keyboard and
joystick functions.
Step 1 - Install Compiler and necessary tools.
Since we are going to be programming with C++ , it is important to have the tool in your computer.
This following command will install a c++ compiler and cmake which is used to manage projects.
sudo apt-get install g++ cmake
Step 2 - Lets install freeglut.
sudo apt-get install freeglut3 freeglut3-dev
Step 3 - Lets install GNU gold linker utility.
sudo apt-get install binutils-gold
Done ! But we need to test it.
Now you can create a simple test program.
Step 3 - Test program - Create a 'main.cpp'
1 #include <GL/glut.h>
2
3
4 void draw(void) {
5
6
// Black background
7
glClearColor(0.0f,0.0f,0.0f,1.0f);
8
glClear(GL_COLOR_BUFFER_BIT);
1
9
//Draw i
10 glFlush();
11
12 }
13
14 //Main program
15
16 int main(int argc, char **argv) {
17
18 glutInit(&argc, argv);
19
20 /*Setting up The Display
21 / -RGB color model + Alpha Channel = GLUT_RGBA
22 */
23 glutInitDisplayMode(GLUT_RGBA|GLUT_SINGLE);
24
25 //Configure Window Postion
26 glutInitWindowPosition(50, 25);
27
28 //Configure Window Size
29 glutInitWindowSize(480,480);
30
31 //Create Window
32 glutCreateWindow("Hello OpenGL");
33
34
35 //Call to the drawing function
36 glutDisplayFunc(draw);
37
38 // Loop require by OpenGL
39 glutMainLoop();
40 return 0;
41 }
Step 4 - Let's Compile it
The first and the easiest option to compile is by using the command :
g++ -lGL -lglut main.cpp -o test
Step 5 - Run it
./test
c. After you finish creating the project you need to change the project settings to include the
OpenGL and GLUT libraries. Highlight the new project and go to Project -> Properties.
d. Choose "C/C++ Build" and select "Libraries" from under the "GCC C++ Linker" branch.
You need to add glut32, glu32, and opengl32 to the list of libraries.
Notes:
Make sure that you include the glut32.dll with your program if you are going to redistribute it.
Reference:
1. OpenGL SUPERBIBLE, Fifth Edition, Richard S. Wright, Jr., Nicholas Haemel, Graham Sellers, Benjamin
Lipchak;
2. OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition)
Dave Shreiner;
3.
4.
http://www.opengl.org/resources/libraries/glut/
http://www.opengl.org/