10 int win_width, win_height;
11 int max_xscroll, max_yscroll;
15 unsigned int img[IMG_W * IMG_H];
17 unsigned int start_tm;
18 unsigned int num_frames;
24 int main(int argc, char **argv)
26 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
27 if(!(fbsurf = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE))) {
28 fprintf(stderr, "failed to set video mode\n");
31 SDL_WM_SetCaption("SDL pixel drawing benchmark", 0);
37 start_tm = SDL_GetTicks();
40 while(SDL_PollEvent(&ev)) {
46 if(ev.key.keysym.sym == 27) goto done;
66 int i, j, xor, r, g, b;
70 for(i=0; i<IMG_H; i++) {
71 for(j=0; j<IMG_W; j++) {
73 r = (xor >> 1) & 0xff;
75 b = (xor << 1) & 0xff;
76 *ptr++ = b | (g << 8) | (r << 16);
83 max_xscroll = IMG_W - win_width;
84 max_yscroll = IMG_H - win_height;
91 unsigned int tm = SDL_GetTicks() - start_tm;
93 float t = tm / 256.0f;
94 int xoffs = (int)((sin(t) * 0.5f + 0.5f) * max_xscroll);
95 int yoffs = (int)((cos(t) * 0.5f + 0.5f) * max_yscroll);
96 unsigned int *start = img + yoffs * IMG_W + xoffs;
99 if(SDL_MUSTLOCK(fbsurf)) {
100 SDL_LockSurface(fbsurf);
102 dest = fbsurf->pixels;
104 for(i=0; i<win_height; i++) {
105 for(j=0; j<win_width; j++) {
111 if(SDL_MUSTLOCK(fbsurf)) {
112 SDL_UnlockSurface(fbsurf);
118 interv = tm - start_tm;
120 unsigned int fps = 100000 * num_frames / interv;
121 printf("SDL: %.2f fps\n", fps / 100.0f);