dbf-udg
diff src/udg.cc @ 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 |
line diff
1.1 --- a/src/udg.cc Tue Feb 19 23:46:44 2013 +0200 1.2 +++ b/src/udg.cc Wed Feb 20 04:55:03 2013 +0200 1.3 @@ -1,13 +1,16 @@ 1.4 #include <stdio.h> 1.5 #include <stdlib.h> 1.6 +#include <string.h> 1.7 #include <math.h> 1.8 #include <assert.h> 1.9 #include "opengl.h" 1.10 +#include "udg.h" 1.11 #include "sdr.h" 1.12 #include "dither_matrix.h" 1.13 #include "scroller.h" 1.14 #include "mballs.h" 1.15 #include "dsys.h" 1.16 +#include "post.h" 1.17 1.18 #define DITHER_SZ 8 1.19 #define DITHER_LEVELS 16 1.20 @@ -35,6 +38,7 @@ 1.21 void motion(int x, int y); 1.22 struct render_target *create_rtarg(int xsz, int ysz); 1.23 void destroy_rtarg(struct render_target *rt); 1.24 +bool parse_args(int argc, char **argv); 1.25 1.26 int xsz, ysz; 1.27 float cam_theta, cam_phi = 25, cam_dist = 11; 1.28 @@ -46,12 +50,17 @@ 1.29 bool opt_autorot = true; 1.30 1.31 struct dsys_demo *demo; 1.32 - 1.33 +struct dsys_event *evfadein; 1.34 1.35 int main(int argc, char **argv) 1.36 { 1.37 + glutInitWindowSize(1024, 768); 1.38 glutInit(&argc, argv); 1.39 - glutInitWindowSize(1024, 768); 1.40 + 1.41 + if(!parse_args(argc, argv)) { 1.42 + return 1; 1.43 + } 1.44 + 1.45 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); 1.46 glutCreateWindow("DBF UDG compo entry by Nuclear"); 1.47 1.48 @@ -74,6 +83,13 @@ 1.49 1.50 bool init() 1.51 { 1.52 + if(!(demo = dsys_open("demoscript"))) { 1.53 + return false; 1.54 + } 1.55 + evfadein = dsys_event(demo, "fade_in"); 1.56 + dsys_set_event_eval(evfadein, dsys_eval_sigmoid); 1.57 + 1.58 + // dump the tile image 1.59 FILE *fp = fopen("udg.ppm", "wb"); 1.60 if(fp) { 1.61 fprintf(fp, "P6\n%d %d\n255\n", DITHER_SZ, DITHER_SZ * DITHER_LEVELS); 1.62 @@ -130,10 +146,6 @@ 1.63 return false; 1.64 } 1.65 1.66 - if(!(demo = dsys_open("demoscript"))) { 1.67 - return false; 1.68 - } 1.69 - 1.70 glEnable(GL_CULL_FACE); 1.71 glEnable(GL_DEPTH_TEST); 1.72 glEnable(GL_LIGHTING); 1.73 @@ -141,7 +153,7 @@ 1.74 glEnable(GL_LIGHT1); 1.75 glEnable(GL_NORMALIZE); 1.76 1.77 - dsys_start(demo); 1.78 + //dsys_start(demo); 1.79 1.80 return true; 1.81 } 1.82 @@ -238,6 +250,14 @@ 1.83 mball_render(sec); 1.84 bind_program(0); 1.85 1.86 + float tfadein = evfadein ? dsys_event_value(evfadein) : 1.0; 1.87 + /*if(tfadein < 1.0) { 1.88 + glEnable(GL_BLEND); 1.89 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1.90 + overlay(0, 0, 0, 1.0 - tfadein); 1.91 + glDisable(GL_BLEND); 1.92 + }*/ 1.93 + 1.94 1.95 if(!opt_regular_render) { 1.96 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 1.97 @@ -245,21 +265,12 @@ 1.98 1.99 glClear(GL_COLOR_BUFFER_BIT); 1.100 1.101 - glMatrixMode(GL_PROJECTION); 1.102 - glPushMatrix(); 1.103 - glLoadIdentity(); 1.104 - glMatrixMode(GL_MODELVIEW); 1.105 - glLoadIdentity(); 1.106 - glPushMatrix(); 1.107 - 1.108 - glPushAttrib(GL_ENABLE_BIT); 1.109 - glDisable(GL_DEPTH_TEST); 1.110 - 1.111 bind_program(post_prog); 1.112 set_uniform_int(post_prog, "framebuf", 0); 1.113 set_uniform_int(post_prog, "dither_tex", 1); 1.114 set_uniform_int(post_prog, "dither_levels", DITHER_LEVELS); 1.115 set_uniform_int(post_prog, "dither_size", DITHER_SZ); 1.116 + set_uniform_float(post_prog, "tfadein", tfadein); 1.117 1.118 glActiveTextureARB(GL_TEXTURE0); 1.119 glBindTexture(GL_TEXTURE_2D, rtarg->color_tex); 1.120 @@ -268,13 +279,7 @@ 1.121 glBindTexture(GL_TEXTURE_2D, dither_tex); 1.122 glEnable(GL_TEXTURE_2D); 1.123 1.124 - glBegin(GL_QUADS); 1.125 - glColor3f(0, 1, 0); 1.126 - glTexCoord2f(0, 0); glVertex2f(-1, -1); 1.127 - glTexCoord2f(1, 0); glVertex2f(1, -1); 1.128 - glTexCoord2f(1, 1); glVertex2f(1, 1); 1.129 - glTexCoord2f(0, 1); glVertex2f(-1, 1); 1.130 - glEnd(); 1.131 + overlay(1, 1, 1, 1); 1.132 1.133 glActiveTextureARB(GL_TEXTURE1); 1.134 glDisable(GL_TEXTURE_2D); 1.135 @@ -282,13 +287,6 @@ 1.136 glDisable(GL_TEXTURE_2D); 1.137 1.138 bind_program(0); 1.139 - 1.140 - glPopAttrib(); 1.141 - 1.142 - glMatrixMode(GL_PROJECTION); 1.143 - glPopMatrix(); 1.144 - glMatrixMode(GL_MODELVIEW); 1.145 - glPopMatrix(); 1.146 } 1.147 1.148 glutSwapBuffers(); 1.149 @@ -439,3 +437,18 @@ 1.150 glDeleteRenderbuffersEXT(1, &rt->depth_buf); 1.151 delete rt; 1.152 } 1.153 + 1.154 +bool parse_args(int argc, char **argv) 1.155 +{ 1.156 + for(int i=1; i<argc; i++) { 1.157 + if(strcmp(argv[i], "-noblock") == 0) { 1.158 + opt_highres = true; 1.159 + } else if(strcmp(argv[i], "-nodither") == 0) { 1.160 + opt_regular_render = true; 1.161 + } else { 1.162 + fprintf(stderr, "invalid argument: %s\n", argv[i]); 1.163 + return false; 1.164 + } 1.165 + } 1.166 + return true; 1.167 +}