wboe, if I recall correctly (haven’t used SDL_gfx in a while), it’s
possible to cast a SDL_Color into an int like this:
SDL_Color some_colour;
Uint32 same_colour;
same_colour = *(int *)SDL_Colour;
This is possible because SDL_Colour is 4 bytes, each are 8 bits, and there
are 32 bits in an integer, and 8*4=32.
However, I think this casting isn’t ideal because it doesn’t take machine
Endian-ness into account. Andreas/anyone, can you confirm this?
But at the very least, you can use:
Uint32 same_colour SDL_MapRGB http://wiki.libsdl.org/moin.cgi/SDL_MapRGB(
your_pixel_format, some_colour.r, some_colour.g, some_colour.b );
The efficiency isn’t really an issue here, because you also have to
remember that Andreas is trying to maintain some sort of consistency and
backward compatibility to the original SDL_gfx, so it wouldn’t make sense
to switch to SDL_Color.
Recoding some of your app may seem tedious, but by my estimation, it’s
worth it. There are many times that I’ve spent a week of spare time
programming stuff for a project, only to tear it out and recode it with a
library that works differently than I expected. It’s the nature of
programming, I guess (also the nature of bad planning, something I’ve been
known to have).
If you want to make an easy conversion, make a macro/define that you can
easily stitch into your code to convert your SDL_Colour to Uint32 (if
you’re using one consistent pixel format).
That’s all to say that I don’t think this is really in the scope of
SDL2_Gfx, but I’m not a dev on it - just my two cents.
-AlexOn Tue, Sep 11, 2012 at 2:52 AM, wboe <w.boeke at upcmail.nl> wrote:
**
Hi Andreas,
Wouldn’t it be a terrible good idea to reconsider the color format used by
SDL_gfx? There are now 2 formats for color: SDL_Color as used by the SDL2
graphics primitives, and Uint32’s for SDL_gfx. In practice this is very
inconvenient, and at that, it does not serve a real purpose.
When a designer switches from SDL1.2 to SDL2 he has to modify a lot of
code. So maybe now is the best time to give up about backward compatibility
issues regarding SDL_gfx. It would be very nice when SDL from now on used
one single color format.
wboe
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org