diff --git a/src/rendering/twn_gl_15_gpu_texture.c b/src/rendering/twn_gl_15_gpu_texture.c index d8f5591..f4cad53 100644 --- a/src/rendering/twn_gl_15_gpu_texture.c +++ b/src/rendering/twn_gl_15_gpu_texture.c @@ -41,6 +41,9 @@ void upload_gpu_texture(gpu_texture texture, void *pixels, int channels, int wid if (channels == 4) { format_internal = GL_RGBA8; format = GL_RGBA; + } else if (channels == 3) { + format_internal = GL_RGBA8; + format = GL_RGB; } else if (channels == 1) { format_internal = GL_ALPHA; format = GL_ALPHA; diff --git a/src/twn_textures.c b/src/twn_textures.c index 5688a49..94c2873 100644 --- a/src/twn_textures.c +++ b/src/twn_textures.c @@ -34,7 +34,7 @@ static SDL_Surface *image_to_surface(const char *path) { goto ERR_CANNOT_ALLOCATE_MEM; int width, height, channels; - void *image_mem = stbi_load_from_memory(file_mem, (int)file_size, &width, &height, &channels, 4); + void *image_mem = stbi_load_from_memory(file_mem, (int)file_size, &width, &height, &channels, 0); if (!image_mem) goto ERR_CANNOT_READ_IMAGE; @@ -123,7 +123,7 @@ static void add_new_atlas(struct texture_cache *cache) { static void upload_texture_from_surface(gpu_texture texture, SDL_Surface *surface) { SDL_LockSurface(surface); - upload_gpu_texture(texture, surface->pixels, 4, surface->w, surface->h); + upload_gpu_texture(texture, surface->pixels, surface->format->BytesPerPixel, surface->w, surface->h); SDL_UnlockSurface(surface); }