hacked support for both 16 and 32 bpp framebuffers
[fbgfx] / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "fbgfx.h"
5 #include "fbevents.h"
6 #include "tunnel.h"
7 #include "timer.h"
8
9 unsigned long start_msec, time_msec, num_frames;
10
11 static void keyboard(int key, int pressed, void *cls);
12 static void mouse(int bn, int pressed, int x, int y, void *cls);
13 static void motion(int x, int y, void *cls);
14
15 static void *vmem;
16 static int xsz, ysz, depth;
17
18 static int quit;
19
20
21 int main(void)
22 {
23         fbgfx_save_video_mode();
24         if(!(vmem = fbgfx_get_video_mode(&xsz, &ysz, &depth))) {
25                 return 1;
26         }
27
28         /*if(!(vmem = fbgfx_set_video_mode(xsz, ysz, 16))) {
29                 return 1;
30         }
31         fbgfx_get_video_mode(&xsz, &ysz, &depth);
32         if(depth != 16) {
33                 fprintf(stderr, "failed to set color depth: 16bpp\n");
34                 goto end;
35         }*/
36         if(fbev_init() == -1) {
37                 goto end;
38         }
39         fbev_keyboard(keyboard, 0);
40         fbev_mbutton(mouse, 0);
41         fbev_mmotion(motion, 0);
42
43         if(init_tunnel(xsz, ysz, depth) == -1) {
44                 goto end;
45         }
46
47         start_msec = get_time_msec();
48         for(;;) {
49                 fbev_update();
50                 if(quit) break;
51
52                 time_msec = get_time_msec() - start_msec;
53
54                 draw_tunnel(vmem);
55                 ++num_frames;
56         }
57
58         time_msec = get_time_msec() - start_msec;
59 end:
60         destroy_tunnel();
61         fbev_shutdown();
62         fbgfx_restore_video_mode();
63         if(num_frames && time_msec) {
64                 printf("\ravg framerate: %.1f\n", (float)num_frames / ((float)time_msec / 1000.0));
65         }
66         return 0;
67 }
68
69 static void keyboard(int key, int pressed, void *cls)
70 {
71         if(!pressed) return;
72
73         switch(key) {
74         case 27:
75         case 'q':
76         case 'Q':
77                 quit = 1;
78                 break;
79         }
80 }
81
82 static void mouse(int bn, int pressed, int x, int y, void *cls)
83 {
84 }
85
86 static void motion(int x, int y, void *cls)
87 {
88 }