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