Skip to content
Snippets Groups Projects
Commit 211b406c authored by Anakin's avatar Anakin
Browse files

dynamical decide whether to use the given texture or solid red

parent c3d73895
Branches
Tags
No related merge requests found
......@@ -71,5 +71,6 @@ private:
public:
std::vector<GLfloat> getVertex() const;
std::vector<GLfloat> getUV() const;
std::list<std::string> getTexture() const;
};
......@@ -148,9 +148,10 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
if (!strcmp("PRNT", (*it)->name))
{
fsMesh.seekg((*it)->position);
char tempName[33] = { 0 };
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
dataDestination->parent = tempName;
char* buffer = new char[(*it)->size];
fsMesh.read(buffer, (*it)->size);
dataDestination->parent = buffer;
delete buffer;
continue;
}
......@@ -160,6 +161,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
char* buffer = new char[(*it)->size];
fsMesh.read(buffer, (*it)->size);
dataDestination->name = buffer;
delete buffer;
continue;
}
......@@ -373,6 +375,7 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
char* buffer = new char[(*it)->size];
fsMesh.read(buffer, (*it)->size);
dataDestination->texture = buffer;
delete buffer;
continue;
}
......@@ -491,6 +494,16 @@ std::vector<GLfloat> Object::getUV() const
return tempData;
}
std::list<std::string> Object::getTexture() const
{
std::list<std::string> tempData;
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
tempData.push_back((*it)->texture);
return tempData;
}
/////////////////////////////////////////////////////////////////////////
// public functions
......
......@@ -296,12 +296,22 @@ void OpenGLController::loadMsh(const char * path)
glGenTextures(1, &gluiTextureID);
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
// if texture && open ok, then
//TextureTGA tempTex(TEXTURE_NAME);
//glTexImage2D(GL_TEXTURE_2D, 0, tempTex.hasAlpha() ? GL_RGBA : GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data());
// else
std::list<std::string> listTextures;
try
{
if (listTextures.empty())
throw std::invalid_argument("no texture names");
TextureTGA tempTex(listTextures.front().c_str());
glTexImage2D(GL_TEXTURE_2D, 0, tempTex.hasAlpha() ? GL_RGBA : GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data());
}
catch (std::invalid_argument e)
{
GLubyte solidColor[4] = { 255,0,0,255 };
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const GLvoid*)solidColor);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment