summary refs log tree commit diff
path: root/src/misc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.zig')
-rw-r--r--src/misc.zig16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/misc.zig b/src/misc.zig
index 3e1ece0..3307713 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -39,6 +39,7 @@ const tokenize = std.mem.tokenize;
 const al = @import("zeal");
 const gf = @import("gfz");
 const ini = @import("ini");
+const qoi = @import("qoi");
 
 const data_dir = @import("build_options").data_dir ++ [_]u8{ sep };
 const c = @import("cimport.zig");
@@ -322,12 +323,9 @@ export fn loadTexture(filename: [*:0]const u8) c.GLuint {
     }) catch unreachable;
     defer allocator.free(file);
 
-    var data: [*c]u8 = undefined;
-    var w: c_uint = undefined;
-    var h: c_uint = undefined;
-    check(c.lodepng_error_text,
-          c.lodepng_decode32(&data, &w, &h, file.ptr, file.len));
-    defer free(data);
+    var image = qoi.decodeBuffer(allocator, file) catch unreachable;
+    defer image.deinit(allocator);
+    const data = @ptrCast([*c]const u8, image.pixels.ptr);
 
     var texture: c.GLuint = undefined;
     c.glGenTextures(1, &texture);
@@ -337,11 +335,11 @@ export fn loadTexture(filename: [*:0]const u8) c.GLuint {
     c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
     c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR);
 
-    const width = @intCast(c.GLint, w);
-    const height = @intCast(c.GLint, h);
+    const width = @intCast(c.GLint, image.width);
+    const height = @intCast(c.GLint, image.height);
     c.glPixelStorei(c.GL_UNPACK_ALIGNMENT, 1);
     c.glTexImage2D(c.GL_TEXTURE_2D, 0, 4, width, height,
-                 0, c.GL_RGBA, c.GL_UNSIGNED_BYTE, data);
+                   0, c.GL_RGBA, c.GL_UNSIGNED_BYTE, data);
     check(c.gluErrorString,
           c.gluBuild2DMipmaps(c.GL_TEXTURE_2D, 4, width, height,
                               c.GL_RGBA, c.GL_UNSIGNED_BYTE, data));