Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1918cc89bf | ||
|
|
e999bf67b7 |
No files matched your search
@@ -99,14 +99,8 @@ static void checkGLErrorLine(const char * function, int line)
|
|||||||
|
|
||||||
/****** WFObj functions ******/
|
/****** WFObj functions ******/
|
||||||
|
|
||||||
WFObj::WFObj(loadfile_t lf, loadtexture_t lt)
|
WFObj::WFObj()
|
||||||
{
|
{
|
||||||
m_loadfile = lf;
|
|
||||||
m_loadtexture = lt;
|
|
||||||
if (m_loadfile == NULL)
|
|
||||||
{
|
|
||||||
m_loadfile = loadfile;
|
|
||||||
}
|
|
||||||
if (m_valid)
|
if (m_valid)
|
||||||
{
|
{
|
||||||
glDeleteBuffers(1, &m_data_vbo);
|
glDeleteBuffers(1, &m_data_vbo);
|
||||||
@@ -131,8 +125,15 @@ void WFObj::clear()
|
|||||||
m_current_material_name = "";
|
m_current_material_name = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WFObj::load(const char *fname)
|
bool WFObj::load(const char *fname, loadfile_t lf, loadtexture_t lt)
|
||||||
{
|
{
|
||||||
|
m_loadfile = lf;
|
||||||
|
m_loadtexture = lt;
|
||||||
|
if (m_loadfile == NULL)
|
||||||
|
{
|
||||||
|
m_loadfile = loadfile;
|
||||||
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
Buffer buff;
|
Buffer buff;
|
||||||
@@ -419,9 +420,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 +560,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)
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -60,11 +60,11 @@ public:
|
|||||||
enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES };
|
enum { VERTEX, VERTEX_TEXTURE, VERTEX_NORMAL, VERTEX_TYPES };
|
||||||
|
|
||||||
/* constructors */
|
/* constructors */
|
||||||
WFObj(loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
WFObj();
|
||||||
~WFObj();
|
~WFObj();
|
||||||
|
|
||||||
/* methods */
|
/* methods */
|
||||||
bool load(const char *fname);
|
bool load(const char *fname, loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
||||||
bool load(const Buffer &buff);
|
bool load(const Buffer &buff);
|
||||||
const float * const getAABB() { return m_aabb; }
|
const float * const getAABB() { return m_aabb; }
|
||||||
size_t getStride() { return sizeof(GLfloat) * m_n_floats_per_vref; }
|
size_t getStride() { return sizeof(GLfloat) * m_n_floats_per_vref; }
|
||||||
@@ -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
|
||||||
Reference in new issue
Block a user