Game Development Reference
In-Depth Information
Initializing the OpenGL 3 core proile on
Windows
OpenGL 3.0 introduced the idea of features deprecation. Some features could be marked
as deprecated and could be removed from the speciication in later versions. For example,
immediate mode rendering via glBegin ()/glEnd () was marked as deprecated in OpenGL
standard Version 3.0 and removed in Version 3.1. However, many OpenGL implementations
retain the deprecated functionality. For example, they want to be able to provide a way for
users of modern OpenGL versions to access the features from old APIs.
Starting from the OpenGL Version 3.2, a new mechanism was introduced to allow the user to
create a rendering context of particular version. Each version allows backwards-compatible,
or core proile contexts. A backwards-compatible context allows the use of all features
marked as deprecated. The core proile context removes the deprecated functionality, making
the API cleaner. Furthermore, the OpenGL 3 core proile is much closer to the mobile OpenGL
ES 2 than previous OpenGL versions. Since the goal of this topic is to provide a way to develop
mobile applications on a desktop, this similarity in feature sets will come in handy. Let's ind
out how we can create a core proile context manually on Windows.
For readers with Unix or Mac desktop computers, we recommend
using the GLFW library for OpenGL context creation, available at
http://www.glfw.org .
Getting ready
More information on core and compatibility context can be found on the oficial OpenGL page
at http://www.opengl.org/wiki/Core_And_Compatibility_in_Contexts .
How to do it…
There is an OpenGL extension named WGL_ARB_create_context that can create an
OpenGL context of a speciic version on Windows, which is available at http://www.
opengl.org/registry/specs/ARB/wgl_create_context.txt .
The trick is that we can get a pointer to the wglCreateContextAttribsARB()
function, which can create a core proile context, only from an existing valid OpenGL
context. This means we have to initialize OpenGL twice. Firstly, we create a temporary
compatibility context using glCreateContext() and retrieve a pointer to the
wglCreateContextAttribsARB() extension function. Then, we go ahead and use
the extension function to create an OpenGL context of the speciied version and with
the desired lags. The following is the code we use to create an OpenGL rendering context:
 
Search WWH ::




Custom Search