]> Dogcows Code - chaz/yoink/commitdiff
use only triangles; no quads
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 19 Jul 2010 18:33:07 +0000 (12:33 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Mon, 19 Jul 2010 18:33:07 +0000 (12:33 -0600)
src/GameLayer.cc
src/Main.cc
src/TitleLayer.cc
src/moof/mesh.cc
src/moof/mesh.hh

index c0d35b95dadb692b085ee1d9d08bb76765800c25..5e95b7615393c57709b1cf3bb4d6b578f4d0ef80 100644 (file)
@@ -188,6 +188,10 @@ void GameLayer::draw(moof::scalar alpha) const
        if (!state_.scene) return;
        state_.camera.upload_to_gl(alpha);
 
+       float pos[] = {state_.heroine->state().position[0],
+                                  state_.heroine->state().position[1], 0.0f};
+       glLightfv(GL_LIGHT0, GL_POSITION, pos);
+
        // DRAW THE SCENE
        moof::image::reset_binding();
 
index 9ae5156047f6205ea41d5bed190796cd7c795bb7..ae183ec49ab845ee9f5921f8b47642e6445526be 100644 (file)
@@ -153,13 +153,20 @@ void Main::setupGL()
        glEnable(GL_POLYGON_SMOOTH);
        glShadeModel(GL_SMOOTH);
 
-       //glEnable(GL_BLEND);
-       //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_ALPHA_TEST);
        glAlphaFunc(GL_GREATER, 0.0);
 
        glClearColor(0.0, 0.0, 0.0, 1.0);
 
+       //glEnable(GL_LIGHTING);
+       glEnable(GL_LIGHT0);
+
+       float light[] = {1.0f, 1.0f, 1.0f, 1.0f};
+       glLightfv(GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, light);
+
+
        //glMatrixMode(GL_PROJECTION);
        //glLoadIdentity();
        //moof::scalar ratio = moof::core.getVideo()->width() /
index 7a206c0b77a4c806b0111d76bc8eb820d3a33e7b..92484d0c3c7afdaffa5b2ce58ca814136249888e 100644 (file)
@@ -30,7 +30,7 @@ void TitleLayer::update(moof::scalar t, moof::scalar dt)
 
 void TitleLayer::draw(moof::scalar alpha) const
 {
-       glClearColor(0.0, 0.0, mFadeIn.state(alpha), 1.0);
+       glClearColor(mFadeIn.state(alpha), 0.0, mFadeIn.state(alpha), 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
        moof::view::draw(alpha);
 }
index ee4d4b62540c22c3ff5a19c891cf145fe238ed49..b41c377f29429514a1bcfffe48b91e16e877f3cc 100644 (file)
@@ -140,7 +140,7 @@ void mesh::import(std::istream& stream)
 
                        stream >> atom >> materials_.back().shininess;
                        stream >> atom >> materials_.back().diffuse[3]; // transparency
-                       materials_.back().diffuse[3] = 1.0;
+                       materials_.back().diffuse[3] = 1.0;     // FIXME: temporary
 
                        log_info("read material", materials_.back().name,
                                                                          materials_.back().diffuse);
@@ -242,7 +242,7 @@ void mesh::import(std::istream& stream)
 
                                int numrefs = 0;
                                stream >> numrefs;
-                               ASSERT(numrefs == 3 || numrefs == 4);
+                               ASSERT(numrefs >= 3);
 
                                if ((int)obj->faces.size() <= material)
                                {
@@ -254,23 +254,46 @@ void mesh::import(std::istream& stream)
                                }
 
                                material_group& face = obj->faces[material];
-                               for (int j = 0; j < numrefs; ++j)
+
+                               int vert;
+                               stream >> vert;
+                               vector2 uv = read_pair(stream);
+                               face.triangles.push_back(vert);
+                               face.triangles_uv.push_back(uv);
+
+                               unsigned first = face.triangles.back();
+                               vector2 first_uv = face.triangles_uv.back();
+
+                               stream >> vert;
+                               uv = read_pair(stream);
+                               face.triangles.push_back(vert);
+                               face.triangles_uv.push_back(uv);
+
+                               stream >> vert;
+                               uv = read_pair(stream);
+                               face.triangles.push_back(vert);
+                               face.triangles_uv.push_back(uv);
+
+                               unsigned last = face.triangles.back();
+                               vector2 last_uv = face.triangles_uv.back();
+
+                               for (int j = 3; j < numrefs; ++j)
                                {
-                                       int             vert;
+                                       // first
+                                       face.triangles.push_back(first);
+                                       face.triangles_uv.push_back(first_uv);
+
+                                       // last
+                                       face.triangles.push_back(last);
+                                       face.triangles_uv.push_back(last_uv);
+
                                        stream >> vert;
+                                       uv = read_pair(stream);
+                                       face.triangles.push_back(vert);
+                                       face.triangles_uv.push_back(uv);
 
-                                       vector2 uv = read_pair(stream);
-
-                                       if (numrefs == 3)
-                                       {
-                                               face.triangles.push_back(vert);
-                                               face.triangles_uv.push_back(uv);
-                                       }
-                                       else
-                                       {
-                                               face.quads.push_back(vert);
-                                               face.quads_uv.push_back(uv);
-                                       }
+                                       last = face.triangles.back();
+                                       last_uv = face.triangles_uv.back();
                                }
                        }
                }
