aboutsummaryrefslogtreecommitdiff
path: root/src/misc.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/misc.zig')
-rw-r--r--src/misc.zig49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/misc.zig b/src/misc.zig
index e58fb30..d6063eb 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -317,7 +317,7 @@ fn check(comptime errorString: fn (c_uint) callconv(.C) [*c]const u8,
}
/// Load PNG file into an OpenGL buffer and return it.
-export fn loadTexture(filename: [*:0]const u8) c.GLuint {
+export fn loadTexture(filename: [*:0]const u8) u32 {
const file = readFile(cwd(), data_dir ++ "textures{c}{s}", .{
sep, filename,
}) catch unreachable;
@@ -327,7 +327,7 @@ export fn loadTexture(filename: [*:0]const u8) c.GLuint {
defer image.deinit(allocator);
const data = @ptrCast([*c]const u8, image.pixels.ptr);
- var texture: c.GLuint = undefined;
+ var texture: u32 = undefined;
c.glGenTextures(1, &texture);
c.glBindTexture(c.GL_TEXTURE_2D, texture);
defer c.glBindTexture(c.GL_TEXTURE_2D, 0);
@@ -335,8 +335,8 @@ 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, image.width);
- const height = @intCast(c.GLint, image.height);
+ const width = @intCast(i32, image.width);
+ const height = @intCast(i32, 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);
@@ -374,3 +374,44 @@ pub fn saveScores(base_dir: []const u8, current: Scores) !void {
defer allocator.free(data);
try dir.writeFile("scores.ini", data);
}
+
+/// OpenGL fog state.
+const Fog = extern struct {
+ color: [4]f32,
+ density: f32,
+ start: f32,
+ end: f32,
+};
+
+/// Set fog effect.
+export fn setFog(fog: *Fog, r: f32, g: f32, b: f32,
+ start: f32, end: f32, density: f32) void {
+ fog.color = .{r, g, b, 1.0};
+ fog.density = density;
+ fog.start = start;
+ fog.end = end;
+ resetFog(fog);
+}
+
+/// Set temporary fog effect.
+export fn tempFog(fog: *Fog, r: f32, g: f32, b: f32) void {
+ const color = [4]f32{r, g, b, 1.0};
+ c.glFogi(c.GL_FOG_MODE, c.GL_LINEAR);
+ c.glFogfv(c.GL_FOG_COLOR, &color);
+ c.glFogf(c.GL_FOG_DENSITY, fog.density);
+ c.glFogi(c.GL_FOG_HINT, c.GL_DONT_CARE);
+ c.glFogf(c.GL_FOG_START, fog.start);
+ c.glFogf(c.GL_FOG_END, fog.end);
+ c.glEnable(c.GL_FOG);
+}
+
+/// Reset fog effect.
+export fn resetFog(fog: *Fog) void {
+ c.glFogi(c.GL_FOG_MODE, c.GL_LINEAR);
+ c.glFogfv(c.GL_FOG_COLOR, &fog.color);
+ c.glFogf(c.GL_FOG_DENSITY, fog.density);
+ c.glFogi(c.GL_FOG_HINT, c.GL_DONT_CARE);
+ c.glFogf(c.GL_FOG_START, fog.start);
+ c.glFogf(c.GL_FOG_END, fog.end);
+ c.glEnable(c.GL_FOG);
+}