Next: , Previous: , Up: GL   [Index]


3.2 GL Contexts

All this talk about drawing is very well and good, but how do you actually get a canvas? Interestingly enough, this is outside the purview of the OpenGL specification. There are specific ways to get an OpenGL context for each different windowing system that is out there. OpenGL is all crayons and no paper.

For the X window system, there is a standard API for creating a GL context given a window (or a drawable), GLX. See GLX, for more information on its binding in Guile.

Bseides creating contexts from native windows or drawables, each backend also supports functions to make a context current. The OpenGL API is stateful; you can think of each call as taking an implicit current context parameter, which holds the current state of the GL and is operated on by the function in question. Contexts are thread-specific, and one context should not be active on more than one thread at a time.

All calls to OpenGL functions must be made while a context is active; otherwise the result is undefined. Hopefully while you are getting used to this rule, your driver is nice enough not to crash on you if you call a function outside a GL context, but it’s not even required to do that. Backend-specific functions may or may not require a context to be current; for example, Windows requires a context to be current, wheras GLX does not.

There have been a few attempts at abstracting away the need for calling API specific to a given windowing system, notably GLUT and EGL. GLUT is the older of the two, and though it is practically unchanged since the mid-1990s, it is still widely used on desktops. See GLUT, for more on GLUT.

EGL is technically part of OpenGL ES, and was designed with the modern OpenGL API and mobile hardware in mind, though it also works on the desktop. Guile does not yet have an EGL binding.


Next: , Previous: , Up: GL   [Index]