test/testpalette.c
changeset 1151 be9c9c8f6d53
parent 0 74212992fb08
child 1429 aff0170f9f1b
equal deleted inserted replaced
1150:7d8e1925f35b 1151:be9c9c8f6d53
    52     {4,203,252}, {3,181,252}, {2,158,252}, {1,136,251},
    52     {4,203,252}, {3,181,252}, {2,158,252}, {1,136,251},
    53     {0,111,248}, {0,82,234}, {0,63,213}, {0,50,192},
    53     {0,111,248}, {0,82,234}, {0,63,213}, {0,50,192},
    54     {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114}
    54     {0,39,172}, {0,28,152}, {0,17,132}, {0,7,114}
    55 };
    55 };
    56 
    56 
       
    57 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
       
    58 static void quit(int rc)
       
    59 {
       
    60 	SDL_Quit();
       
    61 	exit(rc);
       
    62 }
       
    63 
    57 static void sdlerr(char *when)
    64 static void sdlerr(char *when)
    58 {
    65 {
    59     fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError());
    66     fprintf(stderr, "SDL error: %s: %s\n", when, SDL_GetError());
    60     exit(1);
    67     quit(1);
    61 }
    68 }
    62 
    69 
    63 /* create a background surface */
    70 /* create a background surface */
    64 static SDL_Surface *make_bg(SDL_Surface *screen, int startcol)
    71 static SDL_Surface *make_bg(SDL_Surface *screen, int startcol)
    65 {
    72 {
   136     int gamma_fade = 0;
   143     int gamma_fade = 0;
   137     int gamma_ramp = 0;
   144     int gamma_ramp = 0;
   138 
   145 
   139     if(SDL_Init(SDL_INIT_VIDEO) < 0)
   146     if(SDL_Init(SDL_INIT_VIDEO) < 0)
   140 	sdlerr("initialising SDL");
   147 	sdlerr("initialising SDL");
   141 
       
   142     atexit(SDL_Quit);
       
   143 
   148 
   144     while(--argc) {
   149     while(--argc) {
   145 	++argv;
   150 	++argv;
   146 	if(strcmp(*argv, "-hw") == 0)
   151 	if(strcmp(*argv, "-hw") == 0)
   147 	    vidflags |= SDL_HWSURFACE;
   152 	    vidflags |= SDL_HWSURFACE;
   155 	    gamma_ramp = 1;
   160 	    gamma_ramp = 1;
   156 	else {
   161 	else {
   157 	    fprintf(stderr,
   162 	    fprintf(stderr,
   158 		    "usage: testpalette "
   163 		    "usage: testpalette "
   159 		    " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
   164 		    " [-hw] [-fullscreen] [-nofade] [-gamma] [-gammaramp]\n");
   160 	    return 1;
   165 	    quit(1);
   161 	}
   166 	}
   162     }
   167     }
   163 
   168 
   164     /* Ask explicitly for 8bpp and a hardware palette */
   169     /* Ask explicitly for 8bpp and a hardware palette */
   165     if(!(screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE))) {
   170     if(!(screen = SDL_SetVideoMode(SCRW, SCRH, 8, vidflags | SDL_HWPALETTE))) {
   166 	fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
   171 	fprintf(stderr, "error setting %dx%d 8bpp indexed mode: %s\n",
   167 		SCRW, SCRH, SDL_GetError());
   172 		SCRW, SCRH, SDL_GetError());
   168 	return 1;
   173 	quit(1);
   169     }
   174     }
   170 
   175 
   171     if(!(boat[0] = SDL_LoadBMP("sail.bmp")))
   176     if(!(boat[0] = SDL_LoadBMP("sail.bmp")))
   172 	sdlerr("loading sail.bmp");
   177 	sdlerr("loading sail.bmp");
   173     /* We've chosen magenta (#ff00ff) as colour key for the boat */
   178     /* We've chosen magenta (#ff00ff) as colour key for the boat */
   325 	frames++;
   330 	frames++;
   326     } while(fade_level > 0);
   331     } while(fade_level > 0);
   327 
   332 
   328     printf("%d frames, %.2f fps\n",
   333     printf("%d frames, %.2f fps\n",
   329 	   frames, 1000.0 * frames / (SDL_GetTicks() - start));
   334 	   frames, 1000.0 * frames / (SDL_GetTicks() - start));
       
   335 
       
   336     SDL_Quit();
   330     return 0;
   337     return 0;
   331 }
   338 }
   332 
   339