From c143f7e806766a73cd69dc6e084e977641019ce6 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Mon, 19 Jul 2010 12:33:07 -0600 Subject: [PATCH] use only triangles; no quads --- src/GameLayer.cc | 4 ++ src/Main.cc | 11 +++++- src/TitleLayer.cc | 2 +- src/moof/mesh.cc | 93 ++++++++++++++++++++++++----------------------- src/moof/mesh.hh | 45 ++--------------------- 5 files changed, 64 insertions(+), 91 deletions(-) diff --git a/src/GameLayer.cc b/src/GameLayer.cc index c0d35b9..5e95b76 100644 --- a/src/GameLayer.cc +++ b/src/GameLayer.cc @@ -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(); diff --git a/src/Main.cc b/src/Main.cc index 9ae5156..ae183ec 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -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() / diff --git a/src/TitleLayer.cc b/src/TitleLayer.cc index 7a206c0..92484d0 100644 --- a/src/TitleLayer.cc +++ b/src/TitleLayer.cc @@ -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); } diff --git a/src/moof/mesh.cc b/src/moof/mesh.cc index ee4d4b6..b41c377 100644 --- a/src/moof/mesh.cc +++ b/src/moof/mesh.cc @@ -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::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]); - } */ } diff --git a/src/moof/mesh.hh b/src/moof/mesh.hh index 1400cdd..cf267fb 100644 --- a/src/moof/mesh.hh +++ b/src/moof/mesh.hh @@ -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 triangles; - std::vector triangles_uv; - - std::vector quads; - std::vector quads_uv; + void draw(scalar alpha = SCALAR(0.0)) const; - void draw(scalar alpha = SCALAR(0.0)) const; + std::vector triangles; + std::vector triangles_uv; }; -- 2.45.2