@@ -402,12 +425,12 @@ void mesh::set_material(int index) const
 
 void mesh::set_material(const material& material) const
 {
-       //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse.data());
-       //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient.data());
-       //glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular.data());
-       //glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material.emissive.data());
-       //glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
-       glColor(material.diffuse);
+       glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material.diffuse.data());
+       glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material.ambient.data());
+       glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material.specular.data());
+       glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material.emissive.data());
+       glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material.shininess);
+       //glColor(material.diffuse);
 }
 
 
@@ -425,12 +448,12 @@ void mesh::object::draw(const mesh& mesh, scalar alpha) const
                //glEnd();
        //}
        
-       glPolygonMode(GL_BACK, GL_LINE);
+       //glPolygonMode(GL_BACK, GL_LINE);
        //glVertexPointer(3, GL_SCALAR, 0, verts[0].data());
        if (texture) texture->bind();
        else image::reset_binding();
 
-       for (int i = 0; i < faces.size(); ++i)
+       for (size_t i = 0; i < faces.size(); ++i)
        {
                const material_group& face = faces[i];
                mesh.set_material(i);
@@ -448,21 +471,6 @@ void mesh::object::draw(const mesh& mesh, scalar alpha) const
                                glVertex(verts[face.triangles[j+2]]);
                        glEnd();
                }
-
-               count = face.quads.size();
-               for (int j = 0; j < count; j += 4)
-               {
-                       glBegin(GL_QUADS);
-                               glTexCoord(face.quads_uv[j]);
-                               glVertex(verts[face.quads[j]]);
-                               glTexCoord(face.quads_uv[j+1]);
-                               glVertex(verts[face.quads[j+1]]);
-                               glTexCoord(face.quads_uv[j+2]);
-                               glVertex(verts[face.quads[j+2]]);
-                               glTexCoord(face.quads_uv[j+3]);
-                               glVertex(verts[face.quads[j+3]]);
-                       glEnd();
-               }
        }
 
        std::vector<object_ptr>::const_iterator jt;
@@ -485,13 +493,6 @@ void mesh::material_group::draw(scalar alpha) const
                                           triangles.size(), GL_UNSIGNED_INT,
                                           &triangles[0]);
        }
-
-       if (quads.size() > 0)
-       {
-               //log_info("drawing quads:", quads.size()/4);
-               glTexCoordPointer(2, GL_SCALAR, 0, quads_uv[0].data());
-               glDrawElements(GL_QUADS, quads.size(), GL_UNSIGNED_INT, &quads[0]);
-       }
        */
 }
 
index 1400cdd2f920680cb2b2b06a9046807a581dc37a..cf267fba65d8a437a014301869e24dcf78245d44 100644 (file)
@@ -56,42 +56,6 @@ public:
        };
 
 
-       //typedef vector3 triangle[3];
-       //typedef vector2 triangle_uv[3];
-       //typedef vector3 quad[4];
-       //typedef vector2 quad_uv[4];
-
-       //struct triangle
-       //{
-               //vector3 verts[3];
-               //vector3& operator [] (int i) { return verts[i]; }
-               //const vector3& operator [] (int i) const { return verts[i]; }
-       //};
-
-       //struct triangle_uv
-       //{
-               //vector2 verts[3];
-               //vector2& operator [] (int i) { return verts[i]; }
-               //const vector2& operator [] (int i) const { return verts[i]; }
-       //};
-
-
-       //struct quad
-       //{
-               //vector3 verts[4];
-               //vector3& operator [] (int i) { return verts[i]; }
-               //const vector3& operator [] (int i) const { return verts[i]; }
-       //};
-
-
-       //struct quad_uv
-       //{
-               //vector2 verts[4];
-               //vector2& operator [] (int i) { return verts[i]; }
-               //const vector2& operator [] (int i) const { return verts[i]; }
-       //};
-
-
        void set_material(int index) const;
        void set_material(const material& material) const;
 
@@ -99,14 +63,11 @@ public:
        {
                material_group() {}
 
-               std::vector<unsigned>   triangles;
-               std::vector<vector2>    triangles_uv;
-
-               std::vector<unsigned>   quads;
-               std::vector<vector2>    quads_uv;
+               void draw(scalar alpha = SCALAR(0.0)) const;
 
 
-               void draw(scalar alpha = SCALAR(0.0)) const;
+               std::vector<unsigned>   triangles;
+               std::vector<vector2>    triangles_uv;
        };
 
 
This page took 0.03066 seconds and 4 git commands to generate.