X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=laserbrain_demo;a=blobdiff_plain;f=src%2Fapp.cc;h=a03fd34f9bb703a80ad76ea5ac86dd5555fa6007;hp=7f6f077e294268b3281719c571114d08fcbea263;hb=512acaa2427ffa2ff19079f999bc2fcd7cd33925;hpb=fb11663a3654acd0132e71e5652e35b0ea72d544 diff --git a/src/app.cc b/src/app.cc index 7f6f077..a03fd34 100644 --- a/src/app.cc +++ b/src/app.cc @@ -18,6 +18,7 @@ #include "vrinput.h" #include "exman.h" #include "blob_exhibit.h" +#include "dbg_gui.h" #define NEAR_CLIP 5.0 #define FAR_CLIP 10000.0 @@ -70,6 +71,8 @@ static bool show_blobs; static Renderer *rend; +static bool show_debug_gui; + bool app_init(int argc, char **argv) { @@ -95,11 +98,16 @@ bool app_init(int argc, char **argv) goatvr_recenter(); } - int srgb_capable; - glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &srgb_capable); - printf("Framebuffer %s sRGB-capable\n", srgb_capable ? "is" : "is not"); - fb_srgb = srgb_capable != 0; - glEnable(GL_FRAMEBUFFER_SRGB); + if(fb_srgb) { + int srgb_capable; + glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, &srgb_capable); + printf("Framebuffer %s sRGB-capable\n", srgb_capable ? "is" : "is not"); + if(srgb_capable) { + glEnable(GL_FRAMEBUFFER_SRGB); + } else { + fb_srgb = 0; + } + } glEnable(GL_MULTISAMPLE); glEnable(GL_DEPTH_TEST); @@ -107,6 +115,10 @@ bool app_init(int argc, char **argv) glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); + if(!init_debug_gui()) { + return false; + } + Mesh::use_custom_sdr_attr = false; float ambient[] = {0.0, 0.0, 0.0, 0.0}; @@ -169,7 +181,7 @@ bool app_init(int argc, char **argv) app_grab_mouse(true); } - if(mscn->music) { + if(mscn->music && opt.music) { mscn->music->play(AUDIO_PLAYMODE_LOOP); } return true; @@ -194,6 +206,8 @@ void app_cleanup() texman.clear(); sceneman.clear(); + + cleanup_debug_gui(); } static bool constrain_walk_mesh(const Vec3 &v, Vec3 *newv) @@ -333,6 +347,13 @@ void app_display() float dt = (float)(time_msec - prev_msec) / 1000.0f; prev_msec = time_msec; + if(show_debug_gui) { + ImGui::GetIOPtr()->DeltaTime = dt; + ImGui::NewFrame(); + + ImGui::ShowTestWindow(); + } + if(opt.vr) { // VR mode goatvr_draw_start(); @@ -356,6 +377,10 @@ void app_display() if(have_handtracking) { draw_vrhands(); } + + if(show_debug_gui) { + ImGui::Render(); + } } goatvr_draw_done(); @@ -382,6 +407,10 @@ void app_display() slow_post(sdr_post_gamma); glUseProgram(0); } + + if(show_debug_gui) { + ImGui::Render(); + } app_swap_buffers(); } assert(glGetError() == GL_NO_ERROR); @@ -464,12 +493,18 @@ void app_reshape(int x, int y) { glViewport(0, 0, x, y); goatvr_set_fb_size(x, y, 1.0f); + debug_gui_reshape(x, y); } void app_keyboard(int key, bool pressed) { unsigned int mod = app_get_modifiers(); + if(show_debug_gui && !(pressed && (key == '`' || key == 27))) { + debug_gui_key(key, pressed, mod); + return; // ignore all keystrokes when GUI is visible + } + if(pressed) { switch(key) { case 27: @@ -484,6 +519,11 @@ void app_keyboard(int key, bool pressed) break; case '`': + show_debug_gui = !show_debug_gui; + show_message("debug gui %s", show_debug_gui ? "enabled" : "disabled"); + break; + + case 'm': app_toggle_grab_mouse(); show_message("mouse %s", app_is_mouse_grabbed() ? "grabbed" : "released"); break; @@ -552,6 +592,11 @@ void app_keyboard(int key, bool pressed) void app_mouse_button(int bn, bool pressed, int x, int y) { + if(show_debug_gui) { + debug_gui_mbutton(bn, pressed, x, y); + return; // ignore mouse events while GUI is visible + } + prev_mx = x; prev_my = y; bnstate[bn] = pressed; @@ -575,6 +620,11 @@ static void mouse_zoom(float dx, float dy) void app_mouse_motion(int x, int y) { + if(show_debug_gui) { + debug_gui_mmotion(x, y); + return; // ignore mouse events while GUI is visible + } + int dx = x - prev_mx; int dy = y - prev_my; prev_mx = x; @@ -599,6 +649,13 @@ void app_mouse_delta(int dx, int dy) } } +void app_mouse_wheel(int dir) +{ + if(show_debug_gui) { + debug_gui_wheel(dir); + } +} + void app_gamepad_axis(int axis, float val) { switch(axis) {