dbf-udg

changeset 11:5f99c4c7a9fe

now it looks pretty much ok
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Feb 2013 04:55:03 +0200
parents 1120c069eb17
children 1abbed71e9c9
files demoscript libs/dsys2/dsys.c libs/dsys2/dsys.h sdr/dither.p.glsl src/mballs.cc src/post.cc src/post.h src/udg.cc src/udg.h
diffstat 9 files changed, 123 insertions(+), 34 deletions(-) [+]
line diff
     1.1 --- a/demoscript	Tue Feb 19 23:46:44 2013 +0200
     1.2 +++ b/demoscript	Wed Feb 20 04:55:03 2013 +0200
     1.3 @@ -1,1 +1,6 @@
     1.4 -0 10000 demo
     1.5 +0 1000000 dummy
     1.6 +
     1.7 +100 1500 fade_in
     1.8 +1000 6000 mball_rise
     1.9 +
    1.10 +
     2.1 --- a/libs/dsys2/dsys.c	Tue Feb 19 23:46:44 2013 +0200
     2.2 +++ b/libs/dsys2/dsys.c	Wed Feb 20 04:55:03 2013 +0200
     2.3 @@ -357,6 +357,11 @@
     2.4  	return 0;
     2.5  }
     2.6  
     2.7 +void dsys_set_event_eval(struct dsys_event *ev, float (*eval)(struct dsys_event*, demotime_t))
     2.8 +{
     2.9 +	ev->eval = eval;
    2.10 +}
    2.11 +
    2.12  enum dsys_evtype dsys_event_type(struct dsys_event *ev)
    2.13  {
    2.14  	return ev->type;
     3.1 --- a/libs/dsys2/dsys.h	Tue Feb 19 23:46:44 2013 +0200
     3.2 +++ b/libs/dsys2/dsys.h	Wed Feb 20 04:55:03 2013 +0200
     3.3 @@ -45,6 +45,8 @@
     3.4  /* events */
     3.5  struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name);
     3.6  
     3.7 +void dsys_set_event_eval(struct dsys_event *ev, float (*eval)(struct dsys_event*, demotime_t));
     3.8 +
     3.9  enum dsys_evtype dsys_event_type(struct dsys_event *ev);
    3.10  float dsys_event_value(struct dsys_event *ev);
    3.11  
     4.1 --- a/sdr/dither.p.glsl	Tue Feb 19 23:46:44 2013 +0200
     4.2 +++ b/sdr/dither.p.glsl	Wed Feb 20 04:55:03 2013 +0200
     4.3 @@ -1,11 +1,23 @@
     4.4  uniform sampler2D framebuf, dither_tex;
     4.5  uniform int dither_levels, dither_size;
     4.6  
     4.7 +uniform float tfadein;
     4.8 +
     4.9 +vec4 fetch_pixel(vec2 texcoord)
    4.10 +{
    4.11 +	float x = step(0.5, mod(texcoord.y, 0.5) / 0.5);
    4.12 +	float offs = mix(1.0 - tfadein, tfadein - 1.0, x);
    4.13 +	vec2 tc = texcoord + vec2(offs, 0.0);
    4.14 +
    4.15 +	return (1.0 - step(1.0, tc.x)) * step(0.0, tc.x) * texture2D(framebuf, tc);
    4.16 +}
    4.17 +
    4.18  void main()
    4.19  {
    4.20  	float levels = float(dither_levels);
    4.21  
    4.22 -	vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
    4.23 +	//vec4 pixel = texture2D(framebuf, gl_TexCoord[0].xy);
    4.24 +	vec4 pixel = fetch_pixel(gl_TexCoord[0].xy);
    4.25  	float lum = dot(pixel.xyz, vec3(0.2126, 0.7152, 0.0722));
    4.26  	float coord_shift = floor(lum * levels) / levels;
    4.27  
     5.1 --- a/src/mballs.cc	Tue Feb 19 23:46:44 2013 +0200
     5.2 +++ b/src/mballs.cc	Wed Feb 20 04:55:03 2013 +0200
     5.3 @@ -4,6 +4,7 @@
     5.4  #include "metasurf.h"
     5.5  #include "vmath/vmath.h"
     5.6  #include "dsys.h"
     5.7 +#include "udg.h"
     5.8  
     5.9  struct MetaBall {
    5.10  	Vector3 pos;
    5.11 @@ -26,6 +27,8 @@
    5.12  static struct metasurface *msurf;
    5.13  static float floor_height = -0.95;
    5.14  
    5.15 +static struct dsys_event *evrise;
    5.16 +
    5.17  bool mball_init()
    5.18  {
    5.19  	static const float bbmin = -VOL_SZ / 2.0;
    5.20 @@ -49,6 +52,9 @@
    5.21  		balls.push_back(mb);
    5.22  	}
    5.23  
    5.24 +	evrise = dsys_event(demo, "mball_rise");
    5.25 +	dsys_set_event_eval(evrise, dsys_eval_sigmoid);
    5.26 +
    5.27  	return true;
    5.28  }
    5.29  
    5.30 @@ -117,11 +123,13 @@
    5.31  
    5.32  static void update(float sec)
    5.33  {
    5.34 +	float trise = dsys_event_value(evrise);
    5.35 +
    5.36  	for(size_t i=0; i<balls.size(); i++) {
    5.37  		float t = sec + balls[i].phase_offs;
    5.38  		balls[i].pos.x = cos(t * 1.8) * balls[i].orbit;
    5.39  		balls[i].pos.z = sin(t * 1.2) * balls[i].orbit;
    5.40 -		balls[i].pos.y = (sin(t) + cos(t * 2.0) / 2.0 + sin(t * 3.0) / 3.0) * 0.45;
    5.41 +		balls[i].pos.y = (sin(t) + cos(t * 2.0) / 2.0 + sin(t * 3.0) / 3.0) * 0.45 - (2.0 - trise * 2.0);
    5.42  	}
    5.43  
    5.44  	for(int i=0; i<MBALL_GRID_SZ; i++) {
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/post.cc	Wed Feb 20 04:55:03 2013 +0200
     6.3 @@ -0,0 +1,30 @@
     6.4 +#include "opengl.h"
     6.5 +#include "post.h"
     6.6 +
     6.7 +void overlay(float r, float g, float b, float a)
     6.8 +{
     6.9 +	glPushAttrib(GL_ENABLE_BIT);
    6.10 +	glDisable(GL_DEPTH_TEST);
    6.11 +	glDisable(GL_LIGHTING);
    6.12 +
    6.13 +	glMatrixMode(GL_MODELVIEW);
    6.14 +	glPushMatrix();
    6.15 +	glLoadIdentity();
    6.16 +	glMatrixMode(GL_PROJECTION);
    6.17 +	glPushMatrix();
    6.18 +	glLoadIdentity();
    6.19 +
    6.20 +	glBegin(GL_QUADS);
    6.21 +	glColor4f(r, g, b, a);
    6.22 +	glTexCoord2f(0, 0); glVertex2f(-1, -1);
    6.23 +	glTexCoord2f(1, 0); glVertex2f(1, -1);
    6.24 +	glTexCoord2f(1, 1); glVertex2f(1, 1);
    6.25 +	glTexCoord2f(0, 1); glVertex2f(-1, 1);
    6.26 +	glEnd();
    6.27 +
    6.28 +	glPopMatrix();
    6.29 +	glMatrixMode(GL_MODELVIEW);
    6.30 +	glPopMatrix();
    6.31 +
    6.32 +	glPopAttrib();
    6.33 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/post.h	Wed Feb 20 04:55:03 2013 +0200
     7.3 @@ -0,0 +1,6 @@
     7.4 +#ifndef POST_H_
     7.5 +#define POST_H_
     7.6 +
     7.7 +void overlay(float r, float g, float b, float a);
     7.8 +
     7.9 +#endif	// POST_H_
     8.1 --- a/src/udg.cc	Tue Feb 19 23:46:44 2013 +0200
     8.2 +++ b/src/udg.cc	Wed Feb 20 04:55:03 2013 +0200
     8.3 @@ -1,13 +1,16 @@
     8.4  #include <stdio.h>
     8.5  #include <stdlib.h>
     8.6 +#include <string.h>
     8.7  #include <math.h>
     8.8  #include <assert.h>
     8.9  #include "opengl.h"
    8.10 +#include "udg.h"
    8.11  #include "sdr.h"
    8.12  #include "dither_matrix.h"
    8.13  #include "scroller.h"
    8.14  #include "mballs.h"
    8.15  #include "dsys.h"
    8.16 +#include "post.h"
    8.17  
    8.18  #define DITHER_SZ		8
    8.19  #define DITHER_LEVELS	16
    8.20 @@ -35,6 +38,7 @@
    8.21  void motion(int x, int y);
    8.22  struct render_target *create_rtarg(int xsz, int ysz);
    8.23  void destroy_rtarg(struct render_target *rt);
    8.24 +bool parse_args(int argc, char **argv);
    8.25  
    8.26  int xsz, ysz;
    8.27  float cam_theta, cam_phi = 25, cam_dist = 11;
    8.28 @@ -46,12 +50,17 @@
    8.29  bool opt_autorot = true;
    8.30  
    8.31  struct dsys_demo *demo;
    8.32 -
    8.33 +struct dsys_event *evfadein;
    8.34  
    8.35  int main(int argc, char **argv)
    8.36  {
    8.37 +	glutInitWindowSize(1024, 768);
    8.38  	glutInit(&argc, argv);
    8.39 -	glutInitWindowSize(1024, 768);
    8.40 +
    8.41 +	if(!parse_args(argc, argv)) {
    8.42 +		return 1;
    8.43 +	}
    8.44 +
    8.45  	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    8.46  	glutCreateWindow("DBF UDG compo entry by Nuclear");
    8.47  
    8.48 @@ -74,6 +83,13 @@
    8.49  
    8.50  bool init()
    8.51  {
    8.52 +	if(!(demo = dsys_open("demoscript"))) {
    8.53 +		return false;
    8.54 +	}
    8.55 +	evfadein = dsys_event(demo, "fade_in");
    8.56 +	dsys_set_event_eval(evfadein, dsys_eval_sigmoid);
    8.57 +
    8.58 +	// dump the tile image
    8.59  	FILE *fp = fopen("udg.ppm", "wb");
    8.60  	if(fp) {
    8.61  		fprintf(fp, "P6\n%d %d\n255\n", DITHER_SZ, DITHER_SZ * DITHER_LEVELS);
    8.62 @@ -130,10 +146,6 @@
    8.63  		return false;
    8.64  	}
    8.65  
    8.66 -	if(!(demo = dsys_open("demoscript"))) {
    8.67 -		return false;
    8.68 -	}
    8.69 -
    8.70  	glEnable(GL_CULL_FACE);
    8.71  	glEnable(GL_DEPTH_TEST);
    8.72  	glEnable(GL_LIGHTING);
    8.73 @@ -141,7 +153,7 @@
    8.74  	glEnable(GL_LIGHT1);
    8.75  	glEnable(GL_NORMALIZE);
    8.76  
    8.77 -	dsys_start(demo);
    8.78 +	//dsys_start(demo);
    8.79  
    8.80  	return true;
    8.81  }
    8.82 @@ -238,6 +250,14 @@
    8.83  	mball_render(sec);
    8.84  	bind_program(0);
    8.85  
    8.86 +	float tfadein = evfadein ? dsys_event_value(evfadein) : 1.0;
    8.87 +	/*if(tfadein < 1.0) {
    8.88 +		glEnable(GL_BLEND);
    8.89 +		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    8.90 +		overlay(0, 0, 0, 1.0 - tfadein);
    8.91 +		glDisable(GL_BLEND);
    8.92 +	}*/
    8.93 +
    8.94  
    8.95  	if(!opt_regular_render) {
    8.96  		glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    8.97 @@ -245,21 +265,12 @@
    8.98  
    8.99  		glClear(GL_COLOR_BUFFER_BIT);
   8.100  
   8.101 -		glMatrixMode(GL_PROJECTION);
   8.102 -		glPushMatrix();
   8.103 -		glLoadIdentity();
   8.104 -		glMatrixMode(GL_MODELVIEW);
   8.105 -		glLoadIdentity();
   8.106 -		glPushMatrix();
   8.107 -
   8.108 -		glPushAttrib(GL_ENABLE_BIT);
   8.109 -		glDisable(GL_DEPTH_TEST);
   8.110 -
   8.111  		bind_program(post_prog);
   8.112  		set_uniform_int(post_prog, "framebuf", 0);
   8.113  		set_uniform_int(post_prog, "dither_tex", 1);
   8.114  		set_uniform_int(post_prog, "dither_levels", DITHER_LEVELS);
   8.115  		set_uniform_int(post_prog, "dither_size", DITHER_SZ);
   8.116 +		set_uniform_float(post_prog, "tfadein", tfadein);
   8.117  
   8.118  		glActiveTextureARB(GL_TEXTURE0);
   8.119  		glBindTexture(GL_TEXTURE_2D, rtarg->color_tex);
   8.120 @@ -268,13 +279,7 @@
   8.121  		glBindTexture(GL_TEXTURE_2D, dither_tex);
   8.122  		glEnable(GL_TEXTURE_2D);
   8.123  
   8.124 -		glBegin(GL_QUADS);
   8.125 -		glColor3f(0, 1, 0);
   8.126 -		glTexCoord2f(0, 0); glVertex2f(-1, -1);
   8.127 -		glTexCoord2f(1, 0); glVertex2f(1, -1);
   8.128 -		glTexCoord2f(1, 1); glVertex2f(1, 1);
   8.129 -		glTexCoord2f(0, 1); glVertex2f(-1, 1);
   8.130 -		glEnd();
   8.131 +		overlay(1, 1, 1, 1);
   8.132  
   8.133  		glActiveTextureARB(GL_TEXTURE1);
   8.134  		glDisable(GL_TEXTURE_2D);
   8.135 @@ -282,13 +287,6 @@
   8.136  		glDisable(GL_TEXTURE_2D);
   8.137  
   8.138  		bind_program(0);
   8.139 -
   8.140 -		glPopAttrib();
   8.141 -
   8.142 -		glMatrixMode(GL_PROJECTION);
   8.143 -		glPopMatrix();
   8.144 -		glMatrixMode(GL_MODELVIEW);
   8.145 -		glPopMatrix();
   8.146  	}
   8.147  
   8.148  	glutSwapBuffers();
   8.149 @@ -439,3 +437,18 @@
   8.150  	glDeleteRenderbuffersEXT(1, &rt->depth_buf);
   8.151  	delete rt;
   8.152  }
   8.153 +
   8.154 +bool parse_args(int argc, char **argv)
   8.155 +{
   8.156 +	for(int i=1; i<argc; i++) {
   8.157 +		if(strcmp(argv[i], "-noblock") == 0) {
   8.158 +			opt_highres = true;
   8.159 +		} else if(strcmp(argv[i], "-nodither") == 0) {
   8.160 +			opt_regular_render = true;
   8.161 +		} else {
   8.162 +			fprintf(stderr, "invalid argument: %s\n", argv[i]);
   8.163 +			return false;
   8.164 +		}
   8.165 +	}
   8.166 +	return true;
   8.167 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/udg.h	Wed Feb 20 04:55:03 2013 +0200
     9.3 @@ -0,0 +1,8 @@
     9.4 +#ifndef UDG_H_
     9.5 +#define UDG_H_
     9.6 +
     9.7 +#include "dsys.h"
     9.8 +
     9.9 +extern struct dsys_demo *demo;
    9.10 +
    9.11 +#endif	// UDG_H_