added doTextureInfo option to WFObj::render() and WFMtl class methods

git-svn-id: svn://anubis/misc/wfobj@77 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
josh 2008-11-13 23:21:22 +00:00
parent 9a1902b1cb
commit e642818e4a
2 changed files with 33 additions and 27 deletions

View File

@ -166,7 +166,7 @@ void WFObj::processInputLine(const std::string & input)
} }
GLuint WFObj::render() GLuint WFObj::render(bool doTextureInfo)
{ {
GLuint list = glGenLists(1); GLuint list = glGenLists(1);
glNewList(list, GL_COMPILE); glNewList(list, GL_COMPILE);
@ -301,13 +301,13 @@ GLuint WFObj::render()
} }
if (inMaterial) if (inMaterial)
{ {
material.renderEnd(currentMaterialName); material.renderEnd(currentMaterialName, doTextureInfo);
inMaterial = false; inMaterial = false;
} }
if (m_data[i].size() >= 2) if (m_data[i].size() >= 2)
{ {
currentMaterialName = m_data[i][1]; currentMaterialName = m_data[i][1];
material.renderBegin(currentMaterialName); material.renderBegin(currentMaterialName, doTextureInfo);
inMaterial = true; inMaterial = true;
} }
} }
@ -331,7 +331,7 @@ GLuint WFObj::render()
} }
if (inMaterial) if (inMaterial)
{ {
material.renderEnd(currentMaterialName); material.renderEnd(currentMaterialName, doTextureInfo);
inMaterial = false; inMaterial = false;
} }
glEndList(); glEndList();
@ -492,7 +492,7 @@ void WFMtl::processInputLine(const std::string & input)
} }
} }
void WFMtl::renderBegin(const string & mtlname) void WFMtl::renderBegin(const string & mtlname, bool doTextureInfo)
{ {
map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname); map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname);
if (it == m_data.end()) if (it == m_data.end())
@ -575,21 +575,24 @@ void WFMtl::renderBegin(const string & mtlname)
} }
else if (type == "map_Kd") /* load a diffuse texture */ else if (type == "map_Kd") /* load a diffuse texture */
{ {
/* TODO: figure out how i want to load the texture */ if (doTextureInfo)
if (stmts[i].size() == 2)
{ {
if (m_loadTexture != NULL) /* TODO: figure out how i want to load the texture */
if (stmts[i].size() == 2)
{ {
GLuint tex = m_loadTexture( (basePath(m_fileName) + if (m_loadTexture != NULL)
stmts[i][1]).c_str() );
if (tex > 0)
{ {
GLuint tex = m_loadTexture( (basePath(m_fileName) +
stmts[i][1]).c_str() );
if (tex > 0)
{
#ifdef DEBUGGL #ifdef DEBUGGL
cout << " glBindTexture(GL_TEXTURE_2D, " << tex << ")" << endl; cout << " glBindTexture(GL_TEXTURE_2D, " << tex << ")" << endl;
#endif #endif
glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
foundTexture = true; foundTexture = true;
didSomething = true; didSomething = true;
}
} }
} }
} }
@ -599,19 +602,22 @@ void WFMtl::renderBegin(const string & mtlname)
if (didSomething) if (didSomething)
{ {
pushAttributes(); pushAttributes();
if (foundTexture) if (doTextureInfo)
{ {
if (foundTexture)
{
#ifdef DEBUGGL #ifdef DEBUGGL
cout << " glEnable(GL_TEXTURE_2D)" << endl; cout << " glEnable(GL_TEXTURE_2D)" << endl;
#endif #endif
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
} }
else else
{ {
#ifdef DEBUGGL #ifdef DEBUGGL
cout << " glDisable(GL_TEXTURE_2D)" << endl; cout << " glDisable(GL_TEXTURE_2D)" << endl;
#endif #endif
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
}
} }
} }
} }
@ -627,7 +633,7 @@ void WFMtl::pushAttributes()
glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT); glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT);
} }
void WFMtl::renderEnd(const string & mtlname) void WFMtl::renderEnd(const string & mtlname, bool doTextureInfo)
{ {
map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname); map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname);
if (it == m_data.end()) if (it == m_data.end())

View File

@ -13,7 +13,7 @@ public:
bool load(const std::string & filename, bool load(const std::string & filename,
loadTextureFunc_t loadTexture = NULL, loadTextureFunc_t loadTexture = NULL,
loadFileFunc_t loadFile = NULL); loadFileFunc_t loadFile = NULL);
GLuint render(); GLuint render(bool doTextureInfo = true);
const float * const getAABB() { return m_aabb; } const float * const getAABB() { return m_aabb; }
protected: protected:
@ -53,8 +53,8 @@ public:
bool load(const std::string & filename, bool load(const std::string & filename,
WFObj::loadTextureFunc_t loadTexture = NULL, WFObj::loadTextureFunc_t loadTexture = NULL,
WFObj::loadFileFunc_t loadFile = NULL); WFObj::loadFileFunc_t loadFile = NULL);
void renderBegin(const std::string & mtlname); void renderBegin(const std::string & mtlname, bool doTextureInfo = true);
void renderEnd(const std::string & mtlname); void renderEnd(const std::string & mtlname, bool doTextureInfo = true);
protected: protected:
/* methods */ /* methods */