Compare commits

..
4 Commits
3 changed files with 16 additions and 6 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# vim:filetype=python # vim:filetype=python
env = Environment(LIBS = ['GL'], CXXFLAGS = ['-Wall']) env = Environment(LIBS = ['GL'], CXXFLAGS = ['-Wall', '-DGL_GLEXT_PROTOTYPES'])
env.Program('driver', Glob('*.cc')) env.Program('driver', Glob('*.cc'))
+13 -4
View File
@@ -1,6 +1,4 @@
#define GL_GLEXT_PROTOTYPES
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@@ -341,7 +339,7 @@ WFObj::VertexRef WFObj::readVertexRef(const std::string ref)
void WFObj::loadMaterial(const std::string & name) void WFObj::loadMaterial(const std::string & name)
{ {
Buffer buff; Buffer buff;
string path = (name[0] != '/') ? basePath(m_path) + name : name; string path = resolvePath(name);
if (!m_loadfile(path.c_str(), buff)) if (!m_loadfile(path.c_str(), buff))
{ {
cerr << "WFObj: error: couldn't open material file '" << path << "'" cerr << "WFObj: error: couldn't open material file '" << path << "'"
@@ -422,7 +420,7 @@ void WFObj::loadMaterial(const std::string & name)
} }
else if (tokens[0] == "map_Kd") else if (tokens[0] == "map_Kd")
{ {
m_materials[mat_name].texture = loadTexture(tokens[1]); m_materials[mat_name].texture = loadTexture(resolvePath(tokens[1]));
if (m_materials[mat_name].texture != 0) if (m_materials[mat_name].texture != 0)
m_materials[mat_name].flags |= Material::TEXTURE_BIT; m_materials[mat_name].flags |= Material::TEXTURE_BIT;
} }
@@ -464,6 +462,12 @@ bool WFObj::buildVBO()
it != m_faces.end(); it != m_faces.end();
it++) it++)
{ {
if (m_materials.find(it->first) == m_materials.end())
{
cerr << "Material '" << it->first << "' referenced in '"
<< m_path << "' is not defined." << endl;
return false;
}
for (vector<Face>::iterator fit = it->second.begin(); for (vector<Face>::iterator fit = it->second.begin();
fit != it->second.end(); fit != it->second.end();
fit++) fit++)
@@ -571,6 +575,11 @@ GLuint WFObj::loadTexture(const std::string & path)
return id; return id;
} }
string WFObj::resolvePath(const string & name)
{
return (name[0] != '/') ? basePath(m_path) + name : name;
}
bool WFObj::VertexRef::operator<(const VertexRef & other) const bool WFObj::VertexRef::operator<(const VertexRef & other) const
{ {
if (vertex != other.vertex) if (vertex != other.vertex)
+2 -1
View File
@@ -19,7 +19,7 @@ public:
class Buffer class Buffer
{ {
public: public:
Buffer() : m_alloc(false) {} Buffer() : m_alloc(false) {data = NULL; length = 0;}
~Buffer() { if (m_alloc) delete data; } ~Buffer() { if (m_alloc) delete data; }
uint8_t *data; uint8_t *data;
size_t length; size_t length;
@@ -116,6 +116,7 @@ protected:
void loadMaterial(const std::string & name); void loadMaterial(const std::string & name);
bool buildVBO(); bool buildVBO();
GLuint loadTexture(const std::string & path); GLuint loadTexture(const std::string & path);
std::string resolvePath(const std::string & name);
/* variables */ /* variables */
std::vector<Vertex> m_vertices[VERTEX_TYPES]; std::vector<Vertex> m_vertices[VERTEX_TYPES];