From 452796bf81852b2357f831abc7c4c31dd0bb59e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Pinto?= Date: Thu, 23 May 2024 02:39:22 +0100 Subject: [PATCH] fix: grayscale textures --- engine/src/model.cpp | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/engine/src/model.cpp b/engine/src/model.cpp index 10c0533..824bab6 100644 --- a/engine/src/model.cpp +++ b/engine/src/model.cpp @@ -118,7 +118,7 @@ bool Model::loadTexture() { // Load image data int width, height, num_channels; unsigned char* image_data = stbi_load(this->texture_filepath.data(), &width, - &height, &num_channels, 3); + &height, &num_channels, STBI_rgb); if (!image_data) { std::cerr << "Failed to load texture: " << this->texture_filepath @@ -136,29 +136,9 @@ bool Model::loadTexture() { GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - // Determine the correct format - GLenum format; - switch (num_channels) { - case 1: - format = GL_RED; - break; - case 3: - format = GL_RGB; - break; - case 4: - format = GL_RGBA; - break; - default: { - // Free image data before returning - stbi_image_free(image_data); - std::cerr << "Unsupported number of channels: " << num_channels - << std::endl; - return false; - } - } - + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // Upload data to GPU - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data); glGenerateMipmap(GL_TEXTURE_2D);