View Full Version : what is a 'context'

07-01-2003, 12:28 PM
please, an explanation of what people mean when i see code that says things like,

/* Function that is called immediately after a new context is created.
* Use this function to create context specific data structures.
* i.e. Display lists, Texture objects, etc.
* @pre The ogl context has been set to the new context.
* @post Application has completed in initialization the user wishes.
virtual void contextInit();

i don't understand what 'context' could encompass. please set me straight. feel free to write as much info as necessary to explain, :-)


07-01-2003, 01:15 PM
The term 'context' is frequently used in environments where you have a client and server model (hint: OpenGL is one of these).

Because multiple 'clients' can use the 'server' concurrently, the server must somehow identify which client it serves at any given time. That's done because for each client there is a seperate set of state governing the operation of the server for this particular client.

Consider two OpenGL applications running simultaneously (in seperate windows on a desktop). One uses textures, the other doesn't. When application #1 calls glEnable(GL_TEXTURE_2D), this state change applies only to its own private connection to OpenGL. Application #2 must not be affected by this.

You can think of an OpenGL context as an object encapsulating all state for a client. Every GL call you make implicitly references the currently selected context. Or in C++ notation


This is avoided however, mostly for efficiency reasons (note that DirectX Graphics does use this form of interface). Instead OpenGL uses something I like to call 'object selection' (no idea whether that's a proper technical term). That's where wglMakeCurrent(hdc,rendering_context) comes into play.

You actually don't have to do much for this to work. A proper OS maintains the current GL context along with thread state, ie if your thread is interrupted by a different thread also using GL, the OS will automatically select the different GL context when it stops your thread, and also automatically switch it back before it resumes your thread.

Hope this helps http://www.opengl.org/discussion_boards/ubb/smile.gif