[SDL] SDL_color assignment

James Barrett xucaen at gmail.com
Sat Dec 15 16:31:46 PST 2007


Hi, I've been searching google for a way to assign an SDL_Color struct
from a single numeric value. I might be misremembering, but I thought
there was a way to do this. I thought I remembered seeing somewhere an
example using preprocessor defines to store colors (probably as hex
values) and then using those values to asign to an SDL_Color.

Obviously, when I try it like this, I get a compile error:

#define WHITE {255,255,255}
#define BLUE  {0,0,255}

    SDL_Color c = WHITE;//OK
    c = BLUE;//Compile error


The only other way I can think of is to store SDL_Color objects for each
color I want to use.

static const SDL_Color WHITE = {255,255,255};
static const SDL_Color BLUE = {0,0,255};

    SDL_Color c = WHITE;//OK
    c = BLUE;//Now this is OK


jim



More information about the SDL mailing list