From 2f83d37e124015b1855df522596a940076b2b8b3 Mon Sep 17 00:00:00 2001 From: Anakin Date: Tue, 8 Nov 2016 21:28:24 +0100 Subject: [PATCH] fixed the problem, next solve texture name is taken only from the first element, move some code around --- MshViewer/Source/OpenGlController.cpp | 40 ++++++++++++++------------- MshViewer/main.cpp | 4 +-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index afe0b2f..62ecaac 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -119,6 +119,12 @@ void OpenGLController::processInit() // generate texture glGenTextures(1, &gluiTextureID); glBindTexture(GL_TEXTURE_2D, gluiTextureID); + + // set some texture parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } void OpenGLController::startGLFW() @@ -266,6 +272,21 @@ void OpenGLController::updateScene() for (int modelIndex = 0; modelIndex < vModels.size(); modelIndex++) { + // give texture to the shader + glTexImage2D(GL_TEXTURE_2D, + 0, + vTextures[modelIndex]->alpha ? GL_RGBA : GL_RGB, + vTextures[modelIndex]->width, + vTextures[modelIndex]->height, + 0, + vTextures[modelIndex]->alpha ? GL_BGRA : GL_BGR, + GL_UNSIGNED_BYTE, + vTextures[modelIndex]->data->data() + ); + + glGenerateMipmap(GL_TEXTURE_2D); + + // give the MVP to the shader glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]); glDrawArrays(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize); @@ -361,23 +382,4 @@ void OpenGLController::loadMsh(const char * path) vTextures.push_back(tempData); } - - glTexImage2D(GL_TEXTURE_2D, - 0, - vTextures.front()->alpha ? GL_RGBA : GL_RGB, - vTextures.front()->width, - vTextures.front()->height, - 0, - vTextures.front()->alpha ? GL_BGRA : GL_BGR, - GL_UNSIGNED_BYTE, - vTextures.front()->data->data() - ); - - // set some texture parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glGenerateMipmap(GL_TEXTURE_2D); - } diff --git a/MshViewer/main.cpp b/MshViewer/main.cpp index 2f52e99..024d5cb 100644 --- a/MshViewer/main.cpp +++ b/MshViewer/main.cpp @@ -20,8 +20,8 @@ int main(int argc, char** argv) else scene = OpenGLController::getInstance(); - //scene->loadMsh("..\\Release\\Msh\\multiModTex.msh"); - scene->loadMsh("..\\Release\\Msh\\cubeTex.msh"); + scene->loadMsh("..\\Release\\Msh\\multiModTex.msh"); + //scene->loadMsh("..\\Release\\Msh\\cubeTex.msh"); do { scene->updateScene();