Add the logo.

This commit is contained in:
IntegratedQuantum 2024-05-24 20:53:17 +02:00
parent 8db5c00857
commit f5544a4fee
3 changed files with 26 additions and 0 deletions

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -1879,6 +1879,19 @@ pub const Image = struct {
stb_image.stbi_image_free(data);
return result;
}
pub fn readUnflippedFromFile(allocator: NeverFailingAllocator, path: []const u8) !Image {
var result: Image = undefined;
var channel: c_int = undefined;
const nullTerminatedPath = std.fmt.allocPrintZ(main.stackAllocator.allocator, "{s}", .{path}) catch unreachable; // TODO: Find a more zig-friendly image loading library.
errdefer main.stackAllocator.free(nullTerminatedPath);
const data = stb_image.stbi_load(nullTerminatedPath.ptr, @ptrCast(&result.width), @ptrCast(&result.height), &channel, 4) orelse {
return error.FileNotFound;
};
main.stackAllocator.free(nullTerminatedPath);
result.imageData = allocator.dupe(Color, @as([*]Color, @ptrCast(data))[0..result.width*result.height]);
stb_image.stbi_image_free(data);
return result;
}
pub fn exportToFile(self: Image, path: []const u8) !void {
const nullTerminated = main.stackAllocator.dupeZ(u8, path);
defer main.stackAllocator.free(nullTerminated);

View File

@ -312,6 +312,19 @@ pub fn init() void {
c.glfwWindowHint(c.GLFW_CONTEXT_VERSION_MINOR, 6);
window = c.glfwCreateWindow(width, height, "Cubyz", null, null) orelse @panic("Failed to create GLFW window");
iconBlock: {
const image = main.graphics.Image.readUnflippedFromFile(main.stackAllocator, "logo.png") catch |err| {
std.log.err("Error loading logo: {s}", .{@errorName(err)});
break :iconBlock;
};
defer image.deinit(main.stackAllocator);
const glfwImage: c.GLFWimage = .{
.pixels = @ptrCast(image.imageData.ptr),
.width = image.width,
.height = image.height,
};
c.glfwSetWindowIcon(window, 1, &glfwImage);
}
_ = c.glfwSetKeyCallback(window, GLFWCallbacks.keyCallback);
_ = c.glfwSetCharCallback(window, GLFWCallbacks.charCallback);