visual studio project for the SDL backend
[dosdemo] / src / demo.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include <errno.h>
6 #include <limits.h>
7 #include "demo.h"
8 #include "screen.h"
9
10 int fb_width = 320;
11 int fb_height = 240;
12 int fb_bpp = 16;
13 void *fb_pixels;
14 unsigned long time_msec;
15
16 static unsigned long nframes;
17
18 int demo_init(int argc, char **argv)
19 {
20         if(scr_init() == -1) {
21                 return -1;
22         }
23         scr_change(scr_lookup("tunnel"), 4000);
24
25         /* clear the framebuffer at least once */
26         memset(fb_pixels, 0, fb_width * fb_height * fb_bpp / CHAR_BIT);
27         return 0;
28 }
29
30 void demo_cleanup(void)
31 {
32         scr_shutdown();
33
34         if(time_msec) {
35                 float fps = (float)nframes / ((float)time_msec / 1000.0f);
36                 printf("average framerate: %.1f\n", fps);
37         }
38 }
39
40 void demo_draw(void)
41 {
42         scr_update();
43         scr_draw();
44
45         ++nframes;
46 }
47
48 void demo_keyboard(int key, int state)
49 {
50         if(state) {
51                 switch(key) {
52                 case 27:
53                         demo_quit();
54                         break;
55
56                 default:
57                         break;
58                 }
59         }
60 }