Portal:OpenGL Concepts/Context

From OpenGL Wiki
Jump to navigation Jump to search

The OpenGL specification defines the concept of the Context. The context contains all of the information that will be used by the OpenGL system to render, when the system is given a rendering command. A context effectively is OpenGL, because OpenGL cannot be used without one.

OpenGL contexts are local to a particular application; you cannot peek at another application's contexts. However, each application can have multiple contexts. Each context is completely separate and isolated from one another, with one exception. Objects (see below) can be shared between contexts, if the contexts are setup to do so when they are initially created.

All OpenGL functions operate on the context which is "current". This is very much like a global variable that every OpenGL function operates on. OpenGL functions do not work unless a context is current.

Note: To be technical, OpenGL function pointers retrieved from one context should not be used with function pointers retrieved from another context. That being said, this will almost never cause problems, so long as the same driver is servicing both contexts.

While the OpenGL specification details the behavior of contexts, it does not cover the creation of them. This is governed by platform-specific APIs. Therefore, while OpenGL code is generally platform-neutral, it is always dependent on some platform-specific code to create and destroy OpenGL contexts.