diff --git a/.gitignore b/.gitignore index 143fbe6..9362932 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ err.txt *.blend1 /projects/meshes/penguin-lowpoly-poikilos-redochanges-messupback.blend /projects/meshes/penguin-lowpoly-poikilos-redochanges.blend +/build/debug/b3view diff --git a/Engine.cpp b/Engine.cpp index 5260e80..95aae47 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -716,21 +716,30 @@ bool Engine::reloadTexture() bool result = false; if (this->m_LoadedTexturePath.length() > 0) { if (wcslen(this->m_UserInterface->texturePathEditBox->getText()) == 0) - result = loadTexture(this->m_UserInterface->texturePathEditBox->getText()); + result = loadTexture(this->m_UserInterface->texturePathEditBox->getText(), true); else - result = loadTexture(this->m_LoadedTexturePath); + result = loadTexture(this->m_LoadedTexturePath, true); } return result; } -bool Engine::loadTexture(const wstring& fileName) +bool Engine::loadTexture(const wstring& fileName, bool reload) { bool ret = false; if (m_LoadedMesh != nullptr) { ITexture* texture = this->m_Driver->getTexture(fileName.c_str()); + if (reload) { + // The texture may already have been read from storage, so: + this->m_Driver->removeTexture(texture); + texture = this->m_Driver->getTexture(fileName.c_str()); + } if (texture != nullptr) { m_LoadedMesh->setMaterialTexture(0, texture); ret = true; + debug() << "* loaded " << "" << std::endl; + } + else { + debug() << "* failed to load " << "" << std::endl; } this->m_LoadedTexturePath = fileName; std::cerr << "Setting texture path box to " << Utility::toString(this->m_LoadedTexturePath) << std::endl; diff --git a/Engine.h b/Engine.h index 16f54b1..00dc7be 100644 --- a/Engine.h +++ b/Engine.h @@ -86,7 +86,7 @@ public: bool reloadMesh(); std::wstring saveMesh(const irr::io::path path, const std::string& nameOrBlank, const std::string& extension); bool reloadTexture(); - bool loadTexture(const std::wstring& fileName); + bool loadTexture(const std::wstring& fileName, bool reload); void setMeshDisplayMode(bool wireframe = false, bool lighting = false, bool textureInterpolation = true); bool isAnimating(); void playAnimation(); diff --git a/UserInterface.cpp b/UserInterface.cpp index 53aa6f1..34c022e 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -796,11 +796,11 @@ bool UserInterface::loadNextTexture(int direction) if (lastTexture.length() > 0) { if (direction < 0) { cerr << "loading the previous texture..."; - ret = this->m_Engine->loadTexture(prevTexture); + ret = this->m_Engine->loadTexture(prevTexture, false); } else if (direction > 0) { cerr << "loading the next texture..."; - ret = this->m_Engine->loadTexture(nextTexture); + ret = this->m_Engine->loadTexture(nextTexture, false); } else { // If direction is 0 (such as when a model is loaded that has @@ -808,12 +808,13 @@ bool UserInterface::loadNextTexture(int direction) if (this->m_Engine->m_LoadedTexturePath.length() > 0) { cerr << "using a specified texture..."; ret = this->m_Engine->loadTexture( - this->m_Engine->m_LoadedTexturePath + this->m_Engine->m_LoadedTexturePath, + false ); } else if (this->m_MatchingTextures.size() >= 1) { cerr << "loading matching texture..."; - ret = this->m_Engine->loadTexture(firstTexture); + ret = this->m_Engine->loadTexture(firstTexture, false); } else { ret = true; @@ -824,7 +825,8 @@ bool UserInterface::loadNextTexture(int direction) else if (this->m_Engine->m_LoadedTexturePath.length() > 0) { cerr << "loading the first texture..."; ret = this->m_Engine->loadTexture( - this->m_Engine->m_LoadedTexturePath + this->m_Engine->m_LoadedTexturePath, + false ); } } else @@ -1156,7 +1158,7 @@ bool UserInterface::OnEvent(const SEvent& event) case UIE_LOADTEXTUREDIALOG: { IGUIFileOpenDialog* fileOpenDialog = static_cast(ge->Caller); - m_Engine->loadTexture(fileOpenDialog->getFileName()); + m_Engine->loadTexture(fileOpenDialog->getFileName(), true); } break; default: @@ -1191,7 +1193,7 @@ bool UserInterface::OnEvent(const SEvent& event) break; case UIE_TEXTUREPATHEDITBOX: if (this->m_Engine->m_LoadedMesh != nullptr) { - this->m_Engine->loadTexture(texturePathEditBox->getText()); + this->m_Engine->loadTexture(texturePathEditBox->getText(), false); } break; case UIE_FPSEDITBOX: diff --git a/build.sh b/build.sh index 5e509fb..8faeb54 100755 --- a/build.sh +++ b/build.sh @@ -91,7 +91,7 @@ if [ -f "$$OUT_BIN" ]; then exit 1 fi fi -g++ -o build/b3view $OBJDIR/main.o $OBJDIR/Engine.o $OBJDIR/EventHandler.o $OBJDIR/UserInterface.o $OBJDIR/Debug.o $OBJDIR/View.o $OBJDIR/CGUITTFont.o $OBJDIR/Utility.o $OBJDIR/settings.o -lIrrlicht -lX11 -lGL -lXxf86vm -lXcursor -lstdc++fs -lfreetype +g++ -o $OUT_BIN $OBJDIR/main.o $OBJDIR/Engine.o $OBJDIR/EventHandler.o $OBJDIR/UserInterface.o $OBJDIR/Debug.o $OBJDIR/View.o $OBJDIR/CGUITTFont.o $OBJDIR/Utility.o $OBJDIR/settings.o -lIrrlicht -lX11 -lGL -lXxf86vm -lXcursor -lstdc++fs -lfreetype if [ $? -ne 0 ]; then cat <