SDL Color shortcut
I'm using SDL for a project of mine, and I want a shorter way of gett开发者_Go百科ing colors.
I want to do something like this:
SDL_FillRect(screen, &screen->clip_rect, 0x0F380F);
Instead of this:
SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0x0F, 0x38, 0x0F));
When I was working in DarkGDK, you could do something like what I wanted, and it was great and simple, but when I try to do it in SDL, I get off colors.
How about defining this in one of your header files:
#define My_FillRect(screen, num) \
do { \
SDL_FillRect(screen, &screen->clip_rect, \
SDL_MapRGB(screen->format, \
num >> 16, \
(num >> 8) & 0xff, num & 0xff); \
} while (0)
Then you can use My_FillRect(screen, 0x0F380F);
and the compiler should be able to fold the constants that so that there won't be a performance loss.
精彩评论