+ if(!font) return;
+
+ // render the 2D UI in a texture
+ push_render_target(rtarg);
+ glClearColor(0, 1, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ draw_2d_ui();
+ pop_render_target();
+
+ // place UI image into the scene
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ Mat4 mvmat;
+ glGetFloatv(GL_MODELVIEW_MATRIX, mvmat[0]);
+ if(parent) {
+ mvmat = parent->get_matrix() * mvmat;
+ }
+ mvmat.translate(pos.x, pos.y, pos.z);
+
+ mvmat[0][0] = mvmat[1][1] = mvmat[2][2] = 1.0f;
+ mvmat[0][1] = mvmat[0][2] = mvmat[1][0] = mvmat[2][0] = mvmat[1][2] = mvmat[2][1] = 0.0f;
+ glLoadMatrixf(mvmat[0]);
+
+ glPushAttrib(GL_ENABLE_BIT);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ glEnable(GL_TEXTURE_2D);
+ glDepthMask(0);
+
+ glUseProgram(0);
+ bind_texture(rtarg->texture());
+
+ glMatrixMode(GL_TEXTURE);
+ glLoadMatrixf(rtarg->texture_matrix()[0]);
+
+ glBegin(GL_QUADS);
+ glColor3f(1, 1, 1);
+ glTexCoord2f(0, 0); glVertex2f(-size.x / 2, -size.y / 2);
+ glTexCoord2f(1, 0); glVertex2f(size.x / 2, -size.y / 2);
+ glTexCoord2f(1, 1); glVertex2f(size.x / 2, size.y / 2);
+ glTexCoord2f(0, 1); glVertex2f(-size.x / 2, size.y / 2);
+ glEnd();
+
+ glLoadIdentity();
+
+ glDepthMask(1);
+ glPopAttrib();
+
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+}
+
+static inline float *vrect(const Rect &rect, int i)
+{
+ static float v[2];
+ v[0] = ((i + 1) & 2) ? rect.x + rect.w : rect.x;
+ v[1] = (i & 2) ? rect.y : rect.y + rect.h;
+ return v;
+}
+
+static inline void draw_rect(const Rect &rect, int col)
+{
+ glBegin(GL_QUADS);
+ glColor3fv(color[col]);
+ for(int i=0; i<4; i++)
+ glVertex2fv(vrect(rect, i));
+ glEnd();
+}
+
+static void clip_rect(const Rect &rect)
+{
+ glScissor(rect.x, ui_height - rect.y - rect.h, rect.w, rect.h);
+}
+
+static void draw_frame(const Rect &rect)
+{
+ clip_rect(rect);
+
+ draw_rect(rect, COL_BG);
+ glLineWidth(3.0);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ draw_rect(rect, COL_FRM);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+}
+
+static void draw_titlebar(const Rect &rect)
+{
+ clip_rect(rect);
+
+ draw_rect(rect, COL_FRM);