dungeon_crawler
diff prototype/src/main.cc @ 41:acfe0c0110fc
- cleaned up the renderer
- implemented fallback (non-deferred renderer)
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 30 Aug 2012 05:35:00 +0300 |
parents | 060a44040577 |
children | 6d71dd4760f9 |
line diff
1.1 --- a/prototype/src/main.cc Thu Aug 30 03:05:04 2012 +0300 1.2 +++ b/prototype/src/main.cc Thu Aug 30 05:35:00 2012 +0300 1.3 @@ -8,6 +8,7 @@ 1.4 #include "datapath.h" 1.5 #include "tileset.h" 1.6 #include "renderer.h" 1.7 +#include "renderer_deferred.h" 1.8 #include "cmdcon.h" 1.9 #include "cfg.h" 1.10 #include "timer.h" 1.11 @@ -70,11 +71,15 @@ 1.12 1.13 bool init(int xsz, int ysz) 1.14 { 1.15 + // backup light for the forward crappy renderer 1.16 glEnable(GL_LIGHTING); 1.17 glEnable(GL_LIGHT0); 1.18 - float ldir[] = {-1, 1, 2, 0}; 1.19 + 1.20 + float ldir[] = {0, 0, -0.5, 1}; 1.21 glLightfv(GL_LIGHT0, GL_POSITION, ldir); 1.22 - glEnable(GL_NORMALIZE); 1.23 + float lcol[] = {1, 1, 1, 1}; 1.24 + glLightfv(GL_LIGHT0, GL_DIFFUSE, lcol); 1.25 + glLightfv(GL_LIGHT0, GL_SPECULAR, lcol); 1.26 1.27 glEnable(GL_DEPTH_TEST); 1.28 glEnable(GL_CULL_FACE); 1.29 @@ -84,8 +89,15 @@ 1.30 add_data_path("data"); 1.31 add_data_path("sdr"); 1.32 1.33 - if(!init_renderer(xsz, ysz)) { 1.34 - return false; 1.35 + rend = new DeferredRenderer(); 1.36 + if(!rend->init(xsz, ysz)) { 1.37 + printf("falling back to crappy renderer...\n"); 1.38 + 1.39 + rend = new FwdRenderer(); 1.40 + if(!rend->init(xsz, ysz)) { 1.41 + fprintf(stderr, "failed to create renderer\n"); 1.42 + return false; 1.43 + } 1.44 } 1.45 1.46 if(!init_cmdcon()) { 1.47 @@ -115,8 +127,7 @@ 1.48 { 1.49 delete level; 1.50 delete tileset; 1.51 - 1.52 - destroy_renderer(); 1.53 + delete rend; 1.54 1.55 cleanup_cmdcon(); 1.56 } 1.57 @@ -165,15 +176,13 @@ 1.58 1.59 glutSwapBuffers(); 1.60 assert(glGetError() == GL_NO_ERROR); 1.61 - 1.62 - usleep(10000); 1.63 } 1.64 1.65 void draw() 1.66 { 1.67 - glClear(GL_COLOR_BUFFER_BIT); 1.68 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.69 1.70 - render_deferred(level); 1.71 + rend->render(level); 1.72 1.73 if(show_con) { 1.74 draw_cmdcon(); 1.75 @@ -240,7 +249,7 @@ 1.76 cfg.width = x; 1.77 cfg.height = y; 1.78 1.79 - resize_renderer(x, y); 1.80 + rend->resize(x, y); 1.81 } 1.82 1.83 static bool stereo_shift_pressed;