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.
- Later in your OpenGL source files, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included in glut.h.
For an example, see the provided sample source code.
- 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, for example,
the provided sample.c (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: Lion 10.7.2 (11C2002)
kernel: Darwin 11.2.0
Xcode: 4.2.1
gcc: 4.2.1
version: SnowLeopard 10.6.4 (10FS69)
kernel: Darwin 10.4.0
Xcode: 3.2.4
gcc: 4.2.1
version: Leopard 10.5.8 (9L30)
kernel: Darwin 9.8.0
Xcode: 3.1.2
gcc: 4.0.1
version: Tiger 10.4.11 (8S165)
kernel: Darwin 8.11.0
Xcode: 2.0
gcc: 4.0.0
- Installation/verification:
OpenGL and GLUT come with the OS and Xcode
installations. To verify, check for:
/System/Library/Frameworks/{OpenGL,GLUT}.framework
[The installed GLUT is the
original GLUT
not freeglut.]
- Later in your OpenGL source files, 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 in glut.h.
For an example, see the provided sample source code.
- To make a GLUT application on the command line,
use the following linker options:
-framework OpenGL -framework GLUT
- Xcode 4.2.1 project (graphical step-by-step,
see below for older versions of Xcode):
- Create a new project:
- Select "File→New→New Project" (Fig. 18).
- Choose a template for your new project under Mac OS X (not iOS):
"Application→Command Line Tool" and click "Next" (Fig. 19).
- For the sample code, specify "Product Name" as "sampleapp",
"Company Identifier" as "sample", select "Type" "C", leave
"Use Automatic Reference Counting" checked and click "Next" (Fig. 20).
- A window pops up to prompt you where you want to put the new
project folder. In this example I've decided to put the project
project folder on my Desktop. Uncheck "Create local
git repository for this project" if you don't want it. Then
click "Create" (Fig. 21).
- In the leftmost pane, under "sampleapp" select "main.cpp" and
"sampleapp.1" and right click to Delete them
(Fig. 22). Click "Delete" on the
confirmation dialog box.
- Add source files:
Right click on "sampleapp" at the top of the left most pane and select
"Add Files to 'sampleapp'" (Fig. 23),
select your file, for example, the provided sample.c.
You can choose whether to copy added items into the project folder. I've
chosen to keep my source files in the project folder in this example.
Click "Add" (Fig. 24).
- Add libraries:
- In the middle pane, click the "Build Phases" tab, open
the "Link Binary With Libraries" list, and click the
'+' sign at the bottom left corner of the list (Fig. 25).
- A list of frameworks should pop up. Scroll down the list
to "OpenGL.framework" and click "Add" (Fig. 26). Repeat
for "GLUT.framework".
- Click on
to build and run the program.
- Older versions of Xcode:
- Graphical step-by-step for:
- Create a new project:
- Select "File→New Project"
- Choose a template for your new project:
- Xcode 3.2.4: "Application→Command Line Tool".
For the sample code, select project type "C" and click
"Choose" (Fig. 18bis3)
- Xcode 3.1.2: "Command Line Utility→C++ Tool" and
click "Choose" (Fig. 18bis2)
- Xcode 2: "Command Line Utility→C++ Tool" and
click "Next" (Fig. 18bis)
- Give the project a name, e.g., "sampleapp" and click "Save" (Fig. 19bis2)
[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. 21bis),
select your file, for example, the provided sample.c,
and click "Add" (twice)
- Add libraries:
- Right click on "sampleapp" again to "Add→Existing Frameworks" (Fig. 22bis)
[Xcode 3.1.2: double click on the "Frameworks" folder (Fig. 23bis)]
select OpenGL.framework and click "Add"
(Fig. 24bis) [Xcode3.1.2: twice]
- Repeat the previous step to add
GLUT.framework
(Fig. 25bis)
- Click on
to build and run the program.
Windows:
versions:
7 Enterprise
Vista x64 Enterprise Edition SP2 (Build 6002)
Vista Enterprise Edition SP2 (Build 6002)
XP Professional Edition SP3 5.1 (Build 2600)
Visual Studio 2010 version 10.0.30319.1 RTMRel
.NET Framework version 4.0.30319 RTMRel
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 2010/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\v7.0A\Include\GL\{GL,GLU}.h
["Program Files (x86)" for 64-bit Windows; VS2008: v6.0A]
- linker library:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\OpenGL32.Lib
["Program Files (x86)" for 64-bit Windows; VS2008: v6.0A]
If GLUT is not installed, you can install it by downloading the
glut zip file (v. 3.7.6) (web site)
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\v7.0A\Include\GL\glut.h
["Program Files (x86)" for 64-bit Windows; VS2008: v6.0A]
- linker library:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\glut32.lib
["Program Files (x86)" for 64-bit Windows; VS2008: v6.0A]
(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.
- Later in your OpenGL source files, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included in glut.h.
For an example, see the provided sample source code.
- Command line make: see the instructions for Cygwin below.
- Visual Studio 2010/2008 project (graphical step-by-step, all the screen shots are from VS2008, but are applicable to VS2010):
- 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),
select your file, for example, the provided sample.c,
and click "Add"
- 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;
[VS2008: with spaces in place of the semicolons]
as "Additional Dependencies" on the top of the right pane, hit
RETURN and 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
messages to the console,
in which case you may want to use Ctrl-F5 in the following step.
- Close the "Property Pages" pane by clicking "Ok", then click on the play button on the second menu bar
(
)
to build and run the program. If you print out messages to the
console, run the program using Ctrl-F5 instead,
to keep the cmd window from exiting after the program exits.
- To distribute your program, include the
glut32.dll file with
your distribution as it's most likely not installed on most Windows systems.
Cygwin:
Note that I haven't been able to get GLSL to work
under Cygwin/X and Windows 7.
version: NT-6.1 1.7.7(0.230/5/3)
version: NT-6.0-WOW64 1.5.25(0.156/4/2)
version: NT-6.0 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 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
- Later in your OpenGL source files, include the following line:
#include <GL/glut.h>
You don't need to include gl.h and glu.h,
as they are already included in glut.h.
For an example, see the provided sample source code.
- 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: Jan 28, 2012 by Sugih Jamin