test/graywin.c
changeset 538 d3abe873e3f7
parent 380 bce7171e7a85
child 691 609543e2b3a1
     1.1 --- a/test/graywin.c	Sat Nov 09 05:51:13 2002 +0000
     1.2 +++ b/test/graywin.c	Sat Nov 09 05:52:49 2002 +0000
     1.3 @@ -36,7 +36,11 @@
     1.4  
     1.5  	/* Do it! */
     1.6  	SDL_FillRect(screen, &area, color);
     1.7 -	SDL_UpdateRects(screen, 1, &area);
     1.8 +	if ( screen->flags & SDL_DOUBLEBUF ) {
     1.9 +		SDL_Flip(screen);
    1.10 +	} else {
    1.11 +		SDL_UpdateRects(screen, 1, &area);
    1.12 +	}
    1.13  }
    1.14  
    1.15  SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
    1.16 @@ -65,18 +69,25 @@
    1.17  	SDL_SetColors(screen, palette, 0, NUM_COLORS);
    1.18  
    1.19  	/* Set the surface pixels and refresh! */
    1.20 -	if ( SDL_LockSurface(screen) < 0 ) {
    1.21 -		fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.22 -							SDL_GetError());
    1.23 -		return(NULL);
    1.24 +	/* Use two loops in case the surface is double-buffered (both sides) */
    1.25 +	for ( i=0; i<2; ++i ) {
    1.26 +		if ( SDL_LockSurface(screen) < 0 ) {
    1.27 +			fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.28 +								SDL_GetError());
    1.29 +			return(NULL);
    1.30 +		}
    1.31 +		buffer = (Uint8 *)screen->pixels;
    1.32 +		for ( i=0; i<screen->h; ++i ) {
    1.33 +			memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
    1.34 +			buffer += screen->pitch;
    1.35 +		}
    1.36 +		SDL_UnlockSurface(screen);
    1.37 +		if ( screen->flags & SDL_DOUBLEBUF ) {
    1.38 +			SDL_Flip(screen);
    1.39 +		} else {
    1.40 +			SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.41 +		}
    1.42  	}
    1.43 -	buffer = (Uint8 *)screen->pixels;
    1.44 -	for ( i=0; i<screen->h; ++i ) {
    1.45 -		memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
    1.46 -		buffer += screen->pitch;
    1.47 -	}
    1.48 -	SDL_UnlockSurface(screen);
    1.49 -	SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.50  
    1.51  	return(screen);
    1.52  }
    1.53 @@ -120,13 +131,16 @@
    1.54  		if ( argv[argc] && (strcmp(argv[argc], "-hwpalette") == 0) ) {
    1.55  			videoflags |= SDL_HWPALETTE;
    1.56  		} else
    1.57 +		if ( argv[argc] && (strcmp(argv[argc], "-flip") == 0) ) {
    1.58 +			videoflags |= SDL_DOUBLEBUF;
    1.59 +		} else
    1.60  		if ( argv[argc] && (strcmp(argv[argc], "-noframe") == 0) ) {
    1.61  			videoflags |= SDL_NOFRAME;
    1.62  		} else
    1.63  		if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
    1.64  			videoflags |= SDL_FULLSCREEN;
    1.65  		} else {
    1.66 -			fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n",
    1.67 +			fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-flip] [-noframe] [-fullscreen]\n",
    1.68  								argv[0]);
    1.69  			exit(1);
    1.70  		}