X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fmain.c;h=f0588c01f5ad12dc41223a3981ce6cd2bdc30d2c;hb=21180fdf54f0c578af0959df088de308ce25ca61;hp=8752567992db2f648b87b1f6ab4c78136976d0f8;hpb=4b522caf5387f8075b7bbb2a2b0475c012157456;p=fbgfx diff --git a/src/main.c b/src/main.c index 8752567..f0588c0 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,9 @@ #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); @@ -17,14 +20,26 @@ static int quit; int main(void) { + int i, trybpp[] = {32, 24, 16, 0}; + fbgfx_save_video_mode(); - if(!(vmem = fbgfx_set_video_mode(800, 600, 16))) { - return 1; - } fbgfx_get_video_mode(&xsz, &ysz, &depth); - if(depth != 16) { + + for(i=0; trybpp[i]; i++) { + if(!(vmem = fbgfx_set_video_mode(xsz, ysz, trybpp[i]))) { + continue; + } + fbgfx_get_video_mode(&xsz, &ysz, &depth); + if(depth == trybpp[i]) { + break; + } + fprintf(stderr, "failed to set color depth: %dbpp\n", trybpp[i]); + } + if(trybpp[i] == 0) { + fprintf(stderr, "no usable color depths found\n"); goto end; } + if(fbev_init() == -1) { goto end; } @@ -32,21 +47,29 @@ int main(void) fbev_mbutton(mouse, 0); fbev_mmotion(motion, 0); - if(init_tunnel(xsz, ysz) == -1) { + 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; } @@ -58,7 +81,8 @@ static void keyboard(int key, int pressed, void *cls) case 27: case 'q': case 'Q': - exit(0); + quit = 1; + break; } }