dynamical decide whether to use the given texture or solid red
This commit is contained in:
parent
c3d73895c7
commit
211b406c3d
|
@ -71,5 +71,6 @@ private:
|
||||||
public:
|
public:
|
||||||
std::vector<GLfloat> getVertex() const;
|
std::vector<GLfloat> getVertex() const;
|
||||||
std::vector<GLfloat> getUV() 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))
|
if (!strcmp("PRNT", (*it)->name))
|
||||||
{
|
{
|
||||||
fsMesh.seekg((*it)->position);
|
fsMesh.seekg((*it)->position);
|
||||||
char tempName[33] = { 0 };
|
char* buffer = new char[(*it)->size];
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
|
fsMesh.read(buffer, (*it)->size);
|
||||||
dataDestination->parent = tempName;
|
dataDestination->parent = buffer;
|
||||||
|
delete buffer;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,6 +161,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
||||||
char* buffer = new char[(*it)->size];
|
char* buffer = new char[(*it)->size];
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, (*it)->size);
|
||||||
dataDestination->name = buffer;
|
dataDestination->name = buffer;
|
||||||
|
delete buffer;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,6 +375,7 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
|
||||||
char* buffer = new char[(*it)->size];
|
char* buffer = new char[(*it)->size];
|
||||||
fsMesh.read(buffer, (*it)->size);
|
fsMesh.read(buffer, (*it)->size);
|
||||||
dataDestination->texture = buffer;
|
dataDestination->texture = buffer;
|
||||||
|
delete buffer;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,6 +494,16 @@ std::vector<GLfloat> Object::getUV() const
|
||||||
return tempData;
|
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
|
// public functions
|
||||||
|
|
|
@ -296,12 +296,22 @@ void OpenGLController::loadMsh(const char * path)
|
||||||
glGenTextures(1, &gluiTextureID);
|
glGenTextures(1, &gluiTextureID);
|
||||||
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
||||||
|
|
||||||
// if texture && open ok, then
|
std::list<std::string> listTextures;
|
||||||
//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
|
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 };
|
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);
|
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);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
|
Loading…
Reference in New Issue