Platform specifics: Linux

From OpenGL Wiki
Jump to navigation Jump to search

This Section explains how to install Drivers to make OpenGL Programs run under Linux and how to use different Libraries/Toolkits to create Opengl Programs.

The standard OpenGL implementation used on Linux systems is Mesa3D. As of this writing, it provides implementations of OpenGL (up to version 3.0), as well as OpenGL ES, both versions 1.1 and 2.0. It includes a software-only implementation of the entire GL stack, but can also use hardware-specific drivers.

Mesa3D & DRI

Direct Rendering Infrastructure, also known as the DRI, is a framework for allowing direct access to graphics hardware under the X Window System in a safe and efficient manner. It includes changes to the X server, to several client libraries, and to the kernel (DRM, Direct Rendering Manager). The most important use for the DRI is to create fast OpenGL implementations providing hardware acceleration for Mesa. Several 3D accelerated drivers have been written to the DRI specification

DRIconf is a configuration applet for the Direct Rendering Infrastructure. It allows customizing performance and visual quality settings of OpenGL drivers on a per-driver, per-screen and/or per-application level. The settings are stored in system wide and per-user XML configuration files

  • DRI libgl1-mesa-dri
    • /etc/drirc
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/lib/x86_64-linux-gnu/dri/
    • /usr/share/bug/libgl1-mesa-dri/control
    • /usr/share/bug/libgl1-mesa-dri/script
    • /usr/share/doc/libgl1-mesa-dri/changelog.Debian.gz
    • /usr/share/doc/libgl1-mesa-dri/copyright
    • /usr/share/lintian/overrides/libgl1-mesa-dri

Mesa3D & GLX

  • OpenGL application on X Windows must use GLX, a standardized API, to set up a rendering context;
  • GLX API is closely coupled with Xlib;
  • OpenGL library also provides the GLX API implementation;
  • GLX system has two roles, it communicates with the X server and initializes client-side and hardware state. The GLX client-server communication takes place using a standardized GLX wire protocol, which is an extension to the X network protocol;
  • GLX library abstracts all client-side and hardware initialization and the internals of the process are hidden in the OpenGL implementation library;
  • GLX API is specified in terms of Xlib, the glX functions use Xlib Displays, Windows, Visuals, etc. The GLX implementations are also built using Xlib;

glxinfo is a command-line tool that can help you diagnose problems with your 3D acceleration setup

  • GLX libgl1-mesa-glx
    • /usr/lib/x86_64-linux-gnu/
    • /usr/lib/x86_64-linux-gnu/
    • /usr/share/bug/libgl1-mesa-glx/control
    • /usr/share/bug/libgl1-mesa-glx/script
    • /usr/share/doc/libgl1-mesa-glx/changelog.Debian.gz
    • /usr/share/doc/libgl1-mesa-glx/copyright
    • /usr/share/lintian/overrides/libgl1-mesa-glx

OpenGL ABI (Headers, Datatypes, Libraries)

  • ABI (Application Binary Interface) and runtime environment for applications using OpenGL under X11 on Linux enable applications using the OpenGL API for rendering to run on a variety of underlying implementations transparently. The intent is to address all of open source, commercial closed binary, OpenGL SI-based, and Mesa-based implementations.
  • SDK for developing apps using OpenGL. This includes header file locations, conventions for use of extensions, etc.

Some Linux distributions may include support for hardware acceleration. Also, some GPUs have Open Source drivers developed by the community even though a closed source driver may be available from the manufacturer.

EGL, XCB, GL* & Forget About Xlib






Source Code


 Why XCB?
 X protocol C-language Binding (XCB) is a replacement for Xlib

 Basic Graphics Programming With The XCB Library

 Introduction to managing client API rendering through the EGL API.

Invoking: GCC C++ Linker
g++  -o "EGL14XCBGLES20MakeCurrentContext"  ./src/EGL14XCBGLES20MakeCurrentContext.o   -lxcb -lEGL -lGLESv2

 See Also:
 Documentation for the X Window System

#include <stdlib.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <xcb/xcb.h>

xcb_window_t makeXcbWindow(uint16_t width, uint16_t height,
		xcb_visualid_t eglConfAttrVisualID) {

	xcb_connection_t *c;
	xcb_screen_t *screen;
	xcb_window_t win;

	/* Open the connection to the X server */
	c = xcb_connect(NULL, NULL);

	/* Get the first screen */
	screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

	/* Ask for our window's Id */
	win = xcb_generate_id(c);

	/* Create the window */

	XCB_COPY_FROM_PARENT, win, screen->root, 0, 0, width, height, 10,

	/* Map the window on the screen */
	xcb_map_window(c, win);

	/* Make sure commands are sent before we pause, so window is shown */

	return win;

int main(int argc, char ** argv) {

	//@FIXME Black screen & cursor problems sometimes...

	/* get an EGL display connection */
	EGLDisplay display;
	display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
	/* initialize the EGL display connection */
	eglInitialize(display, NULL, NULL);

	/* get an appropriate EGL frame buffer configuration */
	 All attributes in attrib_list, including boolean attributes, are immediately
	 followed by the corresponding desired value. The list is terminated with EGL_NONE
	static EGLint const attribute_list[] = {

	EGLConfig config;
	EGLint num_config;
	eglChooseConfig(display, attribute_list, &config, 1, &num_config);

	/* create an EGL rendering context */
	 #define EGL_OPENGL_ES_API		0x30A0
	 #define EGL_OPENVG_API			0x30A1
	 #define EGL_OPENGL_API			0x30A2
	 eglCreateContext — create a new EGL rendering context

	 attrib_list specifies a list of attributes for the context.
	 The list has the same structure as described for eglChooseConfig
	static const EGLint ctx_attribs[] = {

	EGLContext context;
	context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs);

	//Request eglVisualID for native window
	EGLint eglConfAttrVisualID;
	if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID,
			&eglConfAttrVisualID)) {
		//printf("Error: eglGetConfigAttrib() failed\n");

	/* create a native window */
	//native_window = createNativeWindow();
	uint16_t width = 640;
	uint16_t height = 480;
	NativeWindowType nativeWindow;
	nativeWindow = makeXcbWindow(width, height,
			(xcb_visualid_t) eglConfAttrVisualID);

	/* create an EGL window surface */
	EGLSurface surface;
	surface = eglCreateWindowSurface(display, config, nativeWindow, NULL);

	/* connect the context to the surface */
	eglMakeCurrent(display, surface, surface, context);

	/* clear the color buffer */
	while (1) {
		glViewport(0, 0, (GLsizei) width, (GLsizei) height);
		glClearColor(0., 0., 1., 0.);
		eglSwapBuffers(display, surface);