Sie sind auf Seite 1von 4

Laboratory 1

Linux UBUNTU 12.04 INSTALATION

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

GLUT Setup Tutorial with Eclipse CDT on Windows


One of my biggest frustrations with programming in a different Integrated Development Environment
(IDE) or with a programming technology, is not knowing how to get started. There's generally a list of
things which need to be done and sometimes it's hard to find solid tutorials on the internet. I created
this tutorial to help bridge that gap. I've outlined and linked together the different steps necessary to get
started with GLUT/OpenGL and Eclipse's CDT (C/C++ Development Tooling). I will also assume that
the reader has some basic understanding of Eclipse, however I don't expect too much.
GLUT (Graphics Library Utility Toolkit) is an quick way to create OpenGL applications. It's cross
platform so you can port anything you create in Windows to a different operating system. GLUT will
take care of window management and input for your programs. OpenGL is a C based graphics library
and it is state based, so you can think of it as a switchboard.

1. Download Eclipse SDK 3.2.2 or newer at Eclipse.org/downloads


2. Install MinGW and the gcc/g++ compiler Compiler Setup
Eclipse CDT does not come with a compiler so you will have to install one. The easiest way is to use
MinGW (Minimalist GNU for Windows) and the gcc/g++ compiler. The compiler comes with the
necessary header and library files for programming with OpenGL, but you will need to add several
GLUT files in step 4.

3. Install the C/C++ Development Tooling (CDT)


CDT is an environment which allows you to develop in C/C++ using Eclipse. It's relatively easy to
download the plug-in from inside Eclipse.
a. Go to Help -> Software Updates -> Find and Install
b. Choose "Search for New Features to Install" and click on both "Callisto Discovery Site" and "The
Eclipse Project Updates"
c. Choose an "Update Site Mirror" and install any updates for Eclipse and then install "C and C++
Development" (CDT) from the Callisto Discovery site.

4. Download and setup GLUT


a. Download GLUT MinGW
b. Place glut32.dll in your C:\Windows\System32 folder
c. Put glut.h in the folder C:\MinGW\include\GL folder and libglut32.a in C:\MinGW\lib (These
folders are relative to where MinGW was installed).

5. Start a new C/C++ Project in Eclipse


a. Go to File -> New -> Project, and choose "Managed Make C++ Project" from the wizard.
b. Name the project and press Next -> Finish.
3

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.

6. Create a simple GLUT C++ program


a. Right click on the project name -> New -> Source File.
b. Paste the code from Demo.cpp into the empty source file and save it. Eclipse will automatically
compile the code and if everything was setup correctly you shouldn't see any compilation errors.
NOTE: When you create programs using GLUT, you need to include windows.h and any standard
library header before the glut.h header file.
c. Run the program by right clicking on the Project Name -> Run As -> Run As Local C/C++
Application
c. Now you have a basic GLUT OpenGL window which can be used to create 2D/3D applications.

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/

Das könnte Ihnen auch gefallen