comparison test/testfill.c @ 3576:5ea08f1c29d0

Added testfill to test raw fill performance
author Sam Lantinga <slouken@libsdl.org>
date Wed, 16 Dec 2009 02:08:59 +0000
parents
children
comparison
equal deleted inserted replaced
3575:239ae83fc2f6 3576:5ea08f1c29d0
1 /* Simple program: Fill the screen with colors as fast as possible */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <time.h>
7
8 #include "SDL.h"
9
10 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
11 static void
12 quit(int rc)
13 {
14 SDL_Quit();
15 exit(rc);
16 }
17
18 int
19 main(int argc, char *argv[])
20 {
21 SDL_Surface *screen;
22 int width, height;
23 Uint8 video_bpp;
24 Uint32 videoflags;
25 Uint32 colors[3];
26 int i, done;
27 SDL_Event event;
28 Uint32 then, now, frames;
29
30 /* Initialize SDL */
31 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
32 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
33 return (1);
34 }
35
36 width = 640;
37 height = 480;
38 video_bpp = 8;
39 videoflags = 0;
40 while (argc > 1) {
41 --argc;
42 if (strcmp(argv[argc - 1], "-width") == 0) {
43 width = atoi(argv[argc]);
44 --argc;
45 } else if (strcmp(argv[argc - 1], "-height") == 0) {
46 height = atoi(argv[argc]);
47 --argc;
48 } else if (strcmp(argv[argc - 1], "-bpp") == 0) {
49 video_bpp = atoi(argv[argc]);
50 --argc;
51 } else if (strcmp(argv[argc], "-fullscreen") == 0) {
52 videoflags ^= SDL_FULLSCREEN;
53 } else {
54 fprintf(stderr,
55 "Usage: %s [-width N] [-height N] [-bpp N] [-fullscreen]\n",
56 argv[0]);
57 quit(1);
58 }
59 }
60
61 /* Set video mode */
62 screen = SDL_SetVideoMode(width, height, video_bpp, 0);
63 if (!screen) {
64 fprintf(stderr, "Couldn't set %dx%d video mode: %s\n",
65 width, height, SDL_GetError());
66 quit(2);
67 }
68
69 /* Get the colors */
70 colors[0] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00);
71 colors[1] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00);
72 colors[2] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF);
73
74 /* Loop, filling and waiting for a keystroke */
75 frames = 0;
76 then = SDL_GetTicks();
77 done = 0;
78 while (!done) {
79 /* Check for events */
80 ++frames;
81 while (SDL_PollEvent(&event)) {
82 switch (event.type) {
83 case SDL_MOUSEBUTTONDOWN:
84 SDL_WarpMouse(screen->w / 2, screen->h / 2);
85 break;
86 case SDL_KEYDOWN:
87 /* Any keypress quits the app... */
88 case SDL_QUIT:
89 done = 1;
90 break;
91 default:
92 break;
93 }
94 }
95 SDL_FillRect(screen, NULL, colors[frames%3]);
96 SDL_Flip(screen);
97 }
98
99 /* Print out some timing information */
100 now = SDL_GetTicks();
101 if (now > then) {
102 double fps = ((double) frames * 1000) / (now - then);
103 printf("%2.2f frames per second\n", fps);
104 }
105 SDL_Quit();
106 return (0);
107 }