Handmade Penguin - companion to Casey Muratori’s amazing Handmade Hero series, for Linux. https://davidgow.net/handmadepenguin/default.html
Try to use https://github.com/SpexGuy/Zig-ImGui
These chapters from Handmade Penguing is exactly what I need: https://davidgow.net/handmadepenguin/ch7.html https://davidgow.net/handmadepenguin/ch8.html https://davidgow.net/handmadepenguin/ch9.html https://davidgow.net/handmadepenguin/ch12.html https://davidgow.net/handmadepenguin/ch19.html
Which approach is better - SDL_QueueAudio or SDL_AudioSpec.callback? https://wiki.libsdl.org/SDL2/SDL_AudioSpec https://wiki.libsdl.org/SDL2/SDL_QueueAudio SDL_QueueAudio is simpler to use - you don’t have to maintain a ringbuffer of audio data. But it could be more complicated to do the "optimistic" writing of audio: https://davidgow.net/handmadepenguin/ch12.html
We might want to "optimistically" write an extra frame or two's worth of audio data into our buffer, and then overwrite it when we actually render the next frame. This would give us some leeway if the game ran slowly. While this can be done with SDL_QueueAudio() and its companion function SDL_ClearQueuedAudio(), it is much harder to get right.
It seems that the callback function gives more control, so I will use that.
Game defines a callback method for filling a sound buffer. For now the callback receives the target buffer and requested sample count.
Platform initializes a persistent ring buffer for storing the received sound data. Platform executes the callback with a temporary buffer. Platform writes sound data from the temporary buffer to the ring buffer. SDL reads the sound data from the ring buffer via another callback, defined in the platform.
https://wiki.libsdl.org/SDL2/CategoryAudio https://github.com/jakebesworth/Simple-SDL2-Audio/blob/master/src/audio.c
https://wiki.libsdl.org/SDL2/SDL_OpenAudioDevice https://wiki.libsdl.org/SDL2/SDL_AudioFormat https://wiki.libsdl.org/SDL2/SDL_PauseAudioDevice https://wiki.libsdl.org/SDL2/SDL_CloseAudioDevice https://github.com/MasterQ32/SDL.zig/blob/fbe5f599c65b7a5642990443b2a686d1c53a4985/src/wrapper/sdl.zig#L2573 https://wiki.libsdl.org/SDL2/SDL_MixAudioFormat
/home/reinis/dev/learn/zig/zig_sdl_platform/zig-out/bin/example: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/libpthread.so.0) /home/reinis/dev/learn/zig/zig_sdl_platform/zig-out/bin/example: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_ABI_DT_RELR' not found (required by /nix/store/yaz7pyf0ah88g2v505l38n0f3wg2vzdj-glibc-2.37-8/lib/librt.so.1) /home/reinis/dev/learn/zig/zig_sdl_platform/zig-out/bin/example: /nix/store/vnwdak3n1w2jjil119j65k8mw1z23p84-glibc-2.35-224/lib/libc.so.6: version `GLIBC_2.36' not found (required by /nix/store/0d4xl0xk1g0w41yqyd64jvzbip5lhfig-libXdmcp-1.1.3/lib/libXdmcp.so.6)
This could be related: NixOS/nixpkgs#228899
Checked that the application builds and runs OK on non-NixOS.
A bug has been registered against Zig: ziglang/zig#15898
For now I will use nixpkgs 22.11 (same as my NixOS config) as a workaround.