ContextWin32::ContextWin32(WindowHandle parent, NLOpenGLSettings settings)
: IPlatformContext(parent, settings)
{
int pf = 0;
PIXELFORMATDESCRIPTOR pfd = {0};
OSVERSIONINFO osvi = {0};
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
// Obtain HDC for this window.
if (!(m_hdc = GetDC((HWND)parent)))
{
NLError("[ContextWin32] GetDC() failed.");
throw NLException("GetDC() failed.", true);
}
// Create and set a pixel format for the window.
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = settings.BPP;
pfd.cDepthBits = settings.BPP;
pfd.iLayerType = PFD_MAIN_PLANE;
// Obtain Windows Version
if (!GetVersionEx(&osvi))
{
NLError("[ContextWin32] GetVersionEx() failed.");
throw NLException("[ContextWin32] GetVersionEx() failed.");
}
// Get a pixelformat, based on our settings
pf = ChoosePixelFormat(m_hdc, &pfd);
// Set the pixelformat
if (!SetPixelFormat(m_hdc, pf, &pfd))
{
NLError("[ContextWin32] GetVersionEx() failed.");
throw NLException("[ContextWin32] SetPixelFormat() failed.");
}
// When running under Windows Vista or later support desktop composition.
// This doesn't really apply when running in full screen mode.
if (osvi.dwMajorVersion > 6 || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 0))
pfd.dwFlags |= PFD_SUPPORT_COMPOSITION;
// Verify that this OpenGL implementation supports the extensions we need
std::string extensions = wglGetExtensionsStringARB(m_hdc);
if (extensions.find("WGL_ARB_create_context") == std::string::npos){
NLError("[ContextWin32] Required extension WGL_ARB_create_context is not supported.");
throw NLException("[ContextWin32] Required extension WGL_ARB_create_context is not supported.");
}
int attribList[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, settings.MAJOR,
WGL_CONTEXT_MINOR_VERSION_ARB, settings.MINOR,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
0
};
// First try creating an OpenGL context.
if (!(m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribList)))
{
// Fall back to an OpenGL 3.0 context.
attribList[1] = 0;
// try again
if (!(m_hglrc = wglCreateContextAttribsARB(m_hdc, 0, attribList))){
NLError("[ContextWin32] wglCreateContextAttribsARB() failed for OpenGL 3 context.");
throw NLException("[ContextWin32] wglCreateContextAttribsARB() failed for OpenGL 3 context.", true);
}
}
if (!wglMakeCurrent(m_hdc, m_hglrc)){
NLError("[ContextWin32] wglMakeCurrent() failed for OpenGL 3 context.");
throw NLException("[ContextWin32] wglMakeCurrent() failed for OpenGL 3 context.");
}
// Load wglSwapIntervalExt
typedef BOOL (APIENTRY * PFNWGLSWAPINTERVALEXTPROC)(int);
static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
wglSwapIntervalEXT = reinterpret_cast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT"));
if ( wglSwapIntervalEXT )
{
if ( settings.VSYNC == true )
{
wglSwapIntervalEXT(1);
}
else if ( settings.VSYNC == false )
{
wglSwapIntervalEXT(0);
}
}
else if (wglSwapIntervalEXT == NULL )
{
NLWarning("[ContextWin32] Cannot load wglSwapIntervalEXT");
}
}
This is the code in Question. If fails when setting the attributes. The code works perfect on ATI, but on NVIDIA it fails.
Can anyone see why? I do not own any NVIDIA Product, so I cannot reproduce it.
This are the #defines I use:
http://paste2.org/p/1715784
Hopefully someone can help. Thanks a lot.