Search code examples
c++imagewindowsdl

Change SDL background


Is there any way to change the color of an empty SDL window to be white instead of black? I don't want to change any default settings. I'm just trying to change it for this particular program that I'm writing. I don't want to use an image file, but if I have to, I will.

I don't know if this matters, but I'm using SDL_SetVideoMode()

My code is very basic:

if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    return 1;

SDL_Surface * screen = NULL;

screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);

SDL_FillRect(screen, NULL, 0xFFFFFF);
SDL_Delay(3000);

Solution

  • Acquire the surface from your Window using surf = SDL_SetVideoMode(...) and then do

    SDL_FillRect(surf, NULL, 0xFFFFFF); // 0xFFFFFF = white in RGB, NULL = full window
    SDL_Flip(surf);