Switching between screen resolutions/color depth

I’ve got a problem with switching the color depth (24bit to 16bit and vice versa) of the graphics card while my programme is running. After the user changes the color depth the newly created window does not show the 3D scene correctly. It seems as if only the first call of wglCreateContext initialises the buffers to the current display setting.

When the programme receives WM_DISPLAYCHANGE it’s doing the following:

// Delete the old window
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
DestroyWindow(hWnd);

// …

// Create a new window
hWnd = CreateWindow(…);

// …

// Set pixel format and create context
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};

int PixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, PixelFormat, &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);

// Display scene
// …

Is there any possibility to reinitialise the buffers (e.g. unload and load the opengl32.dll) to the new resolution/color depth. The only way I found is to use a DIBsection, but the performance sucks.
Any ideas? Thanks for your help!

I have the same problem while using MS software implementation of OpenGL. Oddly enough changing bit depth on the fly the way you described works just fine with my GeForce256 under Win2000. The only thing I can suggest is that while the documentation says that SetPixelFormat can only be called once per window, it may in fact be per process. Perhaps you should just respawn your application to it’s current state.

Depth-switching (as opposed to resolution-switching) is not “guaranteed” to work. Remember that you can only set the pixel format of a given window once. There are cases where, after a depth switch, the previous pixel format is incompatible with the new color depth. We do our best to make it work, but there is only one safe way to change your color depth: destroy your context and your window, make the switch, and rebuild everything.

  • Matt