twn_textures.c: handle RGB image files
This commit is contained in:
parent
c8469e9416
commit
e093a6d492
@ -41,6 +41,9 @@ void upload_gpu_texture(gpu_texture texture, void *pixels, int channels, int wid
|
|||||||
if (channels == 4) {
|
if (channels == 4) {
|
||||||
format_internal = GL_RGBA8;
|
format_internal = GL_RGBA8;
|
||||||
format = GL_RGBA;
|
format = GL_RGBA;
|
||||||
|
} else if (channels == 3) {
|
||||||
|
format_internal = GL_RGBA8;
|
||||||
|
format = GL_RGB;
|
||||||
} else if (channels == 1) {
|
} else if (channels == 1) {
|
||||||
format_internal = GL_ALPHA;
|
format_internal = GL_ALPHA;
|
||||||
format = GL_ALPHA;
|
format = GL_ALPHA;
|
||||||
|
@ -34,7 +34,7 @@ static SDL_Surface *image_to_surface(const char *path) {
|
|||||||
goto ERR_CANNOT_ALLOCATE_MEM;
|
goto ERR_CANNOT_ALLOCATE_MEM;
|
||||||
|
|
||||||
int width, height, channels;
|
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)
|
if (!image_mem)
|
||||||
goto ERR_CANNOT_READ_IMAGE;
|
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) {
|
static void upload_texture_from_surface(gpu_texture texture, SDL_Surface *surface) {
|
||||||
SDL_LockSurface(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);
|
SDL_UnlockSurface(surface);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user