From e999bf67b7fefa2ec7a882689ab7c686a066daf4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 16 May 2011 15:16:40 -0400 Subject: [PATCH] add texture support --- WFObj.cc | 19 ++++++++++++++++++- WFObj.h | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/WFObj.cc b/WFObj.cc index 733597a..030fc93 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -419,9 +419,15 @@ void WFObj::loadMaterial(const std::string & name) { /* ignore these parameters */ } + else if (tokens[0] == "map_Kd") + { + m_materials[mat_name].texture = loadTexture(tokens[1]); + if (m_materials[mat_name].texture != 0) + m_materials[mat_name].flags |= Material::TEXTURE_BIT; + } else { - cerr << "WFObj: error: unrecognized material directive: '" + cerr << "WFObj: warning: unrecognized material directive: '" << tokens[0] << "'" << endl; } } @@ -553,6 +559,17 @@ void WFObj::bindBuffers() glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_vbo); } +GLuint WFObj::loadTexture(const std::string & path) +{ + if (m_loadtexture == NULL) + return 0; + if (m_textures.find(path) != m_textures.end()) + return m_textures[path]; + GLuint id = m_loadtexture(path.c_str()); + m_textures[path] = id; + return id; +} + bool WFObj::VertexRef::operator<(const VertexRef & other) const { if (vertex != other.vertex) diff --git a/WFObj.h b/WFObj.h index b11c1c3..32d0caa 100644 --- a/WFObj.h +++ b/WFObj.h @@ -48,7 +48,7 @@ public: GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; - std::string texture; + GLuint texture; int flags; int first_vertex; int num_vertices; @@ -115,6 +115,7 @@ protected: std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx); void loadMaterial(const std::string & name); bool buildVBO(); + GLuint loadTexture(const std::string & path); /* variables */ std::vector m_vertices[VERTEX_TYPES]; @@ -130,6 +131,7 @@ protected: bool m_do_textures; size_t m_n_floats_per_vref; size_t m_num_materials; + std::map m_textures; }; #endif