View Full Version : OpenGl context
03-31-2012, 03:36 AM
I was reading a tutorial programming in opengl version 4.1, the tutorial talks about creating opengl contexts.My question is it mandatory for using functions provided by opengl version 4.1 and above .
Currently I am using this code to set up my window and its properties.
int main(int argc,char** argv)
Will the openGl context do the above function of creating a window,setting the size,etc
I dont get the purpose of creating an opengl context ,can someone explain it to me?
03-31-2012, 05:42 AM
An OpenGL context is the data structure that collects all states needed by server to render an image. It contains references to buffers, textures, shaders, etc. OpenGL API doesn’t define how rendering context is defined, it is up to the native window system; but none of OpenGL commands can be executed until rendering context is created and made current.
A rendering context should be compatible with a window it will render to. There can be several contexts per application, or even per window. On the other hand, the same context can be used for rendering in multiple windows, but in that case all windows using the same context must have the same pixel format. Now we have come to another important aspect of rendering context: its rendering surface must be adequate for appropriate window. In order to achieve that we have to choose and set appropriate pixel format of the window that have to be created. The rendering surface is the surface to which primitives are drawn. It defines types of buffers that are required for rendering such as a color buffer, depth buffer, and stencil buffer.
Choosing pixel format must be performed in order to verify support for defined pixel format. The system would return ID of appropriate pixel format, or the closest match. Setting pixel format that is not previously returned from the system would almost certainly fail. It is not recommended to set pixel format for the window more than once.
In order to issue any OpenGL command we have to make OpenGL context active (i.e. “current”). By making active we assume binding OpenGL context to a window’s DC. It is done from a certain thread. Only one context can be made current for a single thread at a moment. Calling OpenGL commands from another thread (different from that made the context current) fails. If we want to make use of multithreading update of OpenGL resources, we have to make a share-group. All contexts from the share-group share resources like textures, buffers, etc. Although multithreading update can be useful in some cases, we have to be aware that most OpenGL drivers serialize access to the GPU. OpenGL guarantees that all commands in the single context will be executed in the order in which they are issued, but there is no guarantee for multiple contexts. Since OpenGL 3.2 synchronization is enabled through sync objects.
Prior to OpenGL 3.0, there was just one type of OpenGL rendering contexts; the context that contains full functionality. OpenGL3.0 introduced forward compatibility, and 3.2 introduced concept of profiles. There are a lot of other aspects of OpenGL rendering context, but I should rather stop here. :)
03-31-2012, 07:31 AM
In addition to the above, check the FAQ
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.