File: test_sdl_canvas_palette.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 121,872 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,365; asm: 2,415; lisp: 1,869
file content (65 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * Copyright 2012 The Emscripten Authors.  All rights reserved.
 * Emscripten is available under two separate licenses, the MIT license and the
 * University of Illinois/NCSA Open Source License.  Both these licenses can be
 * found in the LICENSE file.
 */

#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_FillRect(screen, NULL, 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, 1);

  {
    SDL_Rect rect = { 300, 200, 300, 200 };
    SDL_FillRect(screen, &rect, 1);
  }

  printf("you should see red, blue and yellow rectangles\n");

  SDL_Quit();

  return 0;
}