wfobj/WFObj.hh
josh e642818e4a added doTextureInfo option to WFObj::render() and WFMtl class methods
git-svn-id: svn://anubis/misc/wfobj@77 bd8a9e45-a331-0410-811e-c64571078777
2008-11-13 23:21:22 +00:00

74 lines
2.0 KiB
C++

#include <GL/gl.h>
#include <vector>
#include <string>
#include <map>
class WFObj
{
public:
typedef GLuint (*loadTextureFunc_t)(const char * texture);
typedef void * (*loadFileFunc_t)(const char * filename,
unsigned int * length);
bool load(const std::string & filename,
loadTextureFunc_t loadTexture = NULL,
loadFileFunc_t loadFile = NULL);
GLuint render(bool doTextureInfo = true);
const float * const getAABB() { return m_aabb; }
protected:
/* types */
class Vertex
{
public:
float operator[](int idx) const { return data[idx]; }
const float & operator[](int idx) { return data[idx]; }
float * getData() { return data; }
private:
float data[4];
};
/* methods */
void clear();
int filesize(const char * filename);
void processInputLine(const std::string & input);
Vertex readVertex(const std::vector<std::string> & parts);
void parseVertexIndices(const std::string & vtxref, int * ret);
void updateAABB(const float * const vertex);
bool load(std::istream & istr, unsigned int size);
/* variables */
std::vector< std::vector<std::string> > m_data;
loadTextureFunc_t m_loadTexture;
loadFileFunc_t m_loadFile;
std::string m_fileName;
float m_aabb[6];
bool m_loadedVertex;
};
class WFMtl
{
public:
bool load(const std::string & filename,
WFObj::loadTextureFunc_t loadTexture = NULL,
WFObj::loadFileFunc_t loadFile = NULL);
void renderBegin(const std::string & mtlname, bool doTextureInfo = true);
void renderEnd(const std::string & mtlname, bool doTextureInfo = true);
protected:
/* methods */
void clear();
int filesize(const char * filename);
void processInputLine(const std::string & input);
void pushAttributes();
bool load(std::istream & istr, unsigned int size);
/* variables */
std::map< std::string, std::vector< std::vector<std::string> > > m_data;
std::string m_currentMaterialName;
bool m_attributesPushed;
WFObj::loadTextureFunc_t m_loadTexture;
std::string m_fileName;
};