I was trying to load texture from file using loadTexture() from zig-raylib, but I constantly get error log saying:
WARNING: FILEIO: [pin.png] Failed to open file
This is my minimal example where I recreated the error:
const std = @import("std");
const rl = @import("raylib");
pub fn main() !void {
const width = 1920;
const height = 1080;
rl.initWindow(width, height, "Platformer");
defer rl.closeWindow();
rl.setTargetFPS(60);
const playerTex = try rl.loadTexture("pin.png");
defer rl.unloadTexture(playerTex);
while(!rl.windowShouldClose()){
rl.beginDrawing();
defer rl.endDrawing();
rl.clearBackground(.black);
rl.drawTexture(playerTex, width/2, height/2, .white);
}
}
I also added this line to my build.zig so my executable directory, includes the image file.
b.getInstallStep().dependOn(&b.addInstallFile(.{.src_path = .{ .owner = b, .sub_path = "src/pin.png" } }, "bin/pin.png").step);
srcandbindir content's shouldn't matter."bin/pin.png"is there so my image and exe are in the same directory zig-out/bin.pin.pngdoes not need to be in eithersrcnorbinit needs to be in the working directory.