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 // 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 ||
vModels->at(modelIndex)->type == shadowMesh ||
vModels->at(modelIndex)->renderFlags == 1)
continue;
for (auto& segIt : vModels->at(modelIndex)->segmLst) for (unsigned int modelIndex = 0; modelIndex < vModels->size(); modelIndex++)
{ {
// 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;
glTexImage2D( for (auto& segIt : vModels->at(modelIndex)->segmLst)
GL_TEXTURE_2D, {
0, // give texture to the shader
vTextures[tempTexIndex]->alpha ? GL_RGBA : GL_RGB, std::uint32_t tempTexIndex = segIt->textureIndex >= vTextures.size() ? vTextures.size() - 1 : segIt->textureIndex;
vTextures[tempTexIndex]->width,
vTextures[tempTexIndex]->height,
0,
vTextures[tempTexIndex]->alpha ? GL_BGRA : GL_BGR,
GL_UNSIGNED_BYTE,
vTextures[tempTexIndex]->data->data()
);
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 glGenerateMipmap(GL_TEXTURE_2D);
glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
// calculate the number of vertex // give the MVP to the shader
unsigned int vertexCount(0); glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
for (auto& it : segIt->meshIndices)
vertexCount += (it.size() - 2) * 3; // 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 // increase the offset
instanceOffset += vertexCount; instanceOffset += vertexCount;
}
} }
} }
glfwSwapBuffers(pWindow); glfwSwapBuffers(pWindow);
glfwPollEvents(); glfwPollEvents();
} }

View File

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