unknown changes
[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 "timer.h"
7 #include "screen.h"
8 #include "screen.h"
9 #include "demo.h"
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 long start_msec, num_frames;
16
17 static int quit;
18
19
20 int main(void)
21 {
22         int i, trybpp[] = {16, 32, 24, 16, 0};
23
24         fbgfx_save_video_mode();
25         fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth);
26
27         for(i=0; trybpp[i]; i++) {
28                 if(!(fb_pixels = fbgfx_set_video_mode(fb_width, fb_height, trybpp[i]))) {
29                         continue;
30                 }
31                 fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth);
32                 if(fb_depth == trybpp[i]) {
33                         break;
34                 }
35                 fprintf(stderr, "failed to set color fb_depth: %dbpp\n", trybpp[i]);
36         }
37         if(trybpp[i] == 0) {
38                 fprintf(stderr, "no usable color fb_depths found\n");
39                 goto end;
40         }
41
42         if(fbev_init() == -1) {
43                 goto end;
44         }
45         fbev_keyboard(keyboard, 0);
46         fbev_mbutton(mouse, 0);
47         fbev_mmotion(motion, 0);
48
49         if(scr_init() == -1) {
50                 goto end;
51         }
52         scr_change(scr_lookup("console"), 0);
53         scr_change(scr_lookup("tunnel"), 4000);
54
55         start_msec = get_time_msec();
56         for(;;) {
57                 fbev_update();
58                 if(quit) break;
59
60                 time_msec = get_time_msec() - start_msec;
61
62                 scr_update();
63                 scr_draw();
64                 ++num_frames;
65         }
66
67         time_msec = get_time_msec() - start_msec;
68 end:
69         scr_shutdown();
70         fbev_shutdown();
71         fbgfx_restore_video_mode();
72         if(num_frames && time_msec) {
73                 printf("\ravg framerate: %.1f\n", (float)num_frames / ((float)time_msec / 1000.0));
74         }
75         return 0;
76 }
77
78 static void keyboard(int key, int pressed, void *cls)
79 {
80         if(!pressed) return;
81
82         switch(key) {
83         case 27:
84         case 'q':
85         case 'Q':
86                 quit = 1;
87                 break;
88         }
89 }
90
91 static void mouse(int bn, int pressed, int x, int y, void *cls)
92 {
93 }
94
95 static void motion(int x, int y, void *cls)
96 {
97 }