Skip to content

Commit

Permalink
Fix GL context creation on Windows. Was creating 3.1 contexts on new …
Browse files Browse the repository at this point in the history
…nVidia drivers.
  • Loading branch information
hrydgard committed Apr 1, 2014
1 parent 51fb157 commit 4714574
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions Windows/OpenGLBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,41 @@ bool GL_Init(HWND window, std::string *error_message) {
return false;
}

// Alright, now for the modernity.
static const int attribs[] = {
CheckGLExtensions();

int contextFlags = enableGLDebug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0;

// Alright, now for the modernity. First try a 4.4, then 4.3, context, if that fails try 3.3.
// I can't seem to find a way that lets you simply request the newest version available.
const int attribs44[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 4,
WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
const int attribs43[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};
const int attribs33[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_FLAGS_ARB, enableGLDebug ? WGL_CONTEXT_DEBUG_BIT_ARB : 0,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, contextFlags,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
0
};

HGLRC m_hrc;
if(wglewIsSupported("WGL_ARB_create_context") == 1) {
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs);
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs44);
if (!m_hrc)
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs43);
if (!m_hrc)
m_hrc = wglCreateContextAttribsARB(hDC, 0, attribs33);
if (!m_hrc) {
// Fall back
m_hrc = hRC;
Expand Down Expand Up @@ -222,8 +246,6 @@ bool GL_Init(HWND window, std::string *error_message) {
MessageBox(0,ConvertUTF8ToWString((const char *)glGetString(GL_SHADING_LANGUAGE_VERSION)).c_str(),0,0);
*/

CheckGLExtensions();

glstate.Initialize();
if (wglSwapIntervalEXT)
wglSwapIntervalEXT(0);
Expand Down

1 comment on commit 4714574

@solarmystic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @hrydgard, it properly shows the OGL driver version as 3.3 instead of 3.1 like it used to on my ATI card:-

menu_00000

Previously:-

menu_00001

Please sign in to comment.