# HG changeset patch # User John Tsiombikas # Date 1361328903 -7200 # Node ID 5f99c4c7a9fe76f3ceeb478eddc3ea0ef8be567f # Parent 1120c069eb1758fd34dfb72e232dec70624b550d now it looks pretty much ok diff -r 1120c069eb17 -r 5f99c4c7a9fe demoscript --- a/demoscript Tue Feb 19 23:46:44 2013 +0200 +++ b/demoscript Wed Feb 20 04:55:03 2013 +0200 @@ -1,1 +1,6 @@ -0 10000 demo +0 1000000 dummy + +100 1500 fade_in +1000 6000 mball_rise + + diff -r 1120c069eb17 -r 5f99c4c7a9fe libs/dsys2/dsys.c --- a/libs/dsys2/dsys.c Tue Feb 19 23:46:44 2013 +0200 +++ b/libs/dsys2/dsys.c Wed Feb 20 04:55:03 2013 +0200 @@ -357,6 +357,11 @@ return 0; } +void dsys_set_event_eval(struct dsys_event *ev, float (*eval)(struct dsys_event*, demotime_t)) +{ + ev->eval = eval; +} + enum dsys_evtype dsys_event_type(struct dsys_event *ev) { return ev->type; diff -r 1120c069eb17 -r 5f99c4c7a9fe libs/dsys2/dsys.h --- a/libs/dsys2/dsys.h Tue Feb 19 23:46:44 2013 +0200 +++ b/libs/dsys2/dsys.h Wed Feb 20 04:55:03 2013 +0200 @@ -45,6 +45,8 @@ /* events */ struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name); +void dsys_set_event_eval(struct dsys_event *ev, float (*eval)(struct dsys_event*, demotime_t)); + enum dsys_evtype dsys_event_type(struct dsys_event *ev); float dsys_event_value(struct dsys_event *ev); diff -r 1120c069eb17 -r 5f99c4c7a9fe sdr/dither.p.glsl --- a/sdr/dither.p.glsl Tue Feb 19 23:46:44 2013 +0200 +++ b/sdr/dither.p.glsl Wed Feb 20 04:55:03 2013 +0200 @@ -1,11 +1,23 @@ uniform sampler2D framebuf, dither_tex; uniform int dither_levels, dither_size; +uniform float tfadein; + +vec4 fetch_pixel(vec2 texcoord) +{ + float x = step(0.5, mod(texcoord.y, 0.5) / 0.5); + float offs = mix(1.0 - tfadein, tfadein - 1.0, x); + vec2 tc = texcoord + vec2(offs, 0.0); + + return (1.0 - step(1.0, tc.x)) * step(0.0, tc.x) * texture2D(framebuf, tc); +} + void main() { float levels = float(dither_levels); - vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy); + //vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy); + vec4 pixel = fetch_pixel(gl_TexCoord[0].xy); float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722)); float coord_shift = floor(lum * levels) / levels; diff -r 1120c069eb17 -r 5f99c4c7a9fe src/mballs.cc --- a/src/mballs.cc Tue Feb 19 23:46:44 2013 +0200 +++ b/src/mballs.cc Wed Feb 20 04:55:03 2013 +0200 @@ -4,6 +4,7 @@ #include "metasurf.h" #include "vmath/vmath.h" #include "dsys.h" +#include "udg.h" struct MetaBall { Vector3 pos; @@ -26,6 +27,8 @@ static struct metasurface *msurf; static float floor_height = -0.95; +static struct dsys_event *evrise; + bool mball_init() { static const float bbmin = -VOL_SZ / 2.0; @@ -49,6 +52,9 @@ balls.push_back(mb); } + evrise = dsys_event(demo, "mball_rise"); + dsys_set_event_eval(evrise, dsys_eval_sigmoid); + return true; } @@ -117,11 +123,13 @@ static void update(float sec) { + float trise = dsys_event_value(evrise); + for(size_t i=0; i #include +#include #include #include #include "opengl.h" +#include "udg.h" #include "sdr.h" #include "dither_matrix.h" #include "scroller.h" #include "mballs.h" #include "dsys.h" +#include "post.h" #define DITHER_SZ 8 #define DITHER_LEVELS 16 @@ -35,6 +38,7 @@ void motion(int x, int y); struct render_target *create_rtarg(int xsz, int ysz); void destroy_rtarg(struct render_target *rt); +bool parse_args(int argc, char **argv); int xsz, ysz; float cam_theta, cam_phi = 25, cam_dist = 11; @@ -46,12 +50,17 @@ bool opt_autorot = true; struct dsys_demo *demo; - +struct dsys_event *evfadein; int main(int argc, char **argv) { + glutInitWindowSize(1024, 768); glutInit(&argc, argv); - glutInitWindowSize(1024, 768); + + if(!parse_args(argc, argv)) { + return 1; + } + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("DBF UDG compo entry by Nuclear"); @@ -74,6 +83,13 @@ bool init() { + if(!(demo = dsys_open("demoscript"))) { + return false; + } + evfadein = dsys_event(demo, "fade_in"); + dsys_set_event_eval(evfadein, dsys_eval_sigmoid); + + // dump the tile image FILE *fp = fopen("udg.ppm", "wb"); if(fp) { fprintf(fp, "P6\n%d %d\n255\n", DITHER_SZ, DITHER_SZ * DITHER_LEVELS); @@ -130,10 +146,6 @@ return false; } - if(!(demo = dsys_open("demoscript"))) { - return false; - } - glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); @@ -141,7 +153,7 @@ glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); - dsys_start(demo); + //dsys_start(demo); return true; } @@ -238,6 +250,14 @@ mball_render(sec); bind_program(0); + float tfadein = evfadein ? dsys_event_value(evfadein) : 1.0; + /*if(tfadein < 1.0) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + overlay(0, 0, 0, 1.0 - tfadein); + glDisable(GL_BLEND); + }*/ + if(!opt_regular_render) { glBindFramebufferEXT(GL_FRAMEBUFFER, 0); @@ -245,21 +265,12 @@ glClear(GL_COLOR_BUFFER_BIT); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glPushMatrix(); - - glPushAttrib(GL_ENABLE_BIT); - glDisable(GL_DEPTH_TEST); - bind_program(post_prog); set_uniform_int(post_prog, "framebuf", 0); set_uniform_int(post_prog, "dither_tex", 1); set_uniform_int(post_prog, "dither_levels", DITHER_LEVELS); set_uniform_int(post_prog, "dither_size", DITHER_SZ); + set_uniform_float(post_prog, "tfadein", tfadein); glActiveTextureARB(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, rtarg->color_tex); @@ -268,13 +279,7 @@ glBindTexture(GL_TEXTURE_2D, dither_tex); glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); - glColor3f(0, 1, 0); - glTexCoord2f(0, 0); glVertex2f(-1, -1); - glTexCoord2f(1, 0); glVertex2f(1, -1); - glTexCoord2f(1, 1); glVertex2f(1, 1); - glTexCoord2f(0, 1); glVertex2f(-1, 1); - glEnd(); + overlay(1, 1, 1, 1); glActiveTextureARB(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); @@ -282,13 +287,6 @@ glDisable(GL_TEXTURE_2D); bind_program(0); - - glPopAttrib(); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); } glutSwapBuffers(); @@ -439,3 +437,18 @@ glDeleteRenderbuffersEXT(1, &rt->depth_buf); delete rt; } + +bool parse_args(int argc, char **argv) +{ + for(int i=1; i