added a non-interactive blobs exhibit
[laserbrain_demo] / src / ui.cc
index 1a18324..a0babe4 100644 (file)
--- a/src/ui.cc
+++ b/src/ui.cc
@@ -19,6 +19,14 @@ struct Message {
 };
 static Message *msglist;
 
+struct Text {
+       char *str;
+       Vec2 pos;
+       Vec3 color;
+       Text *next;
+};
+static Text *txlist;
+
 static long timeout = 2000;
 static long trans_time = 250;
 static dtx_font *font;
@@ -71,6 +79,33 @@ void show_messagev(long timeout, const Vec3 &color, const char *fmt, va_list ap)
        msglist = dummy.next;
 }
 
+void print_text(const Vec2 &pos, const Vec3 &color, const char *fmt, ...)
+{
+       va_list ap;
+       va_start(ap, fmt);
+       print_textv(pos, color, fmt, ap);
+       va_end(ap);
+}
+
+void print_textv(const Vec2 &pos, const Vec3 &color, const char *fmt, va_list ap)
+{
+       char buf[512];
+
+       init();
+
+       vsnprintf(buf, sizeof buf, fmt, ap);
+
+       Text *tx = new Text;
+       int len = strlen(buf);
+       tx->str = new char[len + 1];
+       memcpy(tx->str, buf, len + 1);
+       tx->color = color;
+       tx->pos = Vec2(pos.x, -pos.y);
+
+       tx->next = txlist;
+       txlist = tx;
+}
+
 void draw_ui()
 {
        if(!font) return;
@@ -111,6 +146,21 @@ void draw_ui()
                msg = msg->next;
        }
 
+       while(txlist) {
+               Text *tx = txlist;
+               txlist = txlist->next;
+
+               glMatrixMode(GL_MODELVIEW);
+               glLoadIdentity();
+               glTranslatef(tx->pos.x, tx->pos.y, 0);
+
+               glColor3f(tx->color.x, tx->color.y, tx->color.z);
+               dtx_string(tx->str);
+
+               delete [] tx->str;
+               delete tx;
+       }
+
        glPopAttrib();
 
        glMatrixMode(GL_PROJECTION);