Mercurial > sdl-ios-xcode
annotate test/testpalette.c @ 4446:8b03a20b320f
Much improved multi-display support for iPad.
Fixes most issues and limitations, I think.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 02 May 2010 05:08:12 -0400 |
parents | 06f0768a904c |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * testpalette.c | |
3 * | |
4 * A simple test of runtime palette modification for animation | |
5 * (using the SDL_SetPalette() API). | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <math.h> | |
12 | |
1815
871090feb7ad
Fixed building with CodeWarrior on MacOS Classic
Sam Lantinga <slouken@libsdl.org>
parents:
1516
diff
changeset
|
13 #include "SDL.h" |
0 | 14 |
15 /* screen size */ | |
16 #define SCRW 640 | |
17 #define SCRH 480 | |
18 | |
19 #define NBOATS 5 | |
20 #define SPEED 2 | |
21 | |
22 #ifndef MIN | |
23 #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
24 #endif | |
25 #ifndef MAX | |
26 #define MAX(a, b) ((a) > (b) ? (a) : (b)) | |
27 #endif | |
28 | |
29 /* | |
30 * wave colours: Made by taking a narrow cross-section of a wave picture | |
31 * in Gimp, saving in PPM ascii format and formatting with Emacs macros. | |
32 */ | |
33 static SDL_Color wavemap[] = { | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
34 {0, 2, 103}, {0, 7, 110}, {0, 13, 117}, {0, 19, 125}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
35 {0, 25, 133}, {0, 31, 141}, {0, 37, 150}, {0, 43, 158}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
36 {0, 49, 166}, {0, 55, 174}, {0, 61, 182}, {0, 67, 190}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
37 {0, 73, 198}, {0, 79, 206}, {0, 86, 214}, {0, 96, 220}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
38 {5, 105, 224}, {12, 112, 226}, {19, 120, 227}, {26, 128, 229}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
39 {33, 135, 230}, {40, 143, 232}, {47, 150, 234}, {54, 158, 236}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
40 {61, 165, 238}, {68, 173, 239}, {75, 180, 241}, {82, 188, 242}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
41 {89, 195, 244}, {96, 203, 246}, {103, 210, 248}, {112, 218, 250}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
42 {124, 224, 250}, {135, 226, 251}, {146, 229, 251}, {156, 231, 252}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
43 {167, 233, 252}, {178, 236, 252}, {189, 238, 252}, {200, 240, 252}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
44 {211, 242, 252}, {222, 244, 252}, {233, 247, 252}, {242, 249, 252}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
45 {237, 250, 252}, {209, 251, 252}, {174, 251, 252}, {138, 252, 252}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
46 {102, 251, 252}, {63, 250, 252}, {24, 243, 252}, {7, 225, 252}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
47 {4, 203, 252}, {3, 181, 252}, {2, 158, 252}, {1, 136, 251}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
48 {0, 111, 248}, {0, 82, 234}, {0, 63, 213}, {0, 50, 192}, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
49 {0, 39, 172}, {0, 28, 152}, {0, 17, 132}, {0, 7, 114} |
0 | 50 }; |
51 | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
52 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
53 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
54 quit(int rc) |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
55 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
56 SDL_Quit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
57 exit(rc); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
58 } |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
59 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
60 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
61 sdlerr(char *when) |
0 | 62 { |
63 fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError()); | |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
64 quit(1); |
0 | 65 } |
66 | |
67 /* create a background surface */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
68 static SDL_Surface * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
69 make_bg(SDL_Surface * screen, int startcol) |
0 | 70 { |
71 int i; | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
72 SDL_Surface *bg = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
73 SDL_CreateRGBSurface(SDL_SWSURFACE, screen->w, screen->h, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
74 8, 0, 0, 0, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
75 if (!bg) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
76 sdlerr("creating background surface"); |
0 | 77 |
78 /* set the palette to the logical screen palette so that blits | |
79 won't be translated */ | |
2855 | 80 SDL_SetSurfacePalette(bg, screen->format->palette); |
0 | 81 |
82 /* Make a wavy background pattern using colours 0-63 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
83 if (SDL_LockSurface(bg) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
84 sdlerr("locking background"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
85 for (i = 0; i < SCRH; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
86 Uint8 *p = (Uint8 *) bg->pixels + i * bg->pitch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
87 int j, d; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
88 d = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
89 for (j = 0; j < SCRW; j++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
90 int v = MAX(d, -2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
91 v = MIN(v, 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
92 if (i > 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
93 v += p[-bg->pitch] + 65 - startcol; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
94 p[j] = startcol + (v & 63); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
95 d += ((rand() >> 3) % 3) - 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
96 } |
0 | 97 } |
98 SDL_UnlockSurface(bg); | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
99 return (bg); |
0 | 100 } |
101 | |
102 /* | |
103 * Return a surface flipped horisontally. Only works for 8bpp; | |
104 * extension to arbitrary bitness is left as an exercise for the reader. | |
105 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
106 static SDL_Surface * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
107 hflip(SDL_Surface * s) |
0 | 108 { |
109 int i; | |
110 SDL_Surface *z = SDL_CreateRGBSurface(SDL_SWSURFACE, s->w, s->h, 8, | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
111 0, 0, 0, 0); |
0 | 112 /* copy palette */ |
113 SDL_SetColors(z, s->format->palette->colors, | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
114 0, s->format->palette->ncolors); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
115 if (SDL_LockSurface(s) < 0 || SDL_LockSurface(z) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
116 sdlerr("locking flip images"); |
0 | 117 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
118 for (i = 0; i < s->h; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
119 int j; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
120 Uint8 *from = (Uint8 *) s->pixels + i * s->pitch; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
121 Uint8 *to = (Uint8 *) z->pixels + i * z->pitch + s->w - 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
122 for (j = 0; j < s->w; j++) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
123 to[-j] = from[j]; |
0 | 124 } |
125 | |
126 SDL_UnlockSurface(z); | |
127 SDL_UnlockSurface(s); | |
128 return z; | |
129 } | |
130 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
131 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
132 main(int argc, char **argv) |
0 | 133 { |
134 SDL_Color cmap[256]; | |
135 SDL_Surface *screen; | |
136 SDL_Surface *bg; | |
137 SDL_Surface *boat[2]; | |
138 unsigned vidflags = 0; | |
139 unsigned start; | |
140 int fade_max = 400; | |
141 int fade_level, fade_dir; | |
142 int boatcols, frames, i, red; | |
143 int boatx[NBOATS], boaty[NBOATS], boatdir[NBOATS]; | |
144 int gamma_fade = 0; | |
145 int gamma_ramp = 0; | |
146 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
147 if (SDL_Init(SDL_INIT_VIDEO) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
148 sdlerr("initialising SDL"); |
0 | 149 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
150 while (--argc) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
151 ++argv; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
152 if (strcmp(*argv, "-hw") == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
153 vidflags |= SDL_HWSURFACE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
154 else if (strcmp(*argv, "-fullscreen") == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
155 vidflags |= SDL_FULLSCREEN; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
156 else if (strcmp(*argv, "-nofade") == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
157 fade_max = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
158 else if (strcmp(*argv, "-gamma") == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
159 gamma_fade = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
160 else if (strcmp(*argv, "-gammaramp") == 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
161 gamma_ramp = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
162 else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
163 fprintf(stderr, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
164 "usage: testpalette " |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
165 " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
166 quit(1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
167 } |
0 | 168 } |
169 | |
170 /* Ask explicitly for 8bpp and a hardware palette */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
171 if ((screen = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
172 SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE)) == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
173 fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
174 SCRW, SCRH, SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
175 quit(1); |
0 | 176 } |
177 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
178 if (vidflags & SDL_FULLSCREEN) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
179 SDL_ShowCursor(SDL_FALSE); |
1429
aff0170f9f1b
Date: Sat, 25 Feb 2006 14:26:19 +0100 (CET)
Sam Lantinga <slouken@libsdl.org>
parents:
1151
diff
changeset
|
180 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
181 if ((boat[0] = SDL_LoadBMP("sail.bmp")) == NULL) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
182 sdlerr("loading sail.bmp"); |
0 | 183 /* We've chosen magenta (#ff00ff) as colour key for the boat */ |
184 SDL_SetColorKey(boat[0], SDL_SRCCOLORKEY | SDL_RLEACCEL, | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
185 SDL_MapRGB(boat[0]->format, 0xff, 0x00, 0xff)); |
0 | 186 boatcols = boat[0]->format->palette->ncolors; |
2851
6c3fbeb04eca
Fixed crash in testpalette and potential crash in SDL_LoadBMP_RW()
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
187 if (boatcols >= 256) |
6c3fbeb04eca
Fixed crash in testpalette and potential crash in SDL_LoadBMP_RW()
Sam Lantinga <slouken@libsdl.org>
parents:
2735
diff
changeset
|
188 sdlerr("too many colors in sail.bmp"); |
0 | 189 boat[1] = hflip(boat[0]); |
190 SDL_SetColorKey(boat[1], SDL_SRCCOLORKEY | SDL_RLEACCEL, | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
191 SDL_MapRGB(boat[1]->format, 0xff, 0x00, 0xff)); |
0 | 192 |
193 /* | |
194 * First set the physical screen palette to black, so the user won't | |
195 * see our initial drawing on the screen. | |
196 */ | |
197 memset(cmap, 0, sizeof(cmap)); | |
198 SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, 256); | |
199 | |
200 /* | |
201 * Proper palette management is important when playing games with the | |
202 * colormap. We have divided the palette as follows: | |
203 * | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
204 * index 0..(boatcols-1): used for the boat |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
205 * index boatcols..(boatcols+63): used for the waves |
0 | 206 */ |
207 SDL_SetPalette(screen, SDL_LOGPAL, | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
208 boat[0]->format->palette->colors, 0, boatcols); |
0 | 209 SDL_SetPalette(screen, SDL_LOGPAL, wavemap, boatcols, 64); |
210 | |
211 /* | |
212 * Now the logical screen palette is set, and will remain unchanged. | |
213 * The boats already have the same palette so fast blits can be used. | |
214 */ | |
215 memcpy(cmap, screen->format->palette->colors, 256 * sizeof(SDL_Color)); | |
216 | |
217 /* save the index of the red colour for later */ | |
218 red = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); | |
219 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
220 bg = make_bg(screen, boatcols); /* make a nice wavy background surface */ |
0 | 221 |
222 /* initial screen contents */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
223 if (SDL_BlitSurface(bg, NULL, screen, NULL) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
224 sdlerr("blitting background to screen"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
225 SDL_Flip(screen); /* actually put the background on screen */ |
0 | 226 |
227 /* determine initial boat placements */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
228 for (i = 0; i < NBOATS; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
229 boatx[i] = (rand() % (SCRW + boat[0]->w)) - boat[0]->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
230 boaty[i] = i * (SCRH - boat[0]->h) / (NBOATS - 1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
231 boatdir[i] = ((rand() >> 5) & 1) * 2 - 1; |
0 | 232 } |
233 | |
234 start = SDL_GetTicks(); | |
235 frames = 0; | |
236 fade_dir = 1; | |
237 fade_level = 0; | |
238 do { | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
239 SDL_Event e; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
240 SDL_Rect updates[NBOATS]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
241 SDL_Rect r; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
242 int redphase; |
0 | 243 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
244 /* A small event loop: just exit on any key or mouse button event */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
245 while (SDL_PollEvent(&e)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
246 if (e.type == SDL_KEYDOWN || e.type == SDL_QUIT |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
247 || e.type == SDL_MOUSEBUTTONDOWN) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
248 if (fade_dir < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
249 fade_level = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
250 fade_dir = -1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
251 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
252 } |
0 | 253 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
254 /* move boats */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
255 for (i = 0; i < NBOATS; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
256 int old_x = boatx[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
257 /* update boat position */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
258 boatx[i] += boatdir[i] * SPEED; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
259 if (boatx[i] <= -boat[0]->w || boatx[i] >= SCRW) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
260 boatdir[i] = -boatdir[i]; |
0 | 261 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
262 /* paint over the old boat position */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
263 r.x = old_x; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
264 r.y = boaty[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
265 r.w = boat[0]->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
266 r.h = boat[0]->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
267 if (SDL_BlitSurface(bg, &r, screen, &r) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
268 sdlerr("blitting background"); |
0 | 269 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
270 /* construct update rectangle (bounding box of old and new pos) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
271 updates[i].x = MIN(old_x, boatx[i]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
272 updates[i].y = boaty[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
273 updates[i].w = boat[0]->w + SPEED; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
274 updates[i].h = boat[0]->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
275 /* clip update rectangle to screen */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
276 if (updates[i].x < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
277 updates[i].w += updates[i].x; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
278 updates[i].x = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
279 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
280 if (updates[i].x + updates[i].w > SCRW) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
281 updates[i].w = SCRW - updates[i].x; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
282 } |
0 | 283 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
284 for (i = 0; i < NBOATS; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
285 /* paint boat on new position */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
286 r.x = boatx[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
287 r.y = boaty[i]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
288 if (SDL_BlitSurface(boat[(boatdir[i] + 1) / 2], NULL, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
289 screen, &r) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
290 sdlerr("blitting boat"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
291 } |
0 | 292 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
293 /* cycle wave palette */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
294 for (i = 0; i < 64; i++) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
295 cmap[boatcols + ((i + frames) & 63)] = wavemap[i]; |
0 | 296 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
297 if (fade_dir) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
298 /* Fade the entire palette in/out */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
299 fade_level += fade_dir; |
0 | 300 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
301 if (gamma_fade) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
302 /* Fade linearly in gamma level (lousy) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
303 float level = (float) fade_level / fade_max; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
304 if (SDL_SetGamma(level, level, level) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
305 sdlerr("setting gamma"); |
0 | 306 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
307 } else if (gamma_ramp) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
308 /* Fade using gamma ramp (better) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
309 Uint16 ramp[256]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
310 for (i = 0; i < 256; i++) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
311 ramp[i] = (i * fade_level / fade_max) << 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
312 if (SDL_SetGammaRamp(ramp, ramp, ramp) < 0) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
313 sdlerr("setting gamma ramp"); |
0 | 314 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
315 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
316 /* Fade using direct palette manipulation (best) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
317 memcpy(cmap, screen->format->palette->colors, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
318 boatcols * sizeof(SDL_Color)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
319 for (i = 0; i < boatcols + 64; i++) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
320 cmap[i].r = cmap[i].r * fade_level / fade_max; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
321 cmap[i].g = cmap[i].g * fade_level / fade_max; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
322 cmap[i].b = cmap[i].b * fade_level / fade_max; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
323 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
324 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
325 if (fade_level == fade_max) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
326 fade_dir = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
327 } |
0 | 328 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
329 /* pulse the red colour (done after the fade, for a night effect) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
330 redphase = frames % 64; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
331 cmap[red].r = (int) (255 * sin(redphase * M_PI / 63)); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
332 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
333 SDL_SetPalette(screen, SDL_PHYSPAL, cmap, 0, boatcols + 64); |
0 | 334 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
335 /* update changed areas of the screen */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
336 SDL_UpdateRects(screen, NBOATS, updates); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
337 frames++; |
2735
204be4fc2726
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
338 } while (fade_level > 0); |
0 | 339 |
340 printf("%d frames, %.2f fps\n", | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
341 frames, 1000.0 * frames / (SDL_GetTicks() - start)); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
342 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
343 if (vidflags & SDL_FULLSCREEN) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1815
diff
changeset
|
344 SDL_ShowCursor(SDL_TRUE); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
0
diff
changeset
|
345 SDL_Quit(); |
0 | 346 return 0; |
347 } |