dynamical decide whether to use the given texture or solid red

This commit is contained in:
Anakin
2016-10-21 18:56:34 +02:00
parent c3d73895c7
commit 211b406c3d
3 changed files with 33 additions and 9 deletions

View File

@@ -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
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);
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);