1
\$\begingroup\$

I'm working on an OpenGL project, coming from D3D. They're organised in very different ways, so it's tricky going :)

Is there any way for a Windows application to request a specific OpenGL context version, e.g. 2.1 or 3.x?

Also, I believe I need to use wglext.h from the OpenGL registry as the GL.h that ships with Windows is an earlier version, 1.1 or 1.4 - can anyone confirm?

\$\endgroup\$
1
  • \$\begingroup\$ The OpenGL Wiki's "Getting Started" page is a good place to... get started. \$\endgroup\$ Jun 11, 2012 at 15:32

2 Answers 2

3
\$\begingroup\$

At first, you must know that you can run a given version of OpenGL in two different profiles: Compatibility profile is supposed to be compatible with the previous versions, and Core profile which doesn't support previous versions but might be faster/smaller. There is also a forward compatibility mode, best for you is to check on OpenGL website for more details about them.

Assuming you're using wgl to create an OpenGL context and glew, here is a code snippet that gives you access to advanced options such as version and profile:

// Usual initialization
if(!wglMakeCurrent(Context->hDC, Context->hRC))
    return 0;                               

glewInit();

GLint attribs[] =
{
    // Here we ask for OpenGL 2.1
    WGL_CONTEXT_MAJOR_VERSION_ARB, 2,
    WGL_CONTEXT_MINOR_VERSION_ARB, 1,
    // Uncomment this for forward compatibility mode
    //WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
    // Uncomment this for Compatibility profile
    //WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
    // We are using Core profile here
    WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
    0
};

HGLRC CompHRC = wglCreateContextAttribsARB(Context->hDC, 0, attribs);
if (CompHRC && wglMakeCurrent(Context->hDC, CompHRC))
    Context->hRC = CompHRC;

Don't forget to include wglew.h to get access to wglCreateContextAttribsARB. If you're not using glew (or something equivalent), I think you should do, especially if you're working under Windows and want to avoid a lot of pain.

\$\endgroup\$
1
\$\begingroup\$

I use GL Load

then it is a simply a matter of including the version of the header you want.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .