Creating an OpenGL development environment in Ubuntu Linux


OpenGL is an independent graphics API, and freeglut is the successor of  OpenGL Utility Toolkit (GLUT) which offers a plain procedure for creating and handling windows and also other functions in various other platforms. This post describes how these packages could be installed in Ubuntu, and utilized in an easy C++ program to test if are working properly. There are things that must be included before OpenGL and freeglut can be created and used within the system.

  • Ubuntu 10.10).
  • graphics card must be used and the mandatory drivers must be installed
  • The packages required for needed for C/C++ compilation must be} installed.
  • install the build-essential package,

Installing the OpenGL and freeglut Libraries

sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev

if one of the packages or both of them are installed , the kernel gives a message notifying you the packages seem to be installed, after  OpenGL and freeglut libraries are configured , the next step should be to use a simple program and test if everything works correctly, to determine if the environment created can start designing and coding OpenGL graphics applications. Copy and paste the simple code program into a text editor:

#include "GL/freeglut.h"
#include "GL/gl.h"/* display function - code from:
This is the actual usage of the OpenGL library. 
The following code is the same for any platform */
void renderFunction()
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glColor3f(1.0, 1.0, 1.0);
    glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5, 0.5);
        glVertex2f(0.5, 0.5);
        glVertex2f(0.5, -0.5);
}/* Main method - main entry point of application
the freeglut library does the window creation work for us, 
regardless of the platform. */
int main(int argc, char** argv)
    glutInit(&argc, argv);
    glutCreateWindow("OpenGL - First window demo");
    return 0;

After you type in the above code in a text editor and save it as a CPP file, window.cpp open a terminal window and proceed to window.cpp. Typing the command g++ window.cpp -lglut makes you able to compile the program and make it executable. The -lglut is to link the file to the freeglut library.  Running the executable by typing ./a.out at the terminal should display the above code listing.


Comments are closed.

%d bloggers like this: