Installing and Using GLUT and OpenGL
Sample code: the sample Makefile and
source code
build a simple line drawing application
and have been written to be portable across Linux, Mac OS X, and Windows platforms.
Please let me know if you have any
correction or addition. Thanks.
Linux:
version: Fedora 10
kernel: 2.6.27.24-170.2.68.fc10.i686
gcc: 4.3.2-7
version: RedHat Enterprise Linux Client Release 5.3
kernel: 2.6.18-128.el5
gcc: 4.1.2-44
Eclipse 3.2.0
- Installation/verification:
OpenGL comes with the X11 installation, to verify:
% glxinfo
you should see something like the following:
server glx vendor string: SGI
server glx version string: 1.2
Or look for the following files:
- libraries:
/usr/lib/lib{GL,GLU}.so.*
- header files:
/usr/include/GL/{gl,glu}.h
If GLUT is installed, it will be visible as:
- library:
/usr/lib/libglut.*
- header file:
/usr/include/GL/glut.h
If OpenGL and/or GLUT is not installed on your system,
you can install both with:
# yum install freeglut-devel
which should install all the dependent packages,
including OpenGL itself.
- In the source codes, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included by glut.h.
- To make a GLUT application on the command line,
use the following linker options:
-lGL -lGLU -lglut
- Eclipse 3.2.0 project (graphical step-by-step):
- Start up Eclipse and choose your workspace, click "OK" (Fig. 1)
- Create a new project:
- Select "File→New→Project" (Fig. 2)
- Choose a wizard for your new project:
"C++→Managed Make C++ Project" (Fig. 3)
- Give the project a name, e.g., "sampleapp",
click "Next >" (Fig. 4)
- On the "Select a type of project" page,
accept "Project Type: Executable (Gnu)"
by clicking "Finish" (Fig. 5)
- If prompted to "Open Associated Perspective?",
click "Yes" (Fig. 6)
- Add libraries:
- Right click on "sampleapp" on the first line of the "C/C++" pane on the left and
select "Properties" to tell the linker which libraries need to be added (Fig. 7)
- On the "Properties for sampleapp" page,
click "C/C++ Build→GCC C++ Linker→Libraries" and
click on the "Libraries (-l) Add" button (Fig. 8)
- Type in "GL" and click "OK" (Fig. 9)
- Repeat the above two steps to add "GLU" and "glut" libraries
then click "Apply" and "OK" (Fig. 10)
- Add source files:
- Right click on "sampleapp" again and select "Import" (Fig. 11)
- On the "Select" page, choose "General→File System" and click "Next >" (Fig. 12)
- On the "File system" page, click the "Browse" button next to "From directory:" (Fig. 13)
- Choose the directory where the source file resides and click "OK" (Fig. 14)
- Click on all the source files on the right pane you want imported
(or click the directory name on the left pane to import all files in the directory) and
click "Finish" (Fig. 15)
- Click on the play button on the second menu bar
(
) to build and run the program:
- On the "Create, manage, and run configurations" page,
double click on "C/C++ Local Application" (Fig. 16)
- On the "sampleapp" configuration page, click "Run" (Fig. 17)
Mac OS X:
version: Tiger 10.4.11 (8S165)
kernel: Darwin 8.11.0
Xcode: 2.0
gcc: 4.0.0
version: Leopard 10.5.8 (9L30)
kernel: Darwin 9.8.0
Xcode: 3.1.2
gcc: 4.0.1
- Installation/verification:
OpenGL and GLUT come with the OS and the XcodeTools
installations. To verify, check for:
/System/Library/Frameworks/{OpenGL,GLUT}.framework
The installed GLUT is not freeglut
but the original GLUT.
- In the source code, include the following line:
#include <GLUT/glut.h>
Despite Apple's documentation, you don't need to include gl.h and glu.h,
as they are already included by glut.h.
- To make a GLUT application on the command line,
use the following linker options:
-framework OpenGL -framework GLUT
- Xcode project (graphical step-by-step [Xcode2]):
- Create a new project:
- Select "File→New Project"
- Choose a template for your new project:
"Command Line Utility→C++ Tool" and click "Choose" (Fig. 18) [Xcode 2: click "Next" (Fig. 18bis)]
- Give the project a name, e.g., "sampleapp" and click "Save" (Fig. 19) [Xcode 2: click "Finish" (Fig. 19bis)]
- Right click on file "main.cpp" to Delete it (Fig. 20)
- Add source files:
Right click on "sampleapp" at the top of the "Groups & Files" pane on the left to
"Add→Existing Files" (Fig. 21)
- Add libraries:
- Right click on "sampleapp" again to "Add→Existing Frameworks" (Fig. 22)
double click on the "Frameworks" folder (Fig. 23)
select OpenGL.framework and click "Add" (twice)
(Fig. 24)
- Repeat the previous step to add
GLUT.framework
(Fig. 25)
- Click on
to build and run the program.
Windows:
versions:
XP Professional Edition SP3 5.1 (Build 2600)
Vista Enterprise Edition SP2 (Build 6002)
Vista x64 Enterprise Edition SP2 (Build 6002)
Visual Studio 2008 version 9.0.21022.8.RTM
.NET Framework version 3.5 SP1
- Installation/verification:
OpenGL comes with the OS and Visual Studio 2008
installations, to verify:
- runtime libraries:
C:\Windows\System32\{opengl,glu}32.dll
on 64-bit Windows:
C:\Windows\SysWOW64\{opengl,glu}32.dll
- header files:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\GL\{GL,GLU}.h
- linker library:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\OpenGL32.Lib
If GLUT is not installed, you can install it by downloading the
glut zip file (v. 3.7.6)
and copying its files to the correct folders as follows:
- runtime library:
C:\Windows\system\glut32.dll
- header file:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\GL\glut.h
- linker library:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\glut32.lib
(Alternatively, some installation put the GLUT dll in the same directory as the OpenGL/GLU dlls
and the header and linker library files under
"C:\Program Files\Microsoft Visual Studio 9.0\VC\"
("Program Files (x86)" for 64-bit Windows).)
Unlike the freeglut packages for Linux and Cygwin,
the pre-compiled freeglut for Windows
available on the Net was not built to be a drop-in
replacement for the original GLUT, in terms of file naming convention,
and is therefore not compatible with this GLUT usage instructions.
- In the source code, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included by glut.h.
- Command line make: see the instructions for Cygwin below.
- Visual Studio 2008 project (graphical step-by-step):
- Create a new project:
- Select "File→New→Project" (Fig. 26)
- Choose a template for your new project:
"Visual C++→Win32→Win32 Console Application",
give the project a name, e.g., "sampleapp"
and click "OK" (Fig. 27)
- On the "Welcome to the Win32 Application Wizard" page,
click "Next >" (Fig. 28)
- On the "Application Setting" dialog box, under "Additional options"
tick "Empty project", then click "Finish" (Fig. 29)
- Add source files:
Right click on "sampleapp" on the second line of the "Solution Explorer"
pane on the left to "Add→Existing Item" (Fig. 30)
- Add libraries:
- Right click on "sampleapp" again and select "Properties" to tell
the linker which libraries need to be added (Fig. 31)
- On the "Property Pages", under "Configuration:" tell
VS to add the additional libraries to "All Configurations" (Fig. 32)
- Select "Configuration Properties→Linker→Input" on the left pane,
and enter:
opengl32.lib glu32.lib glut32.lib
as "Additional Dependencies" on the top of the right pane,
then click "Apply" (Fig. 33)
- Optional:
To prevent your program from opening a console window, while still on
the "Property Pages",
select "Configuration "Properties→Linker→Command Line"
on the left pane, and enter:
/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
as "Additional options" at the bottom of the right pane, then click "Apply"
(Fig. 34)
You may not want to disable the console window if you print out debugging
statements to the console.
- Click on the play button on the second menu bar
(
) to build and run the program.
- To distribute your program, include the
glut32.dll file with
your distribution as it's most likely not installed on most Windows systems.
Cygwin:
version: NT-6.0 1.5.25(0.156/4/2)
version: NT-6.0-WOW64 1.5.25(0.156/4/2)
gcc: 3.4.4
- Installation/verification:
Use the Cygwin setup program
to install the following packages:
Devel→gcc-g++
Graphics→libglut-devel
Xhost→xinit
Installing libglut-devel will install all dependent packages.
The GLUT you get is actually freeglut.
Your GLUT programs will run under X11, so you need to install X11 (xinit) also.
To verify installation, look for the following files:
- runtime libraries:
/usr/lib/lib{GL,GLU,glut}.dll.a
- header files:
/usr/include/GL/{gl,glu,glut}.h
- In the source code, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included by glut.h.
- To make a GLUT application on the command line,
include the following linker options:
-lGL -lGLU -lglut
References not cited:
- Bradford, J., Using OpenGL & GLUT in Visual Studio .NET 2003, 2006.
- Nakano, A., How to Install OpenGL, 2008.
- Hewgill A. and Bockus, D., Setting up Microsoft Visual Studio .NET for OpenGL/GLUT and Free Image, 2005.
- Wong, A., OpenGL on Cygwin, 2007.
- LQWiki, OpenGL.
Last updated: September 3, 2009 by Sugih Jamin