fixed walk polygon rendering
[laserbrain_demo] / src / app.cc
index 096bf4e..4fd3690 100644 (file)
@@ -25,6 +25,8 @@ float win_aspect;
 bool fb_srgb;
 bool opt_gear_wireframe;
 
+unsigned int sdr_ltmap, sdr_ltmap_notex;
+
 static float cam_dist = 0.0;
 static float cam_theta, cam_phi = 20;
 static Vec3 cam_pos;
@@ -32,6 +34,7 @@ static float floor_y; // last floor height
 static float user_eye_height = 165;
 
 static float walk_speed = 300.0f;
+static float mouse_speed = 1.0f;
 static bool show_walk_mesh, noclip = false;
 
 static bool have_headtracking, should_swap;
@@ -43,7 +46,7 @@ static bool keystate[256];
 static Mat4 view_matrix, mouse_view_matrix, proj_matrix;
 static TextureSet texman;
 static Scene *scn;
-static unsigned int sdr, sdr_post_gamma;
+static unsigned int sdr_post_gamma;
 
 static long prev_msec;
 
@@ -105,12 +108,15 @@ bool app_init(int argc, char **argv)
                cam_pos = bcent + Vec3(0, user_eye_height, 0);
        }
 
-       if(!(sdr = create_program_load("sdr/test.v.glsl", "sdr/test.p.glsl"))) {
-               fprintf(stderr, "failed to load test shaders\n");
+       if(!(sdr_ltmap_notex = create_program_load("sdr/lightmap.v.glsl", "sdr/lightmap-notex.p.glsl"))) {
                return false;
        }
-       set_uniform_int(sdr, "texmap", 0);
-       set_uniform_int(sdr, "lightmap", 1);
+
+       if(!(sdr_ltmap = create_program_load("sdr/lightmap.v.glsl", "sdr/lightmap-tex.p.glsl"))) {
+               return false;
+       }
+       set_uniform_int(sdr_ltmap, "texmap", 0);
+       set_uniform_int(sdr_ltmap, "lightmap", 1);
 
        if(!fb_srgb) {
                sdr_post_gamma = create_program_load("sdr/post_gamma.v.glsl", "sdr/post_gamma.p.glsl");
@@ -294,9 +300,7 @@ static void draw_scene()
        set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6);
        set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3);
 
-       glUseProgram(sdr);
        scn->draw();
-       glUseProgram(0);
 
        if(show_walk_mesh && scn->walk_mesh) {
                glPushAttrib(GL_ENABLE_BIT);
@@ -305,6 +309,8 @@ static void draw_scene()
                glDisable(GL_LIGHTING);
                glEnable(GL_POLYGON_OFFSET_FILL);
 
+               glUseProgram(0);
+
                glPolygonOffset(-1, 1);
                glDepthMask(0);
 
@@ -336,8 +342,11 @@ void app_keyboard(int key, bool pressed)
                        app_quit();
                        break;
 
-               case 'f':
-                       app_toggle_fullscreen();
+               case '\n':
+               case '\r':
+                       if(mod & MOD_ALT) {
+                               app_toggle_fullscreen();
+                       }
                        break;
 
                case '`':
@@ -359,6 +368,23 @@ void app_keyboard(int key, bool pressed)
                        }
                        break;
 
+               case 'f':
+                       {
+                               static float prev_walk_speed = -1.0;
+                               if(prev_walk_speed < 0.0) {
+                                       noclip = true;
+                                       prev_walk_speed = walk_speed;
+                                       walk_speed = 1000.0;
+                                       show_message("fly mode\n");
+                               } else {
+                                       noclip = false;
+                                       walk_speed = prev_walk_speed;
+                                       prev_walk_speed = -1.0;
+                                       show_message("walk mode\n");
+                               }
+                       }
+                       break;
+
                case 'p':
                        if(mod & MOD_CTRL) {
                                fb_srgb = !fb_srgb;
@@ -375,6 +401,16 @@ void app_keyboard(int key, bool pressed)
                        walk_speed *= 0.75;
                        show_message("walk speed: %g", walk_speed);
                        break;
+
+               case ']':
+                       mouse_speed *= 1.2;
+                       show_message("mouse speed: %g", mouse_speed);
+                       break;
+
+               case '[':
+                       mouse_speed *= 0.8;
+                       show_message("mouse speed: %g", mouse_speed);
+                       break;
                }
        }
 
@@ -426,8 +462,8 @@ void app_mouse_motion(int x, int y)
 void app_mouse_delta(int dx, int dy)
 {
        if(bnstate[2]) {
-               mouse_zoom(dx, dy);
+               mouse_zoom(dx * mouse_speed, dy * mouse_speed);
        } else {
-               mouse_look(dx, dy);
+               mouse_look(dx * mouse_speed, dy * mouse_speed);
        }
 }