#include #include #include #include "SDL.h" //---------------------------------------------------------- // This list describes a large number of differrent pixel // formats. Feel free to add or delete from the list. typedef struct { int bitsPerPixel; int bytesPerPixel; int red; int green; int blue; int alpha; } pixelFormat; pixelFormat formats[] = { { 1, 1, 1, 1, 1, 1}, { 8, 1, 0, 0, 0, 0}, { 8, 1, 3, 3, 2, 0}, {12, 2, 4, 4, 4, 0}, {15, 2, 5, 5, 5, 0}, {16, 2, 4, 4, 4, 4}, {16, 2, 5, 5, 5, 1}, {16, 2, 5, 6, 5, 0}, {24, 3, 8, 8, 8, 0}, {24, 4, 8, 8, 8, 0}, {32, 4, 8, 8, 8, 0}, {32, 4, 8, 8, 8, 8}, }; int numFormats = sizeof(formats) / sizeof(pixelFormat); // zDepths is a list of the number of bits of Z buffer you // want. Most of the values in the list a what you expect // for real Z buffers, but 1, and 8 are there just for // testing. int zDepths[] = {0, 1, 8, 16, 24}; int numDepths = sizeof(zDepths) / sizeof(int); int mssSize[] = {0, 2, 4, 8, 16}; int numMssSize = sizeof(mssSize) / sizeof(int); //---------------------------------------------------------- // This function tries to set a specific OpenGL video mode // based on its input parameters. It always prints // information about the requested mode. If it can set the // requested mode it prints the actual values for all the // parameters that were set by the driver. void testDisplayMode(int bitsPerPixel, int red, int green, int blue, int alpha, int zBufDepth, int doubleBuffer, int fullScreen, int msBuffers, int msSamples) { SDL_Surface *screen = NULL; Uint32 videoFlags = SDL_OPENGL; // Initialize SDL if (-1 == SDL_Init(SDL_INIT_EVERYTHING)) { printf("Failed to initialize SDL error=%s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); // Set all the OpenGL attributes. SDL_GL_SetAttribute(SDL_GL_RED_SIZE, red); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, green); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, blue); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, alpha); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, bitsPerPixel); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zBufDepth); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, doubleBuffer); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msBuffers); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msSamples); // If it is a full screen mode then set the video flag // to request it. if (1 == fullScreen) { videoFlags |= SDL_FULLSCREEN; } // Set the video mode screen = SDL_SetVideoMode(640, 480, 0, videoFlags); if (NULL == screen) { printf("could not set mode -- rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n", red, green, blue, alpha, zBufDepth, doubleBuffer, fullScreen, bitsPerPixel, msBuffers, msSamples); } else { // Print information about the requested video mode. printf("\n -- set mode\n"); printf("asked for rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n", red, green, blue, alpha, zBufDepth, doubleBuffer, fullScreen, bitsPerPixel, msBuffers, msSamples); // Get the real values of the attributes. They are // rarely the same as what you asked for. SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red); SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green); SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &blue); SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha); SDL_GL_GetAttribute(SDL_GL_BUFFER_SIZE, &bitsPerPixel); SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &zBufDepth); SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doubleBuffer); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &msBuffers); SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &msSamples); printf("but got rgba= (%2d, %2d, %2d, %2d) z=%2d db= %d fs= %d bpp=%2d msb=%2d mss=%2d\n", red, green, blue, alpha, zBufDepth, doubleBuffer, fullScreen, bitsPerPixel, msBuffers, msSamples); } // Shut down SDL SDL_Quit(); } //---------------------------------------------------------- // This is test driver. It iterates through all the pixel // formats and all the Z buffer depths. It tries each // combination of pixel format, Z buffer, single/double // buffered, and windowed/full screen. That can be quite a // few different modes. Be prepared for you computer // screen to go blank for a while. void enumerateDisplayModes() { int pixelFormat = 0; int zBufFormat = 0; int fullScreen = 0; int msBuffers = 0; int msSamples = 0; int doubleBuffer = 0; for (fullScreen = 0; fullScreen <= 1; fullScreen++) { for (msBuffers = 0; msBuffers <= 1; msBuffers++) { for (doubleBuffer = 0; doubleBuffer <= 1; doubleBuffer++) { for (zBufFormat = 0; zBufFormat < numDepths; zBufFormat++) { for (pixelFormat = 0; pixelFormat < numFormats; pixelFormat++) { int bitsPerPixel = formats[pixelFormat].bitsPerPixel; int red = formats[pixelFormat].red; int green = formats[pixelFormat].green; int blue = formats[pixelFormat].blue; int alpha = formats[pixelFormat].alpha; int zBufDepth = zDepths[zBufFormat]; if (0 == msBuffers) { testDisplayMode(bitsPerPixel, red, green, blue, alpha, zBufDepth, doubleBuffer, fullScreen, 0, 0); } else { for (msSamples = 0; msSamples < numMssSize; msSamples++) { int sampleSize = mssSize[msSamples]; testDisplayMode(bitsPerPixel, red, green, blue, alpha, zBufDepth, doubleBuffer, fullScreen, msBuffers, sampleSize); } } } } } } } } //---------------------------------------------------------- int main(int argc, char **argv) { printf("======================================================\n"); enumerateDisplayModes(); printf("======================================================\n"); }