X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdemo.c;h=a4bb0c70fd8f7462638b11c90f6343ddcaeb2942;hb=5eefe7b94c8d6c6caa2c10e3835ab0831a3c42a1;hp=8653aa477626d771a783e7c508cd143725bd85d1;hpb=646e75fcb6bdb93c853f6706c23d809c2c63415c;p=demo_prior diff --git a/src/demo.c b/src/demo.c index 8653aa4..a4bb0c7 100644 --- a/src/demo.c +++ b/src/demo.c @@ -1,69 +1,156 @@ +#include #include "opengl.h" #include "demo.h" +#include "part.h" +#include "post.h" +#include "sdr.h" +#include "opt.h" + +void reg_whitted(void); int win_width, win_height; +float win_aspect; long time_msec; +static int reshape_pending; +static unsigned int sdr_gamma; int demo_init(void) { + int i; + if(init_opengl() == -1) { return -1; } glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glEnable(GL_FRAMEBUFFER_SRGB); - glEnable(GL_MULTISAMPLE); + if(opt.srgb) { + glEnable(GL_FRAMEBUFFER_SRGB); + } + if(opt.msaa) { + glEnable(GL_MULTISAMPLE); + } + + post_init(); + if(!(sdr_gamma = create_program_load("sdr/post.v.glsl", "sdr/gamma.p.glsl"))) { + fprintf(stderr, "Warning: failed to load the gamma correction shader\n"); + } + + reg_whitted(); + + for(i=0; iinit() == -1) { + fprintf(stderr, "part %s init failed\n", parts[i]->name); + return -1; + } + } + + switch_part(parts[0]); return 0; } void demo_cleanup(void) { + int i; + + if(sdr_gamma) { + glDeleteProgram(sdr_gamma); + } + post_cleanup(); + + for(i=0; idestroy(); + } } void demo_display(void) { - glClearColor(0.05, 0.05, 0.05, 1); + long part_time; + + if(reshape_pending) { + post_reshape(win_width, win_height); + reshape_pending = 0; + } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0, 0, -8); + if(!cur_part) return; + + part_time = time_msec - cur_part->start_time; + if(part_time < cur_part->in_time) { + float t = (float)part_time / cur_part->in_time; + + if(prev_part) { + long prev_part_time = time_msec - prev_part->start_time; + if(prev_part->draw_out) { + prev_part->draw_out(prev_part_time, t); + } else { + prev_part->draw(prev_part_time); + } + } + + if(cur_part->draw_in) { + cur_part->draw_in(part_time, t); + } else { + cur_part->draw(part_time); + } + } else { + prev_part = 0; + cur_part->draw(part_time); + } + + /* no-srgb gamma correction fallback */ + if(!opt.srgb) { + glBindTexture(GL_TEXTURE_2D, post_fbtex[0].id); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height); - glFrontFace(GL_CW); - glutSolidTeapot(1.0); - glFrontFace(GL_CCW); + glUseProgram(sdr_gamma); + overlay_tex(post_fbtex, 1.0); + } } void demo_reshape(int x, int y) { + reshape_pending = 1; + + win_width = x; + win_height = y; + win_aspect = (float)x / (float)y; + glViewport(0, 0, x, y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0); + gluPerspective(50.0, win_aspect, 0.5, 500.0); } void demo_keyboard(int key, int st) { - if(st) { - switch(key) { - case 27: - demo_quit(); - break; - } + if(st && key == 27) { + demo_quit(); + return; + } + + if(cur_part && cur_part->keyboard) { + cur_part->keyboard(key, st); } } void demo_mbutton(int bn, int st, int x, int y) { + if(cur_part && cur_part->mbutton) { + cur_part->mbutton(bn, st, x, y); + } } void demo_mmotion(int x, int y) { + if(cur_part && cur_part->mmotion) { + cur_part->mmotion(x, y); + } } void demo_sball_motion(int x, int y, int z)