hacked support for both 16 and 32 bpp framebuffers
[fbgfx] / src / main.c
index 9d73367..9e27509 100644 (file)
@@ -1,19 +1,88 @@
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
+#include <string.h>
 #include "fbgfx.h"
+#include "fbevents.h"
+#include "tunnel.h"
+#include "timer.h"
+
+unsigned long start_msec, time_msec, num_frames;
+
+static void keyboard(int key, int pressed, void *cls);
+static void mouse(int bn, int pressed, int x, int y, void *cls);
+static void motion(int x, int y, void *cls);
 
-static unsigned char *vmem;
+static void *vmem;
 static int xsz, ysz, depth;
 
+static int quit;
+
+
 int main(void)
 {
+       fbgfx_save_video_mode();
        if(!(vmem = fbgfx_get_video_mode(&xsz, &ysz, &depth))) {
                return 1;
        }
-       printf("current video mode: %dx%d %dbpp\n", xsz, ysz, depth);
 
-       /*memset(vmem, 0xff, xsz * ysz * depth / 8);*/
+       /*if(!(vmem = fbgfx_set_video_mode(xsz, ysz, 16))) {
+               return 1;
+       }
+       fbgfx_get_video_mode(&xsz, &ysz, &depth);
+       if(depth != 16) {
+               fprintf(stderr, "failed to set color depth: 16bpp\n");
+               goto end;
+       }*/
+       if(fbev_init() == -1) {
+               goto end;
+       }
+       fbev_keyboard(keyboard, 0);
+       fbev_mbutton(mouse, 0);
+       fbev_mmotion(motion, 0);
+
+       if(init_tunnel(xsz, ysz, depth) == -1) {
+               goto end;
+       }
 
+       start_msec = get_time_msec();
+       for(;;) {
+               fbev_update();
+               if(quit) break;
+
+               time_msec = get_time_msec() - start_msec;
+
+               draw_tunnel(vmem);
+               ++num_frames;
+       }
+
+       time_msec = get_time_msec() - start_msec;
+end:
+       destroy_tunnel();
+       fbev_shutdown();
+       fbgfx_restore_video_mode();
+       if(num_frames && time_msec) {
+               printf("\ravg framerate: %.1f\n", (float)num_frames / ((float)time_msec / 1000.0));
+       }
        return 0;
 }
+
+static void keyboard(int key, int pressed, void *cls)
+{
+       if(!pressed) return;
+
+       switch(key) {
+       case 27:
+       case 'q':
+       case 'Q':
+               quit = 1;
+               break;
+       }
+}
+
+static void mouse(int bn, int pressed, int x, int y, void *cls)
+{
+}
+
+static void motion(int x, int y, void *cls)
+{
+}