add texture support
This commit is contained in:
parent
01a90fdef7
commit
e999bf67b7
19
WFObj.cc
19
WFObj.cc
@ -419,9 +419,15 @@ void WFObj::loadMaterial(const std::string & name)
|
|||||||
{
|
{
|
||||||
/* ignore these parameters */
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
cerr << "WFObj: error: unrecognized material directive: '"
|
cerr << "WFObj: warning: unrecognized material directive: '"
|
||||||
<< tokens[0] << "'" << endl;
|
<< tokens[0] << "'" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -553,6 +559,17 @@ void WFObj::bindBuffers()
|
|||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_vbo);
|
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
|
bool WFObj::VertexRef::operator<(const VertexRef & other) const
|
||||||
{
|
{
|
||||||
if (vertex != other.vertex)
|
if (vertex != other.vertex)
|
||||||
|
4
WFObj.h
4
WFObj.h
@ -48,7 +48,7 @@ public:
|
|||||||
GLfloat ambient[4];
|
GLfloat ambient[4];
|
||||||
GLfloat diffuse[4];
|
GLfloat diffuse[4];
|
||||||
GLfloat specular[4];
|
GLfloat specular[4];
|
||||||
std::string texture;
|
GLuint texture;
|
||||||
int flags;
|
int flags;
|
||||||
int first_vertex;
|
int first_vertex;
|
||||||
int num_vertices;
|
int num_vertices;
|
||||||
@ -115,6 +115,7 @@ protected:
|
|||||||
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
std::string getLine(const Buffer & buff, size_t idx, size_t *update_idx);
|
||||||
void loadMaterial(const std::string & name);
|
void loadMaterial(const std::string & name);
|
||||||
bool buildVBO();
|
bool buildVBO();
|
||||||
|
GLuint loadTexture(const std::string & path);
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
std::vector<Vertex> m_vertices[VERTEX_TYPES];
|
||||||
@ -130,6 +131,7 @@ protected:
|
|||||||
bool m_do_textures;
|
bool m_do_textures;
|
||||||
size_t m_n_floats_per_vref;
|
size_t m_n_floats_per_vref;
|
||||||
size_t m_num_materials;
|
size_t m_num_materials;
|
||||||
|
std::map<std::string, GLuint> m_textures;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user