Depth change when switching to fullscreen mode

Hello all,

I have a question about an issue I’m having with an SDL/OpenGL application I’m developing. In short, switching from windowed mode to fullscreen mode (using largely the same code) appears to cause a color depth reduction, so if I render a gradient color range, I get blocky separations rather than a smooth gradient. This is best illustrated by the following two screenshots:

Proper gradient
[Image: ]

Blocky separations
[Image: ]

You can see that the color changes are not smooth in the second image as they are in the first. The only change I make as far as the SDL code between the two is to specify that the window should be fullscreen when I call SDL_SetVideoMode(). It should be noted that the rendering is consistent no matter how many times I switch between fullscreen and windowed mode (using a hotkey in my program).

I am trying to determine whether this is an issue on the OpenGL side (with my shaders, perhaps), or some other issue. I am rather new to SDL so I was wondering if I missed something when initializing the window. The relevant code is as follows:


  • Screen.cpp
  • dominicus

#include “Screen.h”

Screen::Screen(bool fullScreen) : fullScreen(fullScreen) {
// initialize our viewing screen
width = (fullScreen ? systemInfo.screenWidth : gamePrefs.getInt(“windowWidth”));
height = (fullScreen ? systemInfo.screenHeight : gamePrefs.getInt(“windowHeight”));
aspectRatio = (float) width / (float) height;

uint32_t flags = SDL_OPENGL | SDL_DOUBLEBUF | SDL_HWSURFACE | (fullScreen ? SDL_FULLSCREEN : 0);

if(! SDL_VideoModeOK(
	ProgramLog::report(LOG_FATAL, "SDL cannot initialize a window with the specified settings.");

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, gamePrefs.getInt("windowColorDepth"));

SDL_Surface* surface = SDL_SetVideoMode(

if(surface == NULL)
	ProgramLog::report(LOG_FATAL, "SDL could not initialize an OpenGL-ready window.");

if(! fullScreen)
	SDL_WM_SetCaption("dominicus", NULL);


Any help or pointers would be appreciated. I develop on Mac OS X 10.6.4 (Snow Leopard) using Xcode 3.2.2, and I use the SDL 1.2.14 framework. I have an Nvidia 9400M which supports OpenGL 2.1 on my system.


Well, looks like I figured it out. I can make the fullscreen window appear the same as the bordered window by requesting a color depth of 24 when initializing the window (the depth I was requesting was 16). It looks like it is different because SDL initializes a bordered window to the same color depth as the present display setting, ignoring the requested color (if my understanding is correct). I suppose this makes sense, as it doesn’t make sense for different windows within an OS to have different color depths.

Anyway, thanks all!