Sample code: the sample Makefile and source code build a simple line drawing application and runs on Linux, Mac OS X, and Windows platforms. You can also try out some examples with buffer objects and shaders.
For instructions on how to build GLUT programs, please refer to the course note Building OpenGL/GLUT Programs. Please let me know if you have any correction or addition. Thanks.
To find out how to specify command line options, add to header file search path, and link with libraries such as glew, expat, jpeg, and png, see the course note on these topics.
Linux:
version: Ubuntu 14.04.1 LTS (Trusty Tahr), 12.04.5 LTS (Precise Pangolin)
gcc: 4.8.2, 4.6.3
Eclipse 3.7.2-1 (Indigo)
First install GLFW’s dependencies, including OpenGL/Mesa:
sudo apt-get install cmake xorg-dev libglu1-mesa-dev
You must have sudo privileges. (On Red Hat, you’ll need to install cmake28 instead.)
You should now have:
/usr/include/GL
/usr/lib/x86_64-linux-gnu/libGL.so
At the time of writing, the GLFW package one gets with apt-get is version 2.7 whereas we’re using version 3.0.4. So we need to install GLFW from source. Unzip the source file and change your working directory to the glfw-3.0.4 directory. Install GLFW:
cd glfw-3.0.4
rehash
cmake -G "Unix Makefiles"
make
sudo make install
You should now have:
/usr/local/include/GLFW
/usr/local/lib/libglfw3.a
In your OpenGL source files, include the following line:
#include <GLFW/glfw3.h>
You don’t need to include gl.h as it is already included in glfw3.h.
For an example, see the provided sample source code.
If you want to include glu.h automatically, set the -DGLFW_INCLUDE_GLU compiler flag.
To make a GLFW application on the command line, use the following linker options:
-lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread
The last three libraries are needed on Ubuntu 14.04.1.
Eclipse 3.7.2 project (graphical step-by-step):
To install Eclipse:
sudo apt-get install eclipse eclipse-cdt
Start up Eclipse and choose your workspace, click “OK” (Fig. 1)
Open the C/C++ perspective: on the main menu select “Window→Open Perspective→C/C++” (Fig. 2). If the C/C++ perspective is not available, choose “Other…” and it should show up in the window that pops up.