diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2018-05-03 22:55:10 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2018-05-04 20:16:23 +0100 |
commit | 8a52a98fb156e51bd85b6dfade433cfcc6557dc6 (patch) | |
tree | 41c22b8e4cb3340d6bf347e9b84b1f759924e202 | |
parent | 74cda738f8971d90aef752f3efbbd5f2735213d4 (diff) | |
download | faqe-8a52a98fb156e51bd85b6dfade433cfcc6557dc6.tar.gz faqe-8a52a98fb156e51bd85b6dfade433cfcc6557dc6.tar.xz faqe-8a52a98fb156e51bd85b6dfade433cfcc6557dc6.zip |
Cleanup and fix texture loading
-rw-r--r-- | tex.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -13,24 +13,26 @@ GLuint png2tex(FILE *f) { png_image pi = { .version = PNG_IMAGE_VERSION }; unsigned char *data; - size_t size; + size_t stride, size; GLuint id; assert(f != NULL); png_image_begin_read_from_stdio(&pi, f); pi.format = PNG_FORMAT_RGB; - size = sizeof *data * 3 * pi.width * pi.height; + stride = sizeof *data * PNG_IMAGE_SAMPLE_CHANNELS(pi.format) * pi.width; + stride = (stride + 3) & ~(size_t)3; + size = stride * pi.height; data = emalloc(size); - png_image_finish_read(&pi, NULL, data, size / pi.height, NULL); + png_image_finish_read(&pi, NULL, data, stride, NULL); gl_tex_gen(1, &id); gl_tex_bind(GL_TEXTURE_2D, id); gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - gl_tex_img2d(GL_TEXTURE_2D, 0, GL_RGB, pi.width, pi.height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + gl_tex_parami(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + gl_tex_img2d(GL_TEXTURE_2D, 0, GL_SRGB, pi.width, pi.height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); gl_tex_genmip(GL_TEXTURE_2D); free(data); |