= Rokol devlog
:sokol: https://github.com/floooh/sokol[Sokol]
:sokol-rs: https://github.com/code-disaster/sokol-rs[sokol-rs]
:bindgen: https://github.com/rust-lang/rust-bindgen[bindgen]
:miniquad: https://github.com/not-fl3/miniquad[miniquad]
:macroquad: https://github.com/not-fl3/macroquad[macroquad]
:tetra: https://github.com/17cupsofcoffee/tetra[tetra]
:fna3d: https://github.com/FNA-XNA/FNA3D[FNA3D]
:rust-fna3d: https://github.com/toyboot4e/rust-fna3d[Rust-FNA3D]
:imgui: https://github.com/ocornut/imgui[ImGUI]
:imgui-rs: https://github.com/imgui-rs/imgui-rs[imgui-rs]
:sdl2: https://docs.rs/sdl2/[rust-sdl2]
== Background
I'm interested in C libraries. They can be used from almost any other programming language. That's cool!
And I made a wrapper of {fna3d}: {rust-fna3d}. It was a lot of work, unfortunatelly, but it worked perfectly. So I'm temped to make more use of C libraries.
== Notes
This time, I'm trying {sokol}. Different from {fna3d}, it is a set of header-only libraries. The only one file does all the jobs? That's awesome!
{sokol-rs} was a pioneer wrapper, and it worked out of the box, but it was outdated. So I'm making another wrapper, naming it Rokol.
NOTE: I would not recommend Rokol for others. There are native Rust frameworks: {miniquad}, {macroquad}, {tetra}, etc. They're awesome!
=== Nov 15, 2020
I started working with Rokol. I was already familar with `build.rs`, so it's been easier than I expected.
The build script is based on one in {sokol-rs}. Many thanks to them!
==== Why did I start making another repository when there was sokol-rs?
Rokol has different styles from {sokol-rs}:
* Rokol uses {bindgen} to create Rust FFI to Sokol.
* Rokol adds helper functions to Sokol.
* Rokol changes function names.
One would use Rokol as this:
[source,rust]
----
use rokol::app as rapp;
rapp::run( .. );
----
Instead of importing all the items in a module:
[source,rust]
----
use sokol::app::*;
sapp_run( .. );
----
..so Rokol is a different library from `sokol-rs`.
=== Nov 17, 2020
Rokol only considers desktop platforms; WebGPU is not available.
Rokol is only tested on macOS (for now).
Rokol compiles conditionally. User has two options to select their renderer:
. Let Rokol select default renderer
. Use feature flag (like `cargo run --feature rokol/glcore33`)
Rokol user would also want to compile conditionally depending on selected backend renderer. That's possible if they add `rokol_ffi` to their `Cargo.toml` and write some build script. See `rokol/build.rs` and `rokol/examples/conditional.rs` for more details.
c.f. https://doc.rust-lang.org/cargo/reference/build-scripts.html[Build Scripts - The Cargo Book]
=== Nov 20, 2020
References
==== Sokol projects
* https://github.com/floooh/sokol[sokol]
+
Simple https://github.com/nothings/stb/blob/master/docs/stb_howto.txt[STB-style] cross-platform libraries for C and C++, written in C.
* https://github.com/floooh/sokol-samples[sokol-samples]
+
Sample code for https://github.com/floooh/sokol
* https://github.com/geertarien/learnopengl-examples[learnopengl-examples]
+
Examples from learnopengl.com, implemented using Sokol libraries.
* https://github.com/floooh/sokol-tools[sokol-tools]
+
https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md[sokol_shdc]: shader-cross-compiler and code-generator for sokol_gfx.h
* https://github.com/floooh/sokol-tools-bin[sokol-tools-bin]
+
Binaries and fips integration for https://github.com/floooh/sokol-tools
I'm not using the cross compiler (for now). It creates C header files which considers conditional compilations, but they're not so handy from Rust.
==== Sokol articles
From https://floooh.github.io/[The Brain Dump]:
* https://floooh.github.io/2017/07/29/sokol-gfx-tour.html[A Tour of sokol_gfx.h] (July 29, 2017)
* https://floooh.github.io/2019/01/12/sokol-apply-pipeline.html[A small sokol_gfx.h API update] (Jan 12, 2019)
* https://floooh.github.io/2020/04/26/sokol-spring-2020-update.html[Sokol headers: spring 2020 update] (April 26, 2020)
=== Dec 3, 2020
I started to commit auto-generated bindings to Sokol in this repository. Now I can see declaration diffs when I update Sokol. Also I made sure to re-build the project when I update Sokol:
.rokol_ffi/build.rs
[source,rust]
----
println!("cargo:rerun-if-changed=sokol");
----
I expected I would get better completions to FFI items on Emacs as bonus. Unfortunately, I did not; probablly I need to remove `include!` from my code to get it (on VSCode, I can goto definitions of FFI items though).
=== Dec 12, 2020
I drew textured cubes! Examples code explaind [here](https://toyboot4e.github.io/rokol) (also conteins screenshots).
=== Dec 27, 2020
I've been developing a 2D roguelike game using Rokol. I basically copied https://github.com/prime31/zig-gamekit[zig-gamekit] in my 2D framework. It's built on top of zig-renderkit, which has very similar API to Sokol, so it's straight-forward to copy that framework with Rokol.
=== Jan 14, 2021
Now `rokol_ffi` doesn't use `include!` and we can easily goto definition of FFI items.
=== Feb 12, 2021
I updated `rokol` for the https://floooh.github.io/2021/02/07/sokol-api-overhaul.html[Feb 2021 update].
=== Mar 9, 2021
I'm going to use SDL instead of `sokol_app.h`. `sokol_app.h` is light, but it lacks some important features such as window resizing with code.
* [x] Make `rokol::app` optional.
* [x] Add {sdl2} support
* [ ] Add {imgui} ({imgui-rs}) support