X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdemo.c;h=f51dcc1b6fe13301bf327e7ebd71669a5bfec0bc;hb=628ef3345462458f2fb6be034583e61238b89f89;hp=4ab00f3f4f30401c7e628bef92df1957779d9ffa;hpb=aa9f7c423c8c4111b3e1d0a7bbe73e376533ed80;p=andemo diff --git a/src/demo.c b/src/demo.c index 4ab00f3..f51dcc1 100644 --- a/src/demo.c +++ b/src/demo.c @@ -1,34 +1,167 @@ +#include #include "demo.h" #include "opengl.h" +#include "sanegl.h" +#include "assman.h" +#include "demosys.h" + +static unsigned int sdr_foo; +static unsigned int tex_logo; int demo_init(void) { - glClearColor(1, 0, 0, 1); + if(init_opengl() == -1) { + return -1; + } + + if(!(sdr_foo = get_sdrprog("sdr/foo.v.glsl", "sdr/foo.p.glsl"))) { + return -1; + } + if(!(tex_logo = get_tex2d("data/ml_logo_old.png"))) { + return -1; + } + glBindTexture(GL_TEXTURE_2D, tex_logo); + glUseProgram(sdr_foo); + gl_begin(GL_QUADS); + gl_texcoord2f(0, 1); + gl_vertex2f(-1, -1); + gl_texcoord2f(1, 1); + gl_vertex2f(1, -1); + gl_texcoord2f(1, 0); + gl_vertex2f(1, 1); + gl_texcoord2f(0, 0); + gl_vertex2f(-1, 1); + gl_end(); + swap_buffers(); + + if(dsys_init("data/demoscript") == -1) { + return -1; + } + if(opt.scrname) { + struct demoscreen *scr = dsys_find_screen(opt.scrname); + if(scr) { + dsys_run_screen(scr); + } else { + fprintf(stderr, "ignoring screen option, no such screen: %s\n", opt.scrname); + } + } + return 0; } void demo_cleanup(void) { + dsys_destroy(); } void demo_display(void) { - glClear(GL_COLOR_BUFFER_BIT); + dsys_update(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glBindTexture(GL_TEXTURE_2D, tex_logo); + glUseProgram(sdr_foo); + gl_begin(GL_QUADS); + gl_color4f(1, 1, 1, dsys_value("flashlogo")); + gl_texcoord2f(0, 1); + gl_vertex2f(-1, -1); + gl_texcoord2f(1, 1); + gl_vertex2f(1, -1); + gl_texcoord2f(1, 0); + gl_vertex2f(1, 1); + gl_texcoord2f(0, 0); + gl_vertex2f(-1, 1); + gl_end(); + glDisable(GL_BLEND); + + dsys_draw(); } void demo_reshape(int x, int y) { + int i; + glViewport(0, 0, x, y); + + for(i=0; ireshape) { + dsys.screens[i]->reshape(x, y); + } + } } void demo_keyboard(int key, int pressed) { + if(!pressed) return; + + switch(key) { + case ' ': + if(dsys.running) { + dsys_stop(); + } else { + dsys_run(); + } + break; + + case '\b': + dsys_seek_abs(0); + break; + + default: + if(key >= '0' && key <= '9') { + dsys_seek_rel((float)(key - '0') / 9.0f); + + } else if(key >= KEY_F1 && key <= KEY_F12) { + int idx = key - KEY_F1; + if(idx < dsys.num_screens) { + dsys_run_screen(dsys.screens[idx]); + } + + } else { + int i; + + if(dsys.scr_override && dsys.scr_override->keyboard) { + dsys.scr_override->keyboard(key, pressed); + break; + } + + for(i=0; ikeyboard) scr->keyboard(key, pressed); + } + } + } } void demo_mouse(int bn, int pressed, int x, int y) { + int i; + + if(dsys.scr_override && dsys.scr_override->mouse) { + dsys.scr_override->mouse(bn, pressed, x, y); + return; + } + + for(i=0; imouse) scr->mouse(bn, pressed, x, y); + } } void demo_motion(int x, int y) { + int i; + + if(dsys.scr_override && dsys.scr_override->motion) { + dsys.scr_override->motion(x, y); + } + + for(i=0; imotion) scr->motion(x, y); + } }