From 1aaca3876c029a6558d193bf315e2ce188ce1d79 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 7 Oct 2018 16:38:01 +0300 Subject: [PATCH] fixed more animation bugs, added rudimentary UI --- src/geom.cc | 70 ++++++++++++++++++++++++++++++++++++-- src/geom.h | 2 +- src/main.cc | 60 +++++++++++++++++++++----------- src/seq.cc | 31 ++++++++++++----- src/seq.h | 3 ++ src/ui.cc | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ui.h | 11 ++++++ 7 files changed, 255 insertions(+), 31 deletions(-) create mode 100644 src/ui.cc create mode 100644 src/ui.h diff --git a/src/geom.cc b/src/geom.cc index 62e36d3..770b438 100644 --- a/src/geom.cc +++ b/src/geom.cc @@ -1,20 +1,52 @@ +#include #include #include #include "geom.h" #include "sdr.h" static unsigned int sdr_curve_top; +static unsigned int tex_xcircle; + +static const unsigned char tex_xcircle_pixels[] = { + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 64, 255, 255, 255, 255, 64, 0, + + 0, 64, 255, 255, 255, 255, 64, 0, + 0, 0, 255, 255, 255, 255, 0, 0, + 0, 0, 128, 255, 255, 128, 0, 0, + 0, 0, 0, 64, 64, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + bool init_geom() { if(!(sdr_curve_top = create_program_load("sdr/curve_top.v.glsl", "sdr/curve_top.f.glsl"))) { return false; } + + glGenTextures(1, &tex_xcircle); + glBindTexture(GL_TEXTURE_2D, tex_xcircle); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 8, 16, 0, + GL_LUMINANCE, GL_UNSIGNED_BYTE, tex_xcircle_pixels); return true; } void destroy_geom() { + glDeleteTextures(1, &tex_xcircle); free_program(sdr_curve_top); } @@ -112,7 +144,7 @@ void ground() glPopMatrix(); } -void xlogo() +void xlogo(float sz, float alpha, float xcircle) { static const float xlogo_varr[] = { -0.500, 0.407, -0.113, -0.109, 0.059, -0.006, -0.251, 0.407, @@ -124,23 +156,57 @@ void xlogo() /* billboarding */ float mv[16]; glGetFloatv(GL_MODELVIEW_MATRIX, mv); - mv[0] = mv[5] = mv[10] = 1.0f; + mv[0] = mv[5] = mv[10] = sz; mv[1] = mv[2] = mv[4] = mv[6] = mv[8] = mv[9] = 0.0f; glPushMatrix(); glLoadMatrixf(mv); + glTranslatef(0, 0.15, 0); glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); + glColor4f(0, 0, 0, alpha); const float *vptr = xlogo_varr; for(int i=0; i<(int)(sizeof xlogo_varr / sizeof *xlogo_varr) / 2; i++) { glVertex2fv(vptr); vptr += 2; } glEnd(); + glTranslatef(0, -0.15, 0); + glDisable(GL_BLEND); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex_xcircle); + + glDisable(GL_CULL_FACE); + glEnable(GL_ALPHA_TEST); + float aref = 1.0f - xcircle; + glAlphaFunc(GL_GREATER, aref > 0.0f ? aref : 0.0f); + + glScalef(1.4, 1, 1); + +#define XLOGO_CIRCLE_SEG 64 + // circle thingy + glBegin(GL_QUAD_STRIP); + for(int i=0; i 0.0) { glPushMatrix(); float beam_angle_rad = beam_angle / 180.0 * M_PI; float xlogo_dist = beam_len; float xlogo_pos[3] = {sin(beam_angle_rad), 0, cos(beam_angle_rad)}; - glTranslatef(xlogo_pos[0] * xlogo_dist, xlogo_pos[1] * xlogo_dist + 5, xlogo_pos[2] * xlogo_dist); - glColor4f(0, 0, 0, xlogo_alpha); - xlogo(); + glTranslatef(xlogo_pos[0] * xlogo_dist, xlogo_pos[1] * xlogo_dist + 4.7, xlogo_pos[2] * xlogo_dist); + xlogo(0.5, xlogo_alpha, xcircle); glPopMatrix(); } @@ -185,6 +195,10 @@ static void display() light(); glPopMatrix(); + if(show_ui) { + ui(); + } + if(show_help) { help(); } @@ -241,7 +255,7 @@ static void help() { static const char *help_lines[] = { "Camera control", - " LMB ............ rotate", + " LMB drag ....... rotate", " MMB drag ....... pan", " RMB drag/wheel . zoom", " c .............. toggle free/animated camera", @@ -333,7 +347,7 @@ static void keyboard(unsigned char c, int x, int y) int idx; static float orig_beam_speed; static Camera orig_cam; - long anim_time = anim_stop_time ? anim_stop_time - start_time : tmsec; + long anim_time = anim_stopped ? anim_stop_time - start_time : tmsec; switch(c) { case 27: @@ -342,18 +356,20 @@ static void keyboard(unsigned char c, int x, int y) case '\b': start_time = glutGet(GLUT_ELAPSED_TIME); prev_tmsec = 0; - anim_stop_time = 0; + anim_stop_time = anim_stopped ? start_time : 0; beam_angle = 0; break; case ' ': - if(anim_stop_time > 0) { + if(anim_stopped) { long msec = glutGet(GLUT_ELAPSED_TIME); start_time += msec - anim_stop_time; prev_tmsec = msec - start_time; anim_stop_time = 0; + anim_stopped = false; } else { anim_stop_time = glutGet(GLUT_ELAPSED_TIME); + anim_stopped = true; } break; @@ -468,6 +484,10 @@ static void keyb_special(int key, int x, int y) show_help = !show_help; break; + case GLUT_KEY_F5: + show_ui = !show_ui; + break; + default: break; } diff --git a/src/seq.cc b/src/seq.cc index 592abd5..36ce88c 100644 --- a/src/seq.cc +++ b/src/seq.cc @@ -78,16 +78,31 @@ void clear_seq_track(const char *name) } } +bool seq_track_empty(int idx) +{ + return tracks[idx].track->empty(); +} + +bool seq_track_empty(const char *name) +{ + int idx = find_seq_track(name); + if(idx >= 0) { + return tracks[idx].track->empty(); + } + return true; +} + void set_seq_value(int idx, long tm, float val) { tracks[idx].track->set_value(tm, val); + printf("track(%d): set keyframe %ld -> %f\n", idx, tm, val); } void set_seq_value(const char *name, long tm, float val) { int idx = find_seq_track(name); if(idx >= 0) { - tracks[idx].track->set_value(tm, val); + set_seq_value(idx, tm, val); } } @@ -199,16 +214,16 @@ bool dump_seq(const char *fname) int nkeys = tracks[i].track->get_num_keys(); if(!nkeys) continue; - fprintf(fp, " track {\n"); - fprintf(fp, " name = \"%s\"\n", tracks[i].name); + fprintf(fp, "\ttrack {\n"); + fprintf(fp, "\t\tname = \"%s\"\n", tracks[i].name); for(int j=0; j +#include +#include +#include +#include "ui.h" + +extern int win_width, win_height; + +extern bool anim_stopped; +extern long anim_time; + + +bool init_ui() +{ + return true; +} + +void destroy_ui() +{ +} + +void ui() +{ + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, win_width, win_height, 0, -1, 1); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if(anim_stopped) { + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glVertex2f(10, 10); + glVertex2f(10, 50); + glVertex2f(22, 50); + glVertex2f(22, 10); + glVertex2f(30, 10); + glVertex2f(30, 50); + glVertex2f(42, 50); + glVertex2f(42, 10); + glEnd(); + } + + glColor3f(1, 0.9, 0.5); + gl_printf(win_width - 100, 20, "%4ld.%03ld", anim_time / 1000, anim_time % 1000); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + glPopAttrib(); +} + +void gl_printf(int x, int y, const char *fmt, ...) +{ + va_list ap; + int buf_size, curx, cury; + char *buf, tmp; + + va_start(ap, fmt); + buf_size = vsnprintf(&tmp, 0, fmt, ap); + va_end(ap); + + if(buf_size == -1) { + buf_size = 512; + } + + buf = (char*)alloca(buf_size + 1); + va_start(ap, fmt); + vsnprintf(buf, buf_size + 1, fmt, ap); + va_end(ap); + + static const float tabstop = 4; + static const float line_spacing = 18; + + curx = x; + cury = y; + glRasterPos2i(x, y); + + while(*buf) { + char c = *buf++; + + switch(c) { + case '\r': + if(*buf == '\n') ++buf; + case '\n': + cury += line_spacing; + curx = x; + glRasterPos2i(curx, cury); + break; + + case '\t': + curx = (curx / tabstop) * tabstop + tabstop; + glRasterPos2i(curx, cury); + break; + + default: + glutBitmapCharacter(GLUT_BITMAP_9_BY_15, c); + } + } +} diff --git a/src/ui.h b/src/ui.h new file mode 100644 index 0000000..c2b519d --- /dev/null +++ b/src/ui.h @@ -0,0 +1,11 @@ +#ifndef UI_H_ +#define UI_H_ + +bool init_ui(); +void destroy_ui(); + +void ui(); + +void gl_printf(int x, int y, const char *fmt, ...); + +#endif /* UI_H_ */ -- 1.7.10.4