comparison test/graywin.c @ 538:d3abe873e3f7

Added support for testing video flipping with graywin.c
author Sam Lantinga <slouken@libsdl.org>
date Sat, 09 Nov 2002 05:52:49 +0000
parents bce7171e7a85
children 609543e2b3a1
comparison
equal deleted inserted replaced
537:77b05010bb33 538:d3abe873e3f7
34 area.y = Y-(area.h/2); 34 area.y = Y-(area.h/2);
35 color = (rand()%NUM_COLORS); 35 color = (rand()%NUM_COLORS);
36 36
37 /* Do it! */ 37 /* Do it! */
38 SDL_FillRect(screen, &area, color); 38 SDL_FillRect(screen, &area, color);
39 SDL_UpdateRects(screen, 1, &area); 39 if ( screen->flags & SDL_DOUBLEBUF ) {
40 SDL_Flip(screen);
41 } else {
42 SDL_UpdateRects(screen, 1, &area);
43 }
40 } 44 }
41 45
42 SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) 46 SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
43 { 47 {
44 SDL_Surface *screen; 48 SDL_Surface *screen;
63 palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS); 67 palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
64 } 68 }
65 SDL_SetColors(screen, palette, 0, NUM_COLORS); 69 SDL_SetColors(screen, palette, 0, NUM_COLORS);
66 70
67 /* Set the surface pixels and refresh! */ 71 /* Set the surface pixels and refresh! */
68 if ( SDL_LockSurface(screen) < 0 ) { 72 /* Use two loops in case the surface is double-buffered (both sides) */
69 fprintf(stderr, "Couldn't lock display surface: %s\n", 73 for ( i=0; i<2; ++i ) {
70 SDL_GetError()); 74 if ( SDL_LockSurface(screen) < 0 ) {
71 return(NULL); 75 fprintf(stderr, "Couldn't lock display surface: %s\n",
76 SDL_GetError());
77 return(NULL);
78 }
79 buffer = (Uint8 *)screen->pixels;
80 for ( i=0; i<screen->h; ++i ) {
81 memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
82 buffer += screen->pitch;
83 }
84 SDL_UnlockSurface(screen);
85 if ( screen->flags & SDL_DOUBLEBUF ) {
86 SDL_Flip(screen);
87 } else {
88 SDL_UpdateRect(screen, 0, 0, 0, 0);
89 }
72 } 90 }
73 buffer = (Uint8 *)screen->pixels;
74 for ( i=0; i<screen->h; ++i ) {
75 memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
76 buffer += screen->pitch;
77 }
78 SDL_UnlockSurface(screen);
79 SDL_UpdateRect(screen, 0, 0, 0, 0);
80 91
81 return(screen); 92 return(screen);
82 } 93 }
83 94
84 int main(int argc, char *argv[]) 95 int main(int argc, char *argv[])
118 videoflags |= SDL_HWSURFACE; 129 videoflags |= SDL_HWSURFACE;
119 } else 130 } else
120 if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) { 131 if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) {
121 videoflags |= SDL_HWPALETTE; 132 videoflags |= SDL_HWPALETTE;
122 } else 133 } else
134 if ( argv[argc] && (strcmp(argv[argc], "-flip") == 0) ) {
135 videoflags |= SDL_DOUBLEBUF;
136 } else
123 if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) { 137 if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) {
124 videoflags |= SDL_NOFRAME; 138 videoflags |= SDL_NOFRAME;
125 } else 139 } else
126 if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) { 140 if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
127 videoflags |= SDL_FULLSCREEN; 141 videoflags |= SDL_FULLSCREEN;
128 } else { 142 } else {
129 fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n", 143 fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen]\n",
130 argv[0]); 144 argv[0]);
131 exit(1); 145 exit(1);
132 } 146 }
133 } 147 }
134 148