mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Add the logo.
This commit is contained in:
parent
8db5c00857
commit
f5544a4fee
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user