materials rendering colors, still need texture support
git-svn-id: svn://anubis/misc/wfobj@23 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
8772342fdb
commit
0ba39b3669
108
WFMtl.cc
108
WFMtl.cc
@ -20,6 +20,7 @@ void WFMtl::clear()
|
||||
{
|
||||
m_data = map< string, vector< vector<string> > >();
|
||||
m_currentMaterialName = "";
|
||||
m_attributesPushed = false;
|
||||
}
|
||||
|
||||
int WFMtl::filesize(const char * filename)
|
||||
@ -77,6 +78,7 @@ bool WFMtl::load(const string & filename)
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
/* END DEBUG */
|
||||
|
||||
@ -134,7 +136,103 @@ void WFMtl::renderBegin(const string & mtlname)
|
||||
map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname);
|
||||
if (it == m_data.end())
|
||||
return;
|
||||
/* TODO: draw the material at it->second */
|
||||
vector< vector<string> > & stmts = it->second;
|
||||
int num_stmts = stmts.size();
|
||||
bool foundTexture = false;
|
||||
bool didSomething = false;
|
||||
for (int i = 0; i < num_stmts; i++)
|
||||
{
|
||||
string & type = stmts[i][0];
|
||||
if (type == "Ka") /* set ambient color */
|
||||
{
|
||||
if ( (stmts[i].size() == 4) && (stmts[i][1] != "spectral") )
|
||||
{
|
||||
pushAttributes();
|
||||
float mat[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
for (int j = 0; j < 3; j++)
|
||||
sscanf(stmts[i][j+1].c_str(), "%f", &mat[j]);
|
||||
#ifdef DEBUGGL
|
||||
cout << " glMaterialfv(GL_FRONT, GL_AMBIENT, {";
|
||||
for (int j = 0; j < 4; j++)
|
||||
cout << mat[j] << (j < 3 ? ", " : "})");
|
||||
cout << endl;
|
||||
#endif
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
else if (type == "Kd") /* set diffuse color */
|
||||
{
|
||||
if ( (stmts[i].size() == 4) && (stmts[i][1] != "spectral") )
|
||||
{
|
||||
pushAttributes();
|
||||
float mat[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
for (int j = 0; j < 3; j++)
|
||||
sscanf(stmts[i][j+1].c_str(), "%f", &mat[j]);
|
||||
#ifdef DEBUGGL
|
||||
cout << " glMaterialfv(GL_FRONT, GL_DIFFUSE, {";
|
||||
for (int j = 0; j < 4; j++)
|
||||
cout << mat[j] << (j < 3 ? ", " : "})");
|
||||
cout << endl;
|
||||
#endif
|
||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
else if (type == "Ks") /* set specular color */
|
||||
{
|
||||
if ( (stmts[i].size() == 4) && (stmts[i][1] != "spectral") )
|
||||
{
|
||||
pushAttributes();
|
||||
float mat[4] = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
for (int j = 0; j < 3; j++)
|
||||
sscanf(stmts[i][j+1].c_str(), "%f", &mat[j]);
|
||||
#ifdef DEBUGGL
|
||||
cout << " glMaterialfv(GL_FRONT, GL_SPECULAR, {";
|
||||
for (int j = 0; j < 4; j++)
|
||||
cout << mat[j] << (j < 3 ? ", " : "})");
|
||||
cout << endl;
|
||||
#endif
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
else if (type == "map_Kd") /* load a diffuse texture */
|
||||
{
|
||||
/* TODO: figure out how i want to load the texture */
|
||||
foundTexture = true;
|
||||
didSomething = true;
|
||||
}
|
||||
}
|
||||
if (didSomething)
|
||||
{
|
||||
pushAttributes();
|
||||
if (foundTexture)
|
||||
{
|
||||
#ifdef DEBUGGL
|
||||
cout << " glEnable(GL_TEXTURE_2D)" << endl;
|
||||
#endif
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUGGL
|
||||
cout << " glDisable(GL_TEXTURE_2D)" << endl;
|
||||
#endif
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WFMtl::pushAttributes()
|
||||
{
|
||||
if (m_attributesPushed)
|
||||
return;
|
||||
m_attributesPushed = true;
|
||||
#ifdef DEBUGGL
|
||||
cout << " glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT)" << endl;
|
||||
#endif
|
||||
glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT);
|
||||
}
|
||||
|
||||
void WFMtl::renderEnd(const string & mtlname)
|
||||
@ -142,6 +240,12 @@ void WFMtl::renderEnd(const string & mtlname)
|
||||
map< string, vector< vector<string> > >::iterator it = m_data.find(mtlname);
|
||||
if (it == m_data.end())
|
||||
return;
|
||||
/* TODO: end the material at it->second */
|
||||
if (m_attributesPushed)
|
||||
{
|
||||
#ifdef DEBUGGL
|
||||
cout << " glPopAttrib()" << endl;
|
||||
#endif
|
||||
glPopAttrib();
|
||||
}
|
||||
}
|
||||
|
||||
|
4
WFMtl.hh
4
WFMtl.hh
@ -18,8 +18,10 @@ private:
|
||||
int filesize(const char * filename);
|
||||
void processInputLine(const std::string & input);
|
||||
std::string stripFirstToken(std::string & input);
|
||||
void pushAttributes();
|
||||
|
||||
/* variables */
|
||||
std::map< std::string, std::vector< std::vector<std::string> > > m_data;
|
||||
string m_currentMaterialName;
|
||||
std::string m_currentMaterialName;
|
||||
bool m_attributesPushed;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user