OpenGL Programming/Installation/Linux

OpenGL Installation on LinuxEdit

Most Linux distributions rely on the Mesa3D project to provide their OpenGL implementation. This supplies libraries for regular OpenGL as well as OpenGL ES 1.x and 2.0.

The exact names of the packages you need to install are highly dependent on distribution. Referring to your distro's packages can save you a lot of time and headache in installation. Use your favorite package manager and search for the package name. You may need to install packages that come with a dev suffix, these are development packages (usually header files). Also look for packages with a lib prefix, which refer to libraries.

Install the GCC C/C++ compilers and associated tools such as make.

All in all, install

  • mesa
  • make
  • gcc

LibrariesEdit

In this wikibooks, we'll make great use of GLEW, FreeGLUT and GLM, make sure you install the development libraries:

  • glew
  • freeglut
  • glm

If GLM is not available in your distribution repository, you have the option to install it manually. Make sure the headers end in the /usr/include/glm directory. Since it's a headers-only library, you do not need to compile a .so library - just copy the code there.

DriversEdit

OpenGL is the primary 3D graphics API on GNU/Linux-based systems. If your device supports 3D acceleration on GNU/Linux, it probably includes an OpenGL distribution.

OpenGL is included in drivers, so you'll have to make sure drivers are properly installed if you want to enjoy programs using OpenGL. Open source drivers actually make use of Mesa's OpenGL implementation. Proprietary drivers embed their own OpenGL library.

Proprietary optionsEdit

Nvidia provides generally excellent but non-free drivers via the nvidia driver from their website. fglrx drives many modern AMD devices; it is also closed-source, and available from AMD's website.

Free/Open-Source optionsEdit

If your CPU is an Intel one with built-in graphics, then the necessary open-source drivers come as a standard part of the Linux kernel.

If you have one of the newest chips, you may be forced to use the mediocre fglrx driver. However since AMD released the specifications for their chips, the open source 'radeon' made its way to become a full-featured 2D and 3D driver.

As of June 2013, most AMD chips will run well with the open source 'radeon' driver. 3D performance is still better with the AMD Catalyst driver on modern cards, but this may change in the future. Check the feature matrix for a completion status.

The open-source nouveau driver supports nVidia chipsets, but at the time of writing is not as complete as nVidia's closed-source drivers, 3D support may not be satisfactory.

The OpenGL driver on Linux systems consists of two files:

  • libGL.so for the GL itself; libGL.so must be accessible to the Linux library loader (refer to man pages for ldconfig);
  • glx.so (this name may vary) for Xorg support for OpenGL; glx.so will be in Xorg's extensions path and must be loaded by xorg.conf (refer to man pages for xorg.conf).

Many OpenGL applications require libGLU.so as well; GLU operations are not hardware-accelerated, so the implementation provided by Mesa is an excellent option.

Check your OpenGL installationEdit

Type this in a terminal to get much info about your OpenGL driver, including supported extensions:

glxinfo | grep OpenGL

IDEsEdit

The tutorials will mostly rely on simple Makefiles to build the code, and let you edit the source with your favorite text editor, such as Emacs, vim, gedit, kwrite, etc.

Several IDEs exist for GNU/Linux, such as:

  • Code::Blocks
  • Anjuta
  • KDevelop
  • Eclipse CDT

It is very simple to adapt the Makefiles to these environments.

Installing your own OpenGL headersEdit

In the unlikely event that your distribution does not supply packages for Mesa3D, you can build it from source with the usual

 ./configure
 make
 make install

installation procedure; however, be careful of conflicting opengl libraries.

Mesa's software implementation may override your distribution's libraries or libraries manually installed, such as the nvidia or fglrx OpenGL binaries. When this happens, search all directories listed with

ldconfig -Nv 2>/dev/null | awk -F: '/^\// {print $1}'

for libGL.so. The following command should output all the different OpenGL libraries available on your system:

find $(ldconfig -Nv 2>/dev/null | awk -F: '/^\// {print $1}') -name libGL.so -exec realpath {} \; | sort -u

It is usually OK if you have one the mesa library plus the proprietary library. On 64-bits systems, you may also have the lib32 library. Additional copies of libGL.so found in the ld search path (specified in /etc/lf.so.conf by default), if not referring to the same file, usually indicates a conflict. Remove all but the copy you want executed.

The headers will be installed to $PREFIX/include/GL (usually /usr/include/GL when installed from a packaged, or /usr/local/include/GL when installed manually from source).

"Official" OpenGL headers are available from SGI, however, they are hopelessly out of date.

< OpenGL Programming/Installation

Browse & download complete code
Last modified on 13 March 2014, at 14:02