Commit 31181189 authored by Anakin's avatar Anakin
Browse files

some fixes

parent 9b3d12df
...@@ -326,52 +326,54 @@ void OpenGLController::updateScene() ...@@ -326,52 +326,54 @@ void OpenGLController::updateScene()
// tell sampler to use texture unit 0 // tell sampler to use texture unit 0
glUniform1i(gluiSamplerID, 0); glUniform1i(gluiSamplerID, 0);
int instanceOffset(0); if (vModels != NULL)
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
{ {
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!) int instanceOffset(0);
if (vModels->at(modelIndex)->type == null ||
vModels->at(modelIndex)->type == bone || for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
for (auto& segIt : vModels->at(modelIndex)->segmLst)
{ {
// give texture to the shader // skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex; if (vModels->at(modelIndex)->type == null ||
vModels->at(modelIndex)->type == bone ||
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
for (auto& segIt : vModels->at(modelIndex)->segmLst)
{
// give texture to the shader
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, GL_TEXTURE_2D,
0, 0,
vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB, vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB,
vTextures[tempTexIndex]->width, vTextures[tempTexIndex]->width,
vTextures[tempTexIndex]->height, vTextures[tempTexIndex]->height,
0, 0,
vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR, vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE,
vTextures[tempTexIndex]->data->data() vTextures[tempTexIndex]->data->data()
); );
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
// give the MVP to the shader // give the MVP to the shader
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]); glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
// calculate the number of vertex // calculate the number of vertex
unsigned int vertexCount(0); unsigned int vertexCount(0);
for (auto& it : segIt->meshIndices) for (auto& it : segIt->meshIndices)
vertexCount += (it.size() - 2) * 3; vertexCount += (it.size() - 2) * 3;
glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount); glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount);
// increase the offset // increase the offset
instanceOffset += vertexCount; instanceOffset += vertexCount;
}
} }
} }
glfwSwapBuffers(pWindow); glfwSwapBuffers(pWindow);
glfwPollEvents(); glfwPollEvents();
} }
......
...@@ -17,7 +17,9 @@ int main(int argc, char** argv) ...@@ -17,7 +17,9 @@ int main(int argc, char** argv)
else else
scene = OpenGLController::getInstance(); scene = OpenGLController::getInstance();
#ifdef _DEBUG
scene->loadMsh("..\\Release\\Msh\\quadPoly.msh"); scene->loadMsh("..\\Release\\Msh\\quadPoly.msh");
#endif // DEBUG
do { do {
scene->updateScene(); scene->updateScene();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment