C++ - OpenGL - Installation

For this first OpenGL tutorial, we are going to see how to install OpenGL on GNU/Linux and Windows operating system.

We need the OpenGL files, but also those from the GLU and GLUT for GNU/Linux and freeGLUT for Windows.
The last ones, GLU and GLUT are libraries that add functionnalities from the basic OpenGL.

  1. OpenGL = Open Graphics Library
  2. GLU = Graphic Library Utility
  3. GLUT = Graphic Library Utility Toolkit

Installing OpenGL on GNU/Linux

Fedora

If you do not have the glut.h file in your /usr/include/GL/ directory, let's install it with the following command on your favorite shell:

sudo yum install freeglut-devel

Ubuntu

1) With Ubuntu Software Center

Don't forget to enable:

Edit > Software Sources... > Updates > Important security updates (precise-security).
Edit > Software Sources... > Updates > Recommanded updates (precise-updates).

Search for freeglut3 and freeglut3-dev.
Install them.

2) With apt-get

With apt-get and the following command line:

sudo apt-get install freeglut3

It will install the following header files (*.h) inside /usr/include/GL:

glext.h
gl.h
gl_mangle.h
glu.h
glu_mangle.h
glxext.h
glx.h
glx_mangle.h
internal/

Then with:

sudo apt-get install freeglut3-dev

It will install specific header files to develop software with OpenGL in the same directory as before (/usr/include/GL):

freeglut_ext.h
freeglut.h
freeglut_std.h
glut.h

Header files are now ready to be used.

Eclipse Juno IDE

In Eclipse right click on your project name then:
>Properties > C/C++ Build > Settings > Tool Settings > MinGW C++ Linker > Libraries.

On the right, two panels: one for the library names (-l) and the other for the library paths (-L).

On the Libraries (-l) tab, click on the tiny plus icon and add: glut and GLU.

Click Apply then OK.

Your Eclipse IDE is now ready to use OpenGL on Linux.

Installing OpenGL on Windows

Eclipse Indigo IDE

I choose Eclipse because I like it.
You are free to use another IDE of course.

To begin, we have to download the freeGLUT for Windows:

Click on Download freeglut 2.8.0-1 for MinGW.

Yes, you have to use MinGW (a tutorial is on my website, if you don't know what is it).

Once downloaded, extract the directory into another one, I choose: C:\soft\library\freeglut.

Now in Eclipse right click on your project name then:
>Properties > C/C++ Build > Settings > Tool Settings > MinGW C++ Linker > Libraries.

On the right, two panels: one for the library names (-l) and the other for the library paths (-L).

On the Libraries (-l) tab, click on the tiny plus icon and add: freeglut and opengl32.

On the Library search path (-L), click on the tiny plus icon and add: C:\soft\library\freeglut\lib

Click Apply then OK.

You have now to right click on your project name once again then:
> Properties > C/C++ General > Paths and Symbols > Includes > GNU C++.

On the right click Add... then add: c:/soft/library/freeglut/include.

On the Configurations dropdown menu, check if Debug or Release is selected (it will be important when you will try to compile).

Click Apply then OK.

Your Eclipse IDE is now ready to use OpenGL on Windows.

You can now use OpenGL with ease and voluptuousness.

Well done. smiley

Comments

Comment: 

What are the preconditions to follow this setup? I have Eclipse Juno with C++ installed, but anyway I get errors like "\workspace\demoCPP\Debug/../src/demoCPP.cpp:21: undefined reference to `glClear@4'" for each openGL command.

Comment: 

Hello Vladimir smiley

  1. Do you have MinGW installed too on your Windows OS?
  2. How do you compile your project?
  3. Check if in the Paths and Symbols panel you selected Debug in the Configuration dropdown menu (on the top right of the panel) in order to compile the project in Debug mode.

 

Comment: 

thank you

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.