X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=fbgfx;a=blobdiff_plain;f=src%2Fmain.c;h=4d63726f3307514d854b2f01f82687c79ddb6f95;hp=9d73367be921b9d44ab2591288557b4206777512;hb=55eb7990ac9033d9a0185dc9238365b5624be64e;hpb=7e9af893a6d14c0136a89648a2fdebab614a662f diff --git a/src/main.c b/src/main.c index 9d73367..4d63726 100644 --- a/src/main.c +++ b/src/main.c @@ -1,19 +1,97 @@ #include -#include #include +#include #include "fbgfx.h" +#include "fbevents.h" +#include "timer.h" +#include "screen.h" +#include "screen.h" +#include "demo.h" + +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 long start_msec, num_frames; + +static int quit; -static unsigned char *vmem; -static int xsz, ysz, depth; int main(void) { - if(!(vmem = fbgfx_get_video_mode(&xsz, &ysz, &depth))) { - return 1; + int i, trybpp[] = {16, 32, 24, 16, 0}; + + fbgfx_save_video_mode(); + fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth); + + for(i=0; trybpp[i]; i++) { + if(!(fb_pixels = fbgfx_set_video_mode(fb_width, fb_height, trybpp[i]))) { + continue; + } + fbgfx_get_video_mode(&fb_width, &fb_height, &fb_depth); + if(fb_depth == trybpp[i]) { + break; + } + fprintf(stderr, "failed to set color fb_depth: %dbpp\n", trybpp[i]); } - printf("current video mode: %dx%d %dbpp\n", xsz, ysz, depth); + if(trybpp[i] == 0) { + fprintf(stderr, "no usable color fb_depths found\n"); + goto end; + } + + if(fbev_init() == -1) { + goto end; + } + fbev_keyboard(keyboard, 0); + fbev_mbutton(mouse, 0); + fbev_mmotion(motion, 0); - /*memset(vmem, 0xff, xsz * ysz * depth / 8);*/ + if(scr_init() == -1) { + goto end; + } + scr_change(scr_lookup("console"), 0); + scr_change(scr_lookup("tunnel"), 4000); + start_msec = get_time_msec(); + for(;;) { + fbev_update(); + if(quit) break; + + time_msec = get_time_msec() - start_msec; + + scr_update(); + scr_draw(); + ++num_frames; + } + + time_msec = get_time_msec() - start_msec; +end: + scr_shutdown(); + 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) +{ +}