From 109e426a35a43b4d3631e518eb0ca9653456a3a4 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 10 Feb 2022 19:37:29 +0200 Subject: [PATCH] bugfix --- assetManager.cpp | 2 +- imageAsset.h | 5 ++++- imageReader.cpp | 5 +++-- texture.cpp | 12 ++++++++---- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/assetManager.cpp b/assetManager.cpp index 0df8b43..831a3d7 100644 --- a/assetManager.cpp +++ b/assetManager.cpp @@ -24,7 +24,7 @@ namespace vb01{ vector imageFormats = vector{"png", "jpg", "jpeg"}; if(*find(imageFormats.begin(), imageFormats.end(), format) == format) - assets.push_back(ImageReader::getSingleton()->readImage(path, true)); + assets.push_back(ImageReader::getSingleton()->readImage(path, false)); } Asset* AssetManager::getAsset(string path){ diff --git a/imageAsset.h b/imageAsset.h index b7c8c14..54a4a8c 100644 --- a/imageAsset.h +++ b/imageAsset.h @@ -5,12 +5,15 @@ namespace vb01{ struct ImageAsset : public Asset{ - ImageAsset(std::string path, u8 *image){ + ImageAsset(std::string path, u8 *image, int width, int height){ this->path = path; this->image = image; + this->width = width; + this->height = height; } u8 *image; + int width, height; }; } diff --git a/imageReader.cpp b/imageReader.cpp index 82594f7..31ff70f 100644 --- a/imageReader.cpp +++ b/imageReader.cpp @@ -16,7 +16,8 @@ namespace vb01{ ImageAsset* ImageReader::readImage(string path, bool flip){ stbi_set_flip_vertically_on_load(flip); - u8 *data = stbi_load(path.c_str(), nullptr, nullptr, nullptr, 0); - return new ImageAsset(path, data); + int width, height, numChannels; + u8 *data = stbi_load(path.c_str(), &width, &height, &numChannels, 0); + return new ImageAsset(path, data, width, height); } } diff --git a/texture.cpp b/texture.cpp index 51409a4..d9b0e79 100755 --- a/texture.cpp +++ b/texture.cpp @@ -77,9 +77,11 @@ namespace vb01{ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - u8 *image = ((ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]))->image; + ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]); + width = asset->width; + height = asset->height; - glTexImage2D(GL_TEXTURE_2D, 0, png ? GL_RGBA : GL_RGB, width, height, 0, png ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, image); + glTexImage2D(GL_TEXTURE_2D, 0, png ? GL_RGBA : GL_RGB, width, height, 0, png ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, asset->image); glGenerateMipmap(GL_TEXTURE_2D); } } @@ -100,8 +102,10 @@ namespace vb01{ for(int i = 0; i < 6; i++){ if(!depth){ if(fromFile){ - u8 *image = ((ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]))->image; - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, width, width, 0, GL_RGB, GL_UNSIGNED_BYTE, image); + ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(paths[i]); + width = asset->width; + + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, width, width, 0, GL_RGB, GL_UNSIGNED_BYTE, asset->image); } else glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, width, width, 0, GL_RGB, GL_UNSIGNED_INT, NULL);