I decided I have to do some SDL stuff, instead of digging into the windows API.
This is step zero for me… Never did anything with the plethora of graphics / sound etc. possibilities.
What I do not want is a build.zig of 2000 lines with SDL stuff.
So the (for me) cleanest and easiest way is maybe what I saw here: here
(The code on github in the description of the video).
The only riddle I stumbled upon was this:
pub const c = @cImport({
@cInclude("SDL3/SDL.h");
});
Where or where is the location of this? What is the magic behind it?
The magic behind it is the same as C include: The zig compiler will search in the include paths for the header. If these are headers are installed in known locations, it will find them and link them up.
Like @pasta said, it is going away. So you will have to use translate-c in the future. And that will remove some of the magic.
(Btw - following along Handmade Hero using the win32 API from Linux is not too bad either. I burned myself out at an earlier attempt trying to follow along using a different API and language.)
I saw build.zig’s hanging around here and there that were very big (filled with SDL stuff).
Now I have - with the help of some A.I. - a build.zig which is small.
const translate_sdl = b.addTranslateC(.{
.root_source_file = b.path("sdl/include/SDL3/SDL.h"),
.target = target,
.optimize = optimize,
});
translate_sdl.addIncludePath(b.path("sdl/include"));
// exe stuff here...
exe.root_module.addImport("sdl", translate_sdl.createModule());
exe.root_module.addIncludePath(b.path("sdl/include"));
exe.root_module.addLibraryPath(b.path("sdl/lib/x64"));
exe.root_module.linkSystemLibrary("SDL3", .{});
// put SDL3.dll next to lemmix.exe
b.getInstallStep().dependOn(
&b.addInstallBinFile(b.path("sdl/lib/x64/SDL3.dll"), "SDL3.dll").step,
);
// some more stuff here...
I only do not have the zig functions at my disposal.
Magically only this sdl module.
Also with some non-human help I executed: zig translate-c -lc -I sdl\include sdl\include\SDL3\SDL.h > src\sdl.zig
and got a 50.000 lines file which seemed to represent the complete DLL.
Not understanding everything (at all) but with that youtube tutorial I am at least able to have a window and animations running around calling some of the functions inside there.
Remember: sdl noob…