From: Steinar H. Gunderson Date: Mon, 1 Oct 2012 16:45:20 +0000 (+0200) Subject: Split image loading from texture generation. X-Git-Tag: 1.0~471 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=4f8d4ab8bd84bfbe7329a1afae3034ec2937bbb5 Split image loading from texture generation. --- diff --git a/main.cpp b/main.cpp index 4054636..256b29e 100644 --- a/main.cpp +++ b/main.cpp @@ -138,7 +138,7 @@ void mouse(int x, int y) update_hsv(); } -void load_texture(const char *filename) +unsigned char *load_image(const char *filename, unsigned *w, unsigned *h) { SDL_Surface *img = IMG_Load(filename); if (img == NULL) { @@ -177,17 +177,30 @@ void load_texture(const char *filename) } SDL_UnlockSurface(img); + *w = img->w; + *h = img->h; + + SDL_FreeSurface(img); + + return dst_pixels; +} + +void load_texture(const char *filename) +{ + unsigned w, h; + unsigned char *pixels = load_image(filename, &w, &h); + #if 1 // we will convert to sRGB in the shader - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img->w, img->h, 0, GL_RGB, GL_UNSIGNED_BYTE, dst_pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); check_error(); #else // implicit sRGB conversion in hardware - glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8, img->w, img->h, 0, GL_RGB, GL_UNSIGNED_BYTE, dst_pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); check_error(); #endif - free(dst_pixels); - SDL_FreeSurface(img); + + free(pixels); } void write_ppm(const char *filename, unsigned char *screenbuf)