add texture support

This commit is contained in:
Josh Holtrop 2011-05-16 15:16:40 -04:00
parent 01a90fdef7
commit e999bf67b7
2 changed files with 21 additions and 2 deletions

View File

@ -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)

View File

@ -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<Vertex> 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<std::string, GLuint> m_textures;
};
#endif