some fixes

This commit is contained in:
Anakin 2016-12-02 13:00:38 +01:00
parent 9b3d12dfeb
commit 3118118953
2 changed files with 38 additions and 34 deletions

View File

@ -326,52 +326,54 @@ void OpenGLController::updateScene()
// tell sampler to use texture unit 0
glUniform1i(gluiSamplerID, 0);
int instanceOffset(0);
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
if (vModels != NULL)
{
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
if (vModels->at(modelIndex)->type == null ||
vModels->at(modelIndex)->type == bone ||
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
int instanceOffset(0);
for (auto& segIt : vModels->at(modelIndex)->segmLst)
for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
{
// give texture to the shader
std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
// skip null, bones, shadowMesh, hidden things (don't increase textrue index!!)
if (vModels->at(modelIndex)->type == null ||
vModels->at(modelIndex)->type == bone ||
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
glTexImage2D(
GL_TEXTURE_2D,
0,
vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB,
vTextures[tempTexIndex]->width,
vTextures[tempTexIndex]->height,
0,
vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE,
vTextures[tempTexIndex]->data->data()
);
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;
glGenerateMipmap(GL_TEXTURE_2D);
glTexImage2D(
GL_TEXTURE_2D,
0,
vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB,
vTextures[tempTexIndex]->width,
vTextures[tempTexIndex]->height,
0,
vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE,
vTextures[tempTexIndex]->data->data()
);
// give the MVP to the shader
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
glGenerateMipmap(GL_TEXTURE_2D);
// calculate the number of vertex
unsigned int vertexCount(0);
for (auto& it : segIt->meshIndices)
vertexCount += (it.size() - 2) * 3;
// give the MVP to the shader
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
// calculate the number of vertex
unsigned int vertexCount(0);
for (auto& it : segIt->meshIndices)
vertexCount += (it.size() - 2) * 3;
glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount);
glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount);
// increase the offset
instanceOffset += vertexCount;
// increase the offset
instanceOffset += vertexCount;
}
}
}
glfwSwapBuffers(pWindow);
glfwPollEvents();
}

View File

@ -17,7 +17,9 @@ int main(int argc, char** argv)
else
scene = OpenGLController::getInstance();
#ifdef _DEBUG
scene->loadMsh("..\\Release\\Msh\\quadPoly.msh");
#endif // DEBUG
do {
scene->updateScene();