You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A pretty interface to use CSFML in a way that looks Object-Oriented in zig!
What this is
This is a wrapper for CSFML. Theres no problem importing CSFML in Zig, but the resulting code can be a little bit messy.
My goal is to make things close enough to SFML, with nice methods.
This currently for Zig 0.12 (should work with 0.13) and CSFML 2.6.1.
Adding to your project
Add using Zig's package manager like so: zig fetch --save https://github.com/Guigui220D/zig-sfml-wrapper/archive/d5272051a937c8a3756bb96eab8276b76a271de4.tar.gz (replace the commit hash if you want an other version).
Add this to your exe compile in build.zig:
constsfml=@import("sfml"); // AT THE TOP OF THE FILEexe.root_module.addImport("sfml", b.dependency("sfml", .{}).module("sfml"));
sfml.link(exe);
Note: Your project must know the location of the CSFML2.6.1 include, lib, and binaries directories for successful building and running. For more information, please refer to the wiki 👇
Check the wiki for more details on how to compile your project or the examples.
Small example
This is a small example of how you use this sfml wrapper:
//! This is a translation of the c++ code the sfml website gives you to test if SFML works//! for instance, in this page: https://www.sfml-dev.org/tutorials/2.6/start-vc.phpconstsf=struct {
constsfml=@import("sfml");
usingnamespacesfml;
usingnamespacesfml.graphics;
};
pubfnmain() !void {
varwindow=trysf.RenderWindow.createDefault(.{ .x=200, .y=200 }, "SFML works!");
deferwindow.destroy();
varshape=trysf.CircleShape.create(100.0);
defershape.destroy();
shape.setFillColor(sf.Color.Green);
while (window.isOpen()) {
while (window.pollEvent()) |event| {
if (event==.closed)
window.close();
}
window.clear(sf.Color.Black);
window.draw(shape, null);
window.display();
}
}
Most of the classes are wrapped and you should be able to write games with this wrapper.
The network module is a recent addition and does not contain all classes yet (HTTP, FTP, ...).
Threads are not available yet.