Mercurial > sdl-ios-xcode
comparison test/testwin.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | 14717b52abc0 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
10 #define NOTICE(X) printf("%s", X); | 10 #define NOTICE(X) printf("%s", X); |
11 | 11 |
12 #include "SDL.h" | 12 #include "SDL.h" |
13 | 13 |
14 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 14 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
15 static void quit(int rc) | 15 static void |
16 quit (int rc) | |
16 { | 17 { |
17 SDL_Quit(); | 18 SDL_Quit (); |
18 exit(rc); | 19 exit (rc); |
19 } | 20 } |
20 | 21 |
21 void DrawPict(SDL_Surface *screen, char *bmpfile, | 22 void |
22 int speedy, int flip, int nofade) | 23 DrawPict (SDL_Surface * screen, char *bmpfile, |
24 int speedy, int flip, int nofade) | |
23 { | 25 { |
24 SDL_Surface *picture; | 26 SDL_Surface *picture; |
25 SDL_Rect dest, update; | 27 SDL_Rect dest, update; |
26 int i, centered; | 28 int i, centered; |
27 int ncolors; | 29 int ncolors; |
28 SDL_Color *colors, *cmap; | 30 SDL_Color *colors, *cmap; |
29 | 31 |
30 /* Load the image into a surface */ | 32 /* Load the image into a surface */ |
31 if ( bmpfile == NULL ) { | 33 if (bmpfile == NULL) { |
32 bmpfile = "sample.bmp"; /* Sample image */ | 34 bmpfile = "sample.bmp"; /* Sample image */ |
33 } | 35 } |
34 fprintf(stderr, "Loading picture: %s\n", bmpfile); | 36 fprintf (stderr, "Loading picture: %s\n", bmpfile); |
35 picture = SDL_LoadBMP(bmpfile); | 37 picture = SDL_LoadBMP (bmpfile); |
36 if ( picture == NULL ) { | 38 if (picture == NULL) { |
37 fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, | 39 fprintf (stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError ()); |
38 SDL_GetError()); | 40 return; |
39 return; | 41 } |
40 } | 42 |
41 | 43 /* Set the display colors -- on a hicolor display this is a no-op */ |
42 /* Set the display colors -- on a hicolor display this is a no-op */ | 44 if (picture->format->palette) { |
43 if ( picture->format->palette ) { | 45 ncolors = picture->format->palette->ncolors; |
44 ncolors = picture->format->palette->ncolors; | 46 colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color)); |
45 colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color)); | 47 cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color)); |
46 cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color)); | 48 memcpy (colors, picture->format->palette->colors, |
47 memcpy(colors, picture->format->palette->colors, | 49 ncolors * sizeof (SDL_Color)); |
48 ncolors*sizeof(SDL_Color)); | 50 } else { |
49 } else { | 51 int r, g, b; |
50 int r, g, b; | 52 |
51 | 53 /* Allocate 256 color palette */ |
52 /* Allocate 256 color palette */ | 54 ncolors = 256; |
53 ncolors = 256; | 55 colors = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color)); |
54 colors = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color)); | 56 cmap = (SDL_Color *) malloc (ncolors * sizeof (SDL_Color)); |
55 cmap = (SDL_Color *)malloc(ncolors*sizeof(SDL_Color)); | 57 |
56 | 58 /* Set a 3,3,2 color cube */ |
57 /* Set a 3,3,2 color cube */ | 59 for (r = 0; r < 8; ++r) { |
58 for ( r=0; r<8; ++r ) { | 60 for (g = 0; g < 8; ++g) { |
59 for ( g=0; g<8; ++g ) { | 61 for (b = 0; b < 4; ++b) { |
60 for ( b=0; b<4; ++b ) { | 62 i = ((r << 5) | (g << 2) | b); |
61 i = ((r<<5)|(g<<2)|b); | 63 colors[i].r = r << 5; |
62 colors[i].r = r<<5; | 64 colors[i].g = g << 5; |
63 colors[i].g = g<<5; | 65 colors[i].b = b << 6; |
64 colors[i].b = b<<6; | 66 } |
65 } | 67 } |
66 } | 68 } |
67 } | 69 } |
68 } | 70 NOTICE ("testwin: setting colors\n"); |
69 NOTICE("testwin: setting colors\n"); | 71 if (!SDL_SetColors (screen, colors, 0, ncolors) && |
70 if ( ! SDL_SetColors(screen, colors, 0, ncolors) && | 72 (screen->format->palette != NULL)) { |
71 (screen->format->palette != NULL) ) { | 73 fprintf (stderr, |
72 fprintf(stderr, | 74 "Warning: Couldn't set all of the colors, but SDL will map the image\n" |
73 "Warning: Couldn't set all of the colors, but SDL will map the image\n" | 75 " (colormap fading will suffer - try the -warp option)\n"); |
74 " (colormap fading will suffer - try the -warp option)\n" | 76 } |
75 ); | 77 |
76 } | 78 /* Set the screen to black (not really necessary) */ |
77 | 79 if (SDL_LockSurface (screen) == 0) { |
78 /* Set the screen to black (not really necessary) */ | 80 Uint32 black; |
79 if ( SDL_LockSurface(screen) == 0 ) { | 81 Uint8 *pixels; |
80 Uint32 black; | 82 |
81 Uint8 *pixels; | 83 black = SDL_MapRGB (screen->format, 0, 0, 0); |
82 | 84 pixels = (Uint8 *) screen->pixels; |
83 black = SDL_MapRGB(screen->format, 0, 0, 0); | 85 for (i = 0; i < screen->h; ++i) { |
84 pixels = (Uint8 *)screen->pixels; | 86 memset (pixels, black, screen->w * screen->format->BytesPerPixel); |
85 for ( i=0; i<screen->h; ++i ) { | 87 pixels += screen->pitch; |
86 memset(pixels, black, | 88 } |
87 screen->w*screen->format->BytesPerPixel); | 89 SDL_UnlockSurface (screen); |
88 pixels += screen->pitch; | 90 SDL_UpdateRect (screen, 0, 0, 0, 0); |
89 } | 91 } |
90 SDL_UnlockSurface(screen); | 92 |
91 SDL_UpdateRect(screen, 0, 0, 0, 0); | 93 /* Display the picture */ |
92 } | 94 if (speedy) { |
93 | 95 SDL_Surface *displayfmt; |
94 /* Display the picture */ | 96 |
95 if ( speedy ) { | 97 fprintf (stderr, "Converting picture\n"); |
96 SDL_Surface *displayfmt; | 98 displayfmt = SDL_DisplayFormat (picture); |
97 | 99 if (displayfmt == NULL) { |
98 fprintf(stderr, "Converting picture\n"); | 100 fprintf (stderr, "Couldn't convert image: %s\n", SDL_GetError ()); |
99 displayfmt = SDL_DisplayFormat(picture); | 101 goto done; |
100 if ( displayfmt == NULL ) { | 102 } |
101 fprintf(stderr, | 103 SDL_FreeSurface (picture); |
102 "Couldn't convert image: %s\n", SDL_GetError()); | 104 picture = displayfmt; |
103 goto done; | 105 } |
104 } | 106 printf ("(image surface located in %s memory)\n", |
105 SDL_FreeSurface(picture); | 107 (picture->flags & SDL_HWSURFACE) ? "video" : "system"); |
106 picture = displayfmt; | 108 centered = (screen->w - picture->w) / 2; |
107 } | 109 if (centered < 0) { |
108 printf("(image surface located in %s memory)\n", | 110 centered = 0; |
109 (picture->flags&SDL_HWSURFACE) ? "video" : "system"); | 111 } |
110 centered = (screen->w - picture->w)/2; | 112 dest.y = (screen->h - picture->h) / 2; |
111 if ( centered < 0 ) { | 113 dest.w = picture->w; |
112 centered = 0; | 114 dest.h = picture->h; |
113 } | 115 NOTICE ("testwin: moving image\n"); |
114 dest.y = (screen->h - picture->h)/2; | 116 for (i = 0; i <= centered; ++i) { |
115 dest.w = picture->w; | 117 dest.x = i; |
116 dest.h = picture->h; | 118 update = dest; |
117 NOTICE("testwin: moving image\n"); | 119 if (SDL_BlitSurface (picture, NULL, screen, &update) < 0) { |
118 for ( i=0; i<=centered; ++i ) { | 120 fprintf (stderr, "Blit failed: %s\n", SDL_GetError ()); |
119 dest.x = i; | 121 break; |
120 update = dest; | 122 } |
121 if ( SDL_BlitSurface(picture, NULL, screen, &update) < 0 ) { | 123 if (flip) { |
122 fprintf(stderr, "Blit failed: %s\n", SDL_GetError()); | 124 SDL_Flip (screen); |
123 break; | 125 } else { |
124 } | 126 SDL_UpdateRects (screen, 1, &update); |
125 if ( flip ) { | 127 } |
126 SDL_Flip(screen); | 128 } |
127 } else { | |
128 SDL_UpdateRects(screen, 1, &update); | |
129 } | |
130 } | |
131 | 129 |
132 #ifdef SCREENSHOT | 130 #ifdef SCREENSHOT |
133 if ( SDL_SaveBMP(screen, "screen.bmp") < 0 ) | 131 if (SDL_SaveBMP (screen, "screen.bmp") < 0) |
134 printf("Couldn't save screen: %s\n", SDL_GetError()); | 132 printf ("Couldn't save screen: %s\n", SDL_GetError ()); |
135 #endif | 133 #endif |
136 | 134 |
137 #ifndef BENCHMARK_SDL | 135 #ifndef BENCHMARK_SDL |
138 /* Let it sit there for a while */ | 136 /* Let it sit there for a while */ |
139 SDL_Delay(5*1000); | 137 SDL_Delay (5 * 1000); |
140 #endif | 138 #endif |
141 /* Fade the colormap */ | 139 /* Fade the colormap */ |
142 if ( ! nofade ) { | 140 if (!nofade) { |
143 int maxstep; | 141 int maxstep; |
144 SDL_Color final; | 142 SDL_Color final; |
145 SDL_Color palcolors[256]; | 143 SDL_Color palcolors[256]; |
146 struct { | 144 struct |
147 Sint16 r, g, b; | 145 { |
148 } cdist[256]; | 146 Sint16 r, g, b; |
149 | 147 } cdist[256]; |
150 NOTICE("testwin: fading out...\n"); | 148 |
151 memcpy(cmap, colors, ncolors*sizeof(SDL_Color)); | 149 NOTICE ("testwin: fading out...\n"); |
152 maxstep = 32-1; | 150 memcpy (cmap, colors, ncolors * sizeof (SDL_Color)); |
153 final.r = 0xFF; | 151 maxstep = 32 - 1; |
154 final.g = 0x00; | 152 final.r = 0xFF; |
155 final.b = 0x00; | 153 final.g = 0x00; |
156 memcpy(palcolors, colors, ncolors*sizeof(SDL_Color)); | 154 final.b = 0x00; |
157 for ( i=0; i<ncolors; ++i ) { | 155 memcpy (palcolors, colors, ncolors * sizeof (SDL_Color)); |
158 cdist[i].r = final.r-palcolors[i].r; | 156 for (i = 0; i < ncolors; ++i) { |
159 cdist[i].g = final.g-palcolors[i].g; | 157 cdist[i].r = final.r - palcolors[i].r; |
160 cdist[i].b = final.b-palcolors[i].b; | 158 cdist[i].g = final.g - palcolors[i].g; |
161 } | 159 cdist[i].b = final.b - palcolors[i].b; |
162 for ( i=0; i<=maxstep/2; ++i ) { /* halfway fade */ | 160 } |
163 int c; | 161 for (i = 0; i <= maxstep / 2; ++i) { /* halfway fade */ |
164 for ( c=0; c<ncolors; ++c ) { | 162 int c; |
165 colors[c].r = | 163 for (c = 0; c < ncolors; ++c) { |
166 palcolors[c].r+((cdist[c].r*i))/maxstep; | 164 colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; |
167 colors[c].g = | 165 colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; |
168 palcolors[c].g+((cdist[c].g*i))/maxstep; | 166 colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; |
169 colors[c].b = | 167 } |
170 palcolors[c].b+((cdist[c].b*i))/maxstep; | 168 SDL_SetColors (screen, colors, 0, ncolors); |
171 } | 169 SDL_Delay (1); |
172 SDL_SetColors(screen, colors, 0, ncolors); | 170 } |
173 SDL_Delay(1); | 171 final.r = 0x00; |
174 } | 172 final.g = 0x00; |
175 final.r = 0x00; | 173 final.b = 0x00; |
176 final.g = 0x00; | 174 memcpy (palcolors, colors, ncolors * sizeof (SDL_Color)); |
177 final.b = 0x00; | 175 for (i = 0; i < ncolors; ++i) { |
178 memcpy(palcolors, colors, ncolors*sizeof(SDL_Color)); | 176 cdist[i].r = final.r - palcolors[i].r; |
179 for ( i=0; i<ncolors; ++i ) { | 177 cdist[i].g = final.g - palcolors[i].g; |
180 cdist[i].r = final.r-palcolors[i].r; | 178 cdist[i].b = final.b - palcolors[i].b; |
181 cdist[i].g = final.g-palcolors[i].g; | 179 } |
182 cdist[i].b = final.b-palcolors[i].b; | 180 maxstep /= 2; |
183 } | 181 for (i = 0; i <= maxstep; ++i) { /* finish fade out */ |
184 maxstep /= 2; | 182 int c; |
185 for ( i=0; i<=maxstep; ++i ) { /* finish fade out */ | 183 for (c = 0; c < ncolors; ++c) { |
186 int c; | 184 colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; |
187 for ( c=0; c<ncolors; ++c ) { | 185 colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; |
188 colors[c].r = | 186 colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; |
189 palcolors[c].r+((cdist[c].r*i))/maxstep; | 187 } |
190 colors[c].g = | 188 SDL_SetColors (screen, colors, 0, ncolors); |
191 palcolors[c].g+((cdist[c].g*i))/maxstep; | 189 SDL_Delay (1); |
192 colors[c].b = | 190 } |
193 palcolors[c].b+((cdist[c].b*i))/maxstep; | 191 for (i = 0; i < ncolors; ++i) { |
194 } | 192 colors[i].r = final.r; |
195 SDL_SetColors(screen, colors, 0, ncolors); | 193 colors[i].g = final.g; |
196 SDL_Delay(1); | 194 colors[i].b = final.b; |
197 } | 195 } |
198 for ( i=0; i<ncolors; ++i ) { | 196 SDL_SetColors (screen, colors, 0, ncolors); |
199 colors[i].r = final.r; | 197 NOTICE ("testwin: fading in...\n"); |
200 colors[i].g = final.g; | 198 memcpy (palcolors, colors, ncolors * sizeof (SDL_Color)); |
201 colors[i].b = final.b; | 199 for (i = 0; i < ncolors; ++i) { |
202 } | 200 cdist[i].r = cmap[i].r - palcolors[i].r; |
203 SDL_SetColors(screen, colors, 0, ncolors); | 201 cdist[i].g = cmap[i].g - palcolors[i].g; |
204 NOTICE("testwin: fading in...\n"); | 202 cdist[i].b = cmap[i].b - palcolors[i].b; |
205 memcpy(palcolors, colors, ncolors*sizeof(SDL_Color)); | 203 } |
206 for ( i=0; i<ncolors; ++i ) { | 204 for (i = 0; i <= maxstep; ++i) { /* 32 step fade in */ |
207 cdist[i].r = cmap[i].r-palcolors[i].r; | 205 int c; |
208 cdist[i].g = cmap[i].g-palcolors[i].g; | 206 for (c = 0; c < ncolors; ++c) { |
209 cdist[i].b = cmap[i].b-palcolors[i].b; | 207 colors[c].r = palcolors[c].r + ((cdist[c].r * i)) / maxstep; |
210 } | 208 colors[c].g = palcolors[c].g + ((cdist[c].g * i)) / maxstep; |
211 for ( i=0; i<=maxstep; ++i ) { /* 32 step fade in */ | 209 colors[c].b = palcolors[c].b + ((cdist[c].b * i)) / maxstep; |
212 int c; | 210 } |
213 for ( c=0; c<ncolors; ++c ) { | 211 SDL_SetColors (screen, colors, 0, ncolors); |
214 colors[c].r = | 212 SDL_Delay (1); |
215 palcolors[c].r+((cdist[c].r*i))/maxstep; | 213 } |
216 colors[c].g = | 214 NOTICE ("testwin: fading over\n"); |
217 palcolors[c].g+((cdist[c].g*i))/maxstep; | 215 } |
218 colors[c].b = | 216 |
219 palcolors[c].b+((cdist[c].b*i))/maxstep; | 217 done: |
220 } | 218 /* Free the picture and return */ |
221 SDL_SetColors(screen, colors, 0, ncolors); | 219 SDL_FreeSurface (picture); |
222 SDL_Delay(1); | 220 free (colors); |
223 } | 221 free (cmap); |
224 NOTICE("testwin: fading over\n"); | 222 return; |
225 } | |
226 | |
227 done: | |
228 /* Free the picture and return */ | |
229 SDL_FreeSurface(picture); | |
230 free(colors); free(cmap); | |
231 return; | |
232 } | 223 } |
233 | 224 |
234 int main(int argc, char *argv[]) | 225 int |
226 main (int argc, char *argv[]) | |
235 { | 227 { |
236 SDL_Surface *screen; | 228 SDL_Surface *screen; |
237 /* Options */ | 229 /* Options */ |
238 int speedy, flip, nofade; | 230 int speedy, flip, nofade; |
239 int delay; | 231 int delay; |
240 int w, h; | 232 int w, h; |
241 int desired_bpp; | 233 int desired_bpp; |
242 Uint32 video_flags; | 234 Uint32 video_flags; |
243 #ifdef BENCHMARK_SDL | 235 #ifdef BENCHMARK_SDL |
244 Uint32 then, now; | 236 Uint32 then, now; |
245 #endif | 237 #endif |
246 /* Set default options and check command-line */ | 238 /* Set default options and check command-line */ |
247 speedy = 0; | 239 speedy = 0; |
248 flip = 0; | 240 flip = 0; |
249 nofade = 0; | 241 nofade = 0; |
250 delay = 1; | 242 delay = 1; |
251 | 243 |
252 #ifdef _WIN32_WCE | 244 #ifdef _WIN32_WCE |
253 w = 240; | 245 w = 240; |
254 h = 320; | 246 h = 320; |
255 desired_bpp = 8; | 247 desired_bpp = 8; |
256 video_flags = SDL_FULLSCREEN; | 248 video_flags = SDL_FULLSCREEN; |
257 #else | 249 #else |
258 w = 640; | 250 w = 640; |
259 h = 480; | 251 h = 480; |
260 desired_bpp = 0; | 252 desired_bpp = 0; |
261 video_flags = 0; | 253 video_flags = 0; |
262 #endif | 254 #endif |
263 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | 255 if (SDL_Init (SDL_INIT_VIDEO) < 0) { |
264 fprintf(stderr, | 256 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); |
265 "Couldn't initialize SDL: %s\n", SDL_GetError()); | 257 return (1); |
266 return(1); | 258 } |
267 } | 259 |
268 | 260 while (argc > 1) { |
269 while ( argc > 1 ) { | 261 if (strcmp (argv[1], "-speedy") == 0) { |
270 if ( strcmp(argv[1], "-speedy") == 0 ) { | 262 speedy = 1; |
271 speedy = 1; | 263 argv += 1; |
272 argv += 1; | 264 argc -= 1; |
273 argc -= 1; | 265 } else if (strcmp (argv[1], "-nofade") == 0) { |
274 } else | 266 nofade = 1; |
275 if ( strcmp(argv[1], "-nofade") == 0 ) { | 267 argv += 1; |
276 nofade = 1; | 268 argc -= 1; |
277 argv += 1; | 269 } else if (strcmp (argv[1], "-delay") == 0) { |
278 argc -= 1; | 270 if (argv[2]) { |
279 } else | 271 delay = atoi (argv[2]); |
280 if ( strcmp(argv[1], "-delay") == 0 ) { | 272 argv += 2; |
281 if ( argv[2] ) { | 273 argc -= 2; |
282 delay = atoi(argv[2]); | 274 } else { |
283 argv += 2; | 275 fprintf (stderr, "The -delay option requires an argument\n"); |
284 argc -= 2; | 276 quit (1); |
285 } else { | 277 } |
286 fprintf(stderr, | 278 } else if (strcmp (argv[1], "-width") == 0) { |
287 "The -delay option requires an argument\n"); | 279 if (argv[2] && ((w = atoi (argv[2])) > 0)) { |
288 quit(1); | 280 argv += 2; |
289 } | 281 argc -= 2; |
290 } else | 282 } else { |
291 if ( strcmp(argv[1], "-width") == 0 ) { | 283 fprintf (stderr, "The -width option requires an argument\n"); |
292 if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { | 284 quit (1); |
293 argv += 2; | 285 } |
294 argc -= 2; | 286 } else if (strcmp (argv[1], "-height") == 0) { |
295 } else { | 287 if (argv[2] && ((h = atoi (argv[2])) > 0)) { |
296 fprintf(stderr, | 288 argv += 2; |
297 "The -width option requires an argument\n"); | 289 argc -= 2; |
298 quit(1); | 290 } else { |
299 } | 291 fprintf (stderr, "The -height option requires an argument\n"); |
300 } else | 292 quit (1); |
301 if ( strcmp(argv[1], "-height") == 0 ) { | 293 } |
302 if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { | 294 } else if (strcmp (argv[1], "-bpp") == 0) { |
303 argv += 2; | 295 if (argv[2]) { |
304 argc -= 2; | 296 desired_bpp = atoi (argv[2]); |
305 } else { | 297 argv += 2; |
306 fprintf(stderr, | 298 argc -= 2; |
307 "The -height option requires an argument\n"); | 299 } else { |
308 quit(1); | 300 fprintf (stderr, "The -bpp option requires an argument\n"); |
309 } | 301 quit (1); |
310 } else | 302 } |
311 if ( strcmp(argv[1], "-bpp") == 0 ) { | 303 } else if (strcmp (argv[1], "-warp") == 0) { |
312 if ( argv[2] ) { | 304 video_flags |= SDL_HWPALETTE; |
313 desired_bpp = atoi(argv[2]); | 305 argv += 1; |
314 argv += 2; | 306 argc -= 1; |
315 argc -= 2; | 307 } else if (strcmp (argv[1], "-hw") == 0) { |
316 } else { | 308 video_flags |= SDL_HWSURFACE; |
317 fprintf(stderr, | 309 argv += 1; |
318 "The -bpp option requires an argument\n"); | 310 argc -= 1; |
319 quit(1); | 311 } else if (strcmp (argv[1], "-flip") == 0) { |
320 } | 312 video_flags |= SDL_DOUBLEBUF; |
321 } else | 313 argv += 1; |
322 if ( strcmp(argv[1], "-warp") == 0 ) { | 314 argc -= 1; |
323 video_flags |= SDL_HWPALETTE; | 315 } else if (strcmp (argv[1], "-fullscreen") == 0) { |
324 argv += 1; | 316 video_flags |= SDL_FULLSCREEN; |
325 argc -= 1; | 317 argv += 1; |
326 } else | 318 argc -= 1; |
327 if ( strcmp(argv[1], "-hw") == 0 ) { | 319 } else |
328 video_flags |= SDL_HWSURFACE; | 320 break; |
329 argv += 1; | 321 } |
330 argc -= 1; | 322 |
331 } else | 323 /* Initialize the display */ |
332 if ( strcmp(argv[1], "-flip") == 0 ) { | 324 screen = SDL_SetVideoMode (w, h, desired_bpp, video_flags); |
333 video_flags |= SDL_DOUBLEBUF; | 325 if (screen == NULL) { |
334 argv += 1; | 326 fprintf (stderr, "Couldn't set %dx%dx%d video mode: %s\n", |
335 argc -= 1; | 327 w, h, desired_bpp, SDL_GetError ()); |
336 } else | 328 quit (1); |
337 if ( strcmp(argv[1], "-fullscreen") == 0 ) { | 329 } |
338 video_flags |= SDL_FULLSCREEN; | 330 printf ("Set%s %dx%dx%d mode\n", |
339 argv += 1; | 331 screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", |
340 argc -= 1; | 332 screen->w, screen->h, screen->format->BitsPerPixel); |
341 } else | 333 printf ("(video surface located in %s memory)\n", |
342 break; | 334 (screen->flags & SDL_HWSURFACE) ? "video" : "system"); |
343 } | 335 if (screen->flags & SDL_DOUBLEBUF) { |
344 | 336 printf ("Double-buffering enabled\n"); |
345 /* Initialize the display */ | 337 flip = 1; |
346 screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); | 338 } |
347 if ( screen == NULL ) { | 339 |
348 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", | 340 /* Set the window manager title bar */ |
349 w, h, desired_bpp, SDL_GetError()); | 341 SDL_WM_SetCaption ("SDL test window", "testwin"); |
350 quit(1); | 342 |
351 } | 343 /* Do all the drawing work */ |
352 printf("Set%s %dx%dx%d mode\n", | |
353 screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", | |
354 screen->w, screen->h, screen->format->BitsPerPixel); | |
355 printf("(video surface located in %s memory)\n", | |
356 (screen->flags&SDL_HWSURFACE) ? "video" : "system"); | |
357 if ( screen->flags & SDL_DOUBLEBUF ) { | |
358 printf("Double-buffering enabled\n"); | |
359 flip = 1; | |
360 } | |
361 | |
362 /* Set the window manager title bar */ | |
363 SDL_WM_SetCaption("SDL test window", "testwin"); | |
364 | |
365 /* Do all the drawing work */ | |
366 #ifdef BENCHMARK_SDL | 344 #ifdef BENCHMARK_SDL |
367 then = SDL_GetTicks(); | 345 then = SDL_GetTicks (); |
368 DrawPict(screen, argv[1], speedy, flip, nofade); | 346 DrawPict (screen, argv[1], speedy, flip, nofade); |
369 now = SDL_GetTicks(); | 347 now = SDL_GetTicks (); |
370 printf("Time: %d milliseconds\n", now-then); | 348 printf ("Time: %d milliseconds\n", now - then); |
371 #else | 349 #else |
372 DrawPict(screen, argv[1], speedy, flip, nofade); | 350 DrawPict (screen, argv[1], speedy, flip, nofade); |
373 #endif | 351 #endif |
374 SDL_Delay(delay*1000); | 352 SDL_Delay (delay * 1000); |
375 SDL_Quit(); | 353 SDL_Quit (); |
376 return(0); | 354 return (0); |
377 } | 355 } |