From 8e783a58d1e21ace04fd6d7ed00158e65bd78040 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 12 Dec 2020 17:41:03 +0200 Subject: [PATCH] dbg gui, imtk text drawing --- Makefile | 2 +- src/demo.c | 17 +++++++++++++---- src/demo.h | 2 ++ src/imtk/draw.c | 22 +++++++++++++++------- src/imtk/imtk.h | 1 + src/imtk/layout.c | 11 +++++++++++ src/main.c | 1 + src/part_whitted.c | 35 ++++++++++++++++++++++++++++++++++- 8 files changed, 78 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 0ccf3ae..5bcb73e 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ bin = demo warn = -pedantic -Wall -g def = -DMINIGLUT_USE_LIBC -incpath = -Isrc -Ilibs/cgmath -Ilibs/glew -Ilibs/treestore/src \ +incpath = -Isrc -Isrc/imtk -Ilibs/cgmath -Ilibs/glew -Ilibs/treestore/src \ -Ilibs/imago2/src -Ilibs/drawtext/src libpath = -Llibs/glew -Llibs/treestore -Llibs/imago2 -Llibs/drawtext diff --git a/src/demo.c b/src/demo.c index f199939..a27d86c 100644 --- a/src/demo.c +++ b/src/demo.c @@ -18,6 +18,8 @@ long time_msec; struct dtx_font *fnt_ui; int fnt_ui_size; +int dbgui; + static int reshape_pending; static unsigned int sdr_gamma; @@ -139,7 +141,7 @@ void demo_display(void) dt = time_msec - prev_upd; if(dt >= 750) { - fps = (frames * 1000 << 8 + 128) / dt; + fps = ((frames * 1000 << 8) + 128) / dt; frames = 0; prev_upd = time_msec; } @@ -169,9 +171,16 @@ void demo_reshape(int x, int y) void demo_keyboard(int key, int st) { - if(st && key == 27) { - demo_quit(); - return; + if(st) { + switch(key) { + case 27: + demo_quit(); + return; + + case '`': + dbgui ^= 1; + break; + } } if(cur_part && cur_part->keyboard) { diff --git a/src/demo.h b/src/demo.h index a54f154..d15521a 100644 --- a/src/demo.h +++ b/src/demo.h @@ -8,6 +8,8 @@ extern long time_msec; extern struct dtx_font *fnt_ui; extern int fnt_ui_size; +extern int dbgui; + int demo_init(void); void demo_cleanup(void); diff --git a/src/imtk/draw.c b/src/imtk/draw.c index e1c6fbf..331eeae 100644 --- a/src/imtk/draw.c +++ b/src/imtk/draw.c @@ -3,6 +3,8 @@ #include #include "draw.h" #include "imtk.h" +#include "drawtext.h" +#include "demo.h" #define COLOR_MASK 0xff @@ -256,15 +258,21 @@ void imtk_draw_disc_frame(int x, int y, float inner, float outer, int subdiv, in void imtk_draw_string(int x, int y, const char *str) { - /* - glRasterPos2i(x, y); - while(*str) { - glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *str++); - } - */ + dtx_use_font(fnt_ui, fnt_ui_size); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glTranslatef(x, y + dtx_line_height() * 0.2, 0); + glScalef(1, -1, 1); + + glColor4fv(colors[IMTK_TEXT_COLOR]); + dtx_string(str); + + glPopMatrix(); } int imtk_string_size(const char *str) { - return 0; + dtx_use_font(fnt_ui, fnt_ui_size); + return dtx_string_width(str); } diff --git a/src/imtk/imtk.h b/src/imtk/imtk.h index 28ff5d0..e049e4b 100644 --- a/src/imtk/imtk.h +++ b/src/imtk/imtk.h @@ -85,6 +85,7 @@ void imtk_layout_advance(int width, int height); void imtk_layout_newline(void); void imtk_layout_get_pos(int *x, int *y); void imtk_layout_get_bounds(int *bbox); +int imtk_layout_contains(int x, int y); /* defined in draw.c */ void imtk_set_color(unsigned int col, float r, float g, float b, float a); diff --git a/src/imtk/layout.c b/src/imtk/layout.c index 098bf53..6bc9fe7 100644 --- a/src/imtk/layout.c +++ b/src/imtk/layout.c @@ -99,3 +99,14 @@ void imtk_layout_get_bounds(int *bbox) { memcpy(bbox, st[top].box, sizeof st[top].box); } + +int imtk_layout_contains(int x, int y) +{ + if(x < st[top].box[0] || x >= st[top].box[0] + st[top].box[2]) { + return 0; + } + if(y < st[top].box[1] || y >= st[top].box[1] + st[top].box[3]) { + return 0; + } + return 1; +} diff --git a/src/main.c b/src/main.c index a6db187..1cf9ea0 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,7 @@ int main(int argc, char **argv) glutKeyboardUpFunc(keyup); glutMouseFunc(mouse); glutMotionFunc(demo_mmotion); + glutPassiveMotionFunc(demo_mmotion); glutSpaceballMotionFunc(demo_sball_motion); glutSpaceballRotateFunc(demo_sball_rotate); glutSpaceballButtonFunc(demo_sball_button); diff --git a/src/part_whitted.c b/src/part_whitted.c index 18bed8d..bda876b 100644 --- a/src/part_whitted.c +++ b/src/part_whitted.c @@ -4,6 +4,7 @@ #include "sdr.h" #include "texture.h" #include "post.h" +#include "imtk.h" static int init(void); static void destroy(void); @@ -70,6 +71,9 @@ static void stop(void) static void draw(long tm) { + static float vgn_offset = 0.47; + static float vgn_sharp = 3.1; + glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); @@ -97,7 +101,7 @@ static void draw(long tm) glVertex2f(-1, 1); glEnd(); - vignette(0.43, 0.38, 0.45, 0.8, 1.0); + vignette(0.43, 0.38, 0.45, vgn_offset, vgn_sharp); if(dbgtex && dbg_alpha > 0.0) { glUseProgram(0); @@ -108,6 +112,25 @@ static void draw(long tm) glMatrixMode(GL_TEXTURE); glLoadIdentity(); } + + if(dbgui) { + glUseProgram(0); + + imtk_begin(); + imtk_layout_start(10, 20); + imtk_layout_spacing(10); + + imtk_layout_dir(IMTK_HORIZONTAL); + + imtk_label("offset:", IMTK_AUTO, IMTK_AUTO); + vgn_offset = imtk_slider(IMUID, vgn_offset, 0.0, 1.5, IMTK_AUTO, IMTK_AUTO); + imtk_layout_newline(); + + imtk_label("sharpness:", IMTK_AUTO, IMTK_AUTO); + vgn_sharp = imtk_slider(IMUID, vgn_sharp, 0, 10, IMTK_AUTO, IMTK_AUTO); + imtk_layout_newline(); + imtk_end(); + } } static void mbutton(int bn, int st, int x, int y) @@ -117,6 +140,11 @@ static void mbutton(int bn, int st, int x, int y) mouse_y = y; switch(bn) { + case 0: + if(imtk_layout_contains(x, y)) { + imtk_inp_mouse(bn, st); + } + break; case 3: dbg_alpha += 0.1; if(dbg_alpha > 1.0) dbg_alpha = 1.0; @@ -136,6 +164,11 @@ static void mmotion(int x, int y) if(!(dx | dy)) return; + if(imtk_layout_contains(x, y)) { + imtk_inp_motion(x, y); + return; + } + if(bnstate[0]) { cam_theta += dx * 0.5; cam_phi += dy * 0.5; -- 1.7.10.4