How can i find out the color depth of the desktop?

The code below attempts to create a full screen openGL window at a resolution of 1024*768 with a 32 bit color depth:

CreateGLWindow(“Taking Fire”,1024,768,32,fullscreen))

However I want to replace those constants with variables defined by the current desktop resolution. I can use:

int xres = GetSystemMetrics(SM_CXFULLSCREEN);
int yres = GetSystemMetrics(SM_CYFULLSCREEN);

to find out the desktop resolution but I’d like to know how to determine the desktop color depth or alternatively get OpenGL to automatically use the highest color depth the card supports.

Use EnumDisplaySettings, and have it tell you the current settings only.

Or pass the DC of the desktop to GetDeviceCaps to get the BITSPIXEL value.

Thanks for the reply. I had tried Getdevice caps but used GetDC instead of GetDC(NULL) and it kept returning 0. The code below now does the job.

char bpp[10] = {0};// 0-9 !!
int x = GetDeviceCaps(GetDC(NULL),BITSPIXEL);
_itoa( x, bpp, 10 );
alert[9]=0;//ensure null termination
MessageBox (NULL, TEXT (alert), TEXT (“Color Depth”), 0) ;

GLFW :

GLFWvidmode mode;
glfwGetDektopMode( &mode );
printf( "%d x %d x %d:%d:%d
", mode.Width, mode.Height, mode.RedBits, mode.GreenBits, mode.BlueBits );

…which of course also works under Linux, SGI/IRIX, Solaris, etc, and soon Mac OS X too