diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-06-13 13:53:13 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-06-13 13:53:13 -0700 |
commit | 54e6ad2f8f20c9b72aaa12888568108ba2d20da2 (patch) | |
tree | 7b8f3271250dd04e6e78135200a50401fb787706 /tests/sdl_canvas_palette.c | |
parent | 52a5e5e9dc2d2ce9a26ba3a9393dbf8bae93787f (diff) | |
parent | aad005f54a21a91b64bc07fe7ede67bd79f4f2d2 (diff) |
Merge pull request #466 from caiiiycuk/SDL_HWPALETTE
Implementation of SDL_Surface with SDL_HWPALETTE flag (8bpp surface)
Diffstat (limited to 'tests/sdl_canvas_palette.c')
-rw-r--r-- | tests/sdl_canvas_palette.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/sdl_canvas_palette.c b/tests/sdl_canvas_palette.c new file mode 100644 index 00000000..1ba07760 --- /dev/null +++ b/tests/sdl_canvas_palette.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <emscripten.h> + +int main() { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 400, 8, SDL_HWSURFACE | SDL_HWPALETTE); + + //initialize sdl palette + //with red green and blue + //colors + SDL_Color pal[3]; + pal[0].r = 255; + pal[0].g = 0; + pal[0].b = 0; + pal[0].unused = 0; + + pal[1].r = 0; + pal[1].g = 255; + pal[1].b = 0; + pal[1].unused = 0; + + pal[2].r = 0; + pal[2].g = 0; + pal[2].b = 255; + pal[2].unused = 0; + + SDL_SetColors(screen, pal, 0, 3); + + { + SDL_Rect rect = { 0, 0, 300, 200 }; + SDL_FillRect(screen, &rect, 0); + } + + { + SDL_Rect rect = { 300, 0, 300, 200 }; + SDL_FillRect(screen, &rect, 1); + } + + { + SDL_Rect rect = { 0, 200, 600, 200 }; + SDL_FillRect(screen, &rect, 2); + } + + //changing green color + //to yellow + pal[1].r = 255; + SDL_SetColors(screen, pal, 1, 1); + + { + SDL_Rect rect = { 300, 200, 300, 200 }; + SDL_FillRect(screen, &rect, 1); + } + + printf("you should see red, blue and yellow rectangle\n"); + + SDL_Quit(); + + return 0; +} + |