aboutsummaryrefslogtreecommitdiff
path: root/tests/sdl_canvas_palette.c
diff options
context:
space:
mode:
authorAleksander Guryanov <caiiiycuk@gmail.com>2012-06-09 00:07:12 +0700
committerAleksander Guryanov <caiiiycuk@gmail.com>2012-06-13 20:55:11 +0700
commitaad005f54a21a91b64bc07fe7ede67bd79f4f2d2 (patch)
tree62851317e180d7971678a2cfd61a54e263d66bc0 /tests/sdl_canvas_palette.c
parentc406b3bc87fa69ae6a1fc7a1c6c8b7118f4ffec4 (diff)
Implementation of SDL_HWPALETTE
Little bit refactoring for copyIndexedColorData now it can accept dirty rect
Diffstat (limited to 'tests/sdl_canvas_palette.c')
-rw-r--r--tests/sdl_canvas_palette.c61
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;
+}
+