read msh in,

handle non UVed msh,
next test UVed msh + dynamical switch between UVed/not UVed
This commit is contained in:
Anakin 2016-10-17 17:49:44 +02:00
parent e583c361ec
commit c3d73895c7
2 changed files with 29 additions and 16 deletions

View File

@ -34,6 +34,7 @@ Object::Object(const char* path)
if (!strcmp("MODL", (*it)->name))
{
Modl* tempModl = new Modl;
setModlDefault(tempModl);
// get all subchunks
std::list<ChunkHeader*> tempChunks;
@ -342,9 +343,9 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
}
std::cout << "vertices" << std::endl;
std::cout << "triangles: " << dataDestination->meshSize << std::endl;
for (int i = 0; i < dataDestination->meshSize; i += 3)
std::cout << dataDestination->mesh[i] << " - " << dataDestination->mesh[i + 1] << " - " << dataDestination->mesh[i + 2] << std::endl;
std::cout << dataDestination->mesh[i] << " <> " << dataDestination->mesh[i + 1] << " <> " << dataDestination->mesh[i + 2] << std::endl;
continue;
@ -414,12 +415,18 @@ void Object::readVertex(Modl* dataDestination, std::streampos position)
dataDestination->vertex = new float[tempSize * 3];
for (unsigned int i = 0; i < tempSize; i += 3)
for (unsigned int i = 0; i < tempSize * 3; i += 3)
{
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&dataDestination->vertex[i + 2]), sizeof(float));
}
std::cout << "Vertex number: " << tempSize << std::endl;
for (int i = 0; i < tempSize * 3; i += 3)
std::cout << dataDestination->vertex[i] << " <> " << dataDestination->vertex[i + 1] << " <> " << dataDestination->vertex[i + 2] << std::endl;
}
void Object::readUV(Modl* dataDestination, std::streampos position)
@ -452,11 +459,11 @@ std::vector<GLfloat> Object::getVertex() const
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
{
for (int i = 0; i < (*it)->meshSize; i += 3)
for (unsigned int i = 0; i < (*it)->meshSize; i++)
{
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i]]);
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] + 1]);
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] + 2]);
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3]);
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 1]);
tempData.push_back((GLfloat)(*it)->vertex[(*it)->mesh[i] * 3 + 2]);
}
}
@ -470,8 +477,12 @@ std::vector<GLfloat> Object::getUV() const
for (std::list<Modl*>::const_iterator it = lModls.begin(); it != lModls.end(); it++)
{
if ((*it)->uv == NULL)
{
for (unsigned int i = 0; i < (*it)->meshSize; i++)
tempData.push_back(1.0);
continue;
for (int i = 0; i < (*it)->meshSize; i++)
}
for (unsigned int i = 0; i < (*it)->meshSize; i++)
{
tempData.push_back((GLfloat)(*it)->uv[(*it)->mesh[i]]);
}

View File

@ -285,9 +285,7 @@ void OpenGLController::loadMsh(const char * path)
{
Object obj(path);
vfVertices = obj.getVertex();
vfUV = loadUV();
//vfUV = obj.getUV();
vfUV = obj.getUV();
}
catch (std::invalid_argument e)
{
@ -295,13 +293,16 @@ void OpenGLController::loadMsh(const char * path)
exit(1);
}
//vfVertices = loadData();
//vfUV = loadUV();
glGenTextures(1, &gluiTextureID);
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
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());
// 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);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@ -324,4 +325,5 @@ void OpenGLController::loadMsh(const char * path)
vfUV.data(),
GL_STATIC_DRAW
);
}