added message at the bottom "hold h to move the head with the mouse"
[hair] / src / main.cc
index 9720723..0ebbe44 100644 (file)
@@ -26,6 +26,7 @@ static void motion(int x, int y);
 static void idle();
 
 static unsigned int gen_grad_tex(int sz, const Vec3 &c0, const Vec3 &c1);
+static void draw_text(const char *text, int x, int y, float sz, const Vec3 &color);
 
 static std::vector<Mesh*> meshes;
 static Mesh *mesh_head;
@@ -129,6 +130,7 @@ static void cleanup()
        for(size_t i=0; i<meshes.size(); i++) {
                delete meshes[i];
        }
+       glDeleteTextures(1, &grad_tex);
 }
 
 static void display()
@@ -158,7 +160,12 @@ static void display()
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 */
        for(size_t i=0; i<meshes.size(); i++) {
-               meshes[i]->draw();
+               if(!meshes[i]->mtl.tex || meshes[i]->mtl.tex_opaque)
+                       meshes[i]->draw();
+       }
+       for(size_t i=0; i<meshes.size(); i++) {
+               if(meshes[i]->mtl.tex && !meshes[i]->mtl.tex_opaque)
+                       meshes[i]->draw();
        }
 /*
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -194,7 +201,7 @@ static void display()
        glPopAttrib();
 */
        float plane[4] = {
-               0, 0, 0.5 / 350, 0.5 
+               0, 0, 0.5 / 350, 0.5
        };
 
        glPushMatrix();
@@ -224,6 +231,9 @@ static void display()
 
        glPopMatrix();
 
+       draw_text("Hold h to move the head with the mouse!", 15, 15, 0.0015 * win_width, Vec3(0, 0, 0));
+       draw_text("Hold h to move the head with the mouse!", 12, 17, 0.0015 * win_width, Vec3(0.8, 0.5, 0.7));
+
        glutSwapBuffers();
        assert(glGetError() == GL_NO_ERROR);
 }
@@ -342,3 +352,38 @@ static unsigned int gen_grad_tex(int sz, const Vec3 &c0, const Vec3 &c1)
 
        return tex;
 }
+
+static void draw_text(const char *text, int x, int y, float sz, const Vec3 &color)
+{
+       glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POINT_BIT);
+
+       glDisable(GL_DEPTH_TEST);
+       glDisable(GL_LIGHTING);
+       glLineWidth(3);
+       glPointSize(3);
+
+       glMatrixMode(GL_PROJECTION);
+       glPushMatrix();
+       glLoadIdentity();
+       glOrtho(0, win_width, 0, win_height, -1, 1);
+
+       glMatrixMode(GL_MODELVIEW);
+       glPushMatrix();
+       glLoadIdentity();
+       glTranslatef(x, y, 0);
+       glScalef(0.1 * sz, 0.1 * sz, 1);
+
+       glColor3f(color.x, color.y, color.z);
+       while(*text != '\0') {
+               glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, *text);
+               text++;
+       }
+
+       glMatrixMode(GL_PROJECTION);
+       glPopMatrix();
+
+       glMatrixMode(GL_MODELVIEW);
+       glPopMatrix();
+
+       glPopAttrib();
+}