I have an application that uses three separate OpenGL contexts embedded in Windows forms. The first two are of identical size and initialize and run normally. The third is smaller and I cannot create a context on Windows XP SP3, but works fine in Windows 7.
The hardware for both Win7 and WinXP is a Parallels 7 Virtual machine with a MacOS host. I have allocated 256 MB of Video memory and 2GB of RAM.
Here’s the GL context creation method I use for all contexts:
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
32, // 32-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
GLuint pixelFormat = ::ChoosePixelFormat(mDc, &pfd);
if (!pixelFormat)
{
CxDebugLastError();
CxThrow(CxErrorOpenGL);
}
bool validPixelFormat = ::SetPixelFormat(mDc, pixelFormat, &pfd);
if (!validPixelFormat)
{
CxDebugLastError();
CxThrow(CxErrorOpenGL);
}
mContext = ::wglCreateContext(mDc);
if (!mContext)
{
CxDebugLastError();
CxThrow(CxErrorOpenGL);
}
mDc is fetched from an HWND passed into the method, and is valid.
mContext is a HGLRC stored in the class. It has the address of 0x00010002 after the call to wglCreateContext for the aforementioned WinXP issue, thus the “if (!mContext)” fails and doesn’t report an error. I had to move “CxDebugLastError()” outside the if-check to see that I was getting ERROR_INSUFFICIENT_BUFFER.
-
Why is this failing on Windows XP SP3, but working fine on Windows 7?
-
Why does wglCreateContext not return NULL when it fails in this case as the documentation states it should?
p.s. - This did not occur until we started using Visual Studio 2010 and Windows forms. Previously we created the windows programmatically using a MacOS NIB file for the form design. Could there be a Windows form setting that might be causing/might fix this issue?