My engine allows the user to choose between software and hardware acclereated modes, and windowed and fullscreen modes. Both software and hardware use OpenGL, and as it is they use the same code, too. Software mode works just fine, fullscreen and windowed. Hardware mode works fine windowed, but it does all kinds of goofy things in fullscreen. I’m pretty new to OGL and can’t find any reason for what’s happening. Here’s the initialization code (simplified a bit):
//Things already initialized elsewhere
HWND window;
bool windowed;
int bpp, width, height, refresh;
int mode; //HARDWARE or SOFTWARE
//Other members
HGLRC OpenGL;
HWND deviceWindow;
DEVMODE displaymode;
PIXELFORMATDESCRIPTOR pixelFormat, current;
int i;
HDC deviceContext;
if(!windowed) //Fullscreen
{
//Set new resolution
displaymode.dmSize = sizeof(DEVMODE);
displaymode.dmBitsPerPel = bpp;
displaymode.dmPelsWidth = width;
displaymode.dmPelsHeight = height;
displaymode.dmDisplayFrequency = refresh;
displaymode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if(refresh)
displaymode.dmFields |= DM_DISPLAYFREQUENCY;
if(DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&displaymode, CDS_FULLSCREEN))
return false;
}
//NULL means the whole screen
deviceWnd = windowed ? window : NULL;
deviceContext = GetDC(deviceWnd);
if(!deviceContext)
return false;
//Set the pixel format
numPFormats = DescribePixelFormat(deviceContext, 1, 0, NULL);
//Initialize
current.nSize = sizeof(PIXELFORMATDESCRIPTOR);
current.nVersion = 1;
ZeroMemory(&pixelFormat, sizeof(PIXELFORMATDESCRIPTOR));
//Iterate through pixel formats
for(i = 1;i <= numPFormats;i++)
{
DescribePixelFormat(deviceContext, i, current.nSize, ¤t);
if((current.dwFlags & PFD_DOUBLEBUFFER) &&
(current.dwFlags & PFD_SUPPORT_OPENGL) &&
(current.dwFlags & PFD_DRAW_TO_WINDOW) &&
(current.iPixelType == PFD_TYPE_RGBA) &&
(current.cColorBits >= 16) &&
current.cDepthBits)
{
switch(mode)
{
case HARDWARE:
if(current.dwFlags & PFD_GENERIC_FORMAT)
continue;
break;
case SOFTWARE:
if(!current.dwFlags & PFD_GENERIC_FORMAT)
continue;
break;
}
if(current.cColorBits > pixelFormat.cColorBits)
{
memcpy(&pixelFormat, ¤t, sizeof(PIXELFORMATDESCRIPTOR));
selected = i;
}
else if(current.cDepthBits > pixelFormat.cDepthBits)
{
memcpy(&pixelFormat, ¤t, sizeof(PIXELFORMATDESCRIPTOR));
selected = i;
}
}
}
//This checks if a good format was found
if(pixelFormat.nSize == 0)
return false;
if(!SetPixelFormat(deviceContext, selected, &pixelFormat))
return false;
OpenGL = wglCreateContext(deviceContext);
if(!OpenGL)
return false;
if(!wglMakeCurrent(deviceContext, OpenGL))
return false;
return true;
And my cleanup code looks like this:
glFlush();
wglMakeCurrent(NULL, NULL);
wglDeleteContext(OpenGL);
ReleaseDC(deviceWindow, deviceContext);
ChangeDisplaySettings(NULL, 0);
The problem heppsn with or without any actual rendering, so it must be caused somewhere in the above code. If anyone sees a problem, please tell me! Oh, and if you need more info, just ask. Thanks a lot!
-Evan