What does HackerNews think of sokol?

minimal cross-platform standalone C headers

Language: C

I wonder if using your library (https://github.com/floooh/sokol) instead of OpenGL will alleviate some of these issues for newcomers! There's already a sokol port of the learnopengl.com code (https://github.com/GeertArien/learnopengl-examples), so it shouldn't be too hard to match between the tutorial articles and these.
If you're looking for something like this, Sokol is a much simpler alternative:

https://github.com/floooh/sokol

It doesn't support vulkan though, but if that's important to you you're probably much better off just using vulkan directly since it's supported on all the major platforms.

My stuff for instance:

https://github.com/floooh/sokol

...inspired by:

https://github.com/nothings/stb

(here's how the sokol headers are integrated into a Zig project, note that there is only a build.zig which builds everything: https://github.com/floooh/kc85.zig)

But it's not so much about build systems, but requiring a separate compiler toolchain to build any C++ or ObjC dependencies (Rust needs this, Zig currently does not - unless that controversial proposal is implemented).

(also even complex C++ libraries can be wrapped in a build.zig, so you don't require a separate build system like cmake for the C++ dependencies)

At least SDL2 has 'proper' Emscripten support:

https://wiki.libsdl.org/SDL2/README/emscripten

My own cross-platform headers too:

https://github.com/floooh/sokol

...there are also auto-generated Zig bindings btw ;)

https://github.com/floooh/sokol-zig

I use it for my home computer emulation stuff, the same code also compiles to minimal native applications (but with WASM there's not much of a point except during development and debugging - still it's good to have a "native fallback"):

https://floooh.github.io/tiny8bit/

Also see: https://github.com/floooh/sokol and https://floooh.github.io/sokol-html5/index.html.

(e.g. for me it's a way to easily get my C/C++ cross-platform hobby stuff to people without requiring them having to jump through the hoops of downloading and running an untrusted native executable or messing around with C/C++ toolchains and build systems to build the stuff locally).

PS: WASM in the browser is also a good watchdog which punishes you heavily if your code gets to bloated ;)

> Platforms that they actually released on? Xbox Series X|S, Xbox One, Windows 10/11, PS4/5.

> Why? ...

...not really, these are business reasons, plain and simple.

The problem with games on Linux is that the market is too small, the technical problems could be overcome if there would be a will and enough money thrown at it (see Steam Deck and Proton where this approach works pretty well) - for instance the technical problems for games on Android are arguably worse, yet the market is big enough that game developers have enough incentives to deal with those problems.

Also WebGPU is not released yet, so looking at caniuse is not really useful.

As for the last point: the CPU's ISA is the least of the problems. Most applications are no longer coded by hand in assembly.

Apart from being slightly faster, I see no difference between coding on an M1 Mac versus an Intel Mac or even a Windows or Linux machine (exactly because I hardly code in assembly these days).

My (same) code runs on all of those, plus the web, iOS and Android (granted I wrote my own set of wrapper libs to make this easy: https://github.com/floooh/sokol - but it's not like that's the only slim solution for cross-platform code).

I have no idea why this is getting downvoted. Floh is, among other things, the author of Sokol, which is a set of cross platform libs suitable for game dev. Sokol has "native" support for the web, which means you can write your app against Sokol and don't have to deal directly with these painful web APIs.

I've personally used Sokol for a number of projects and it has been great. You get something much leaner and meaner compared to the Emscripten port of SDL, which otherwise seems to be the "default" when people do these things.

https://github.com/floooh/sokol

Well, eye opening was the C++ source code I was able to work with at a previous company, they were an automotive HMI developer company. They had really strict and well planned code structure that just hit a chord with me.

Can't provide source though on that one, as it's a propietary engine. Recently I've enjoyed reading the source code to Sokol, lot's of really good decisions there and I love the minimal C -style structure:

https://github.com/floooh/sokol

For a somewhat more complete example which runs in browsers, check out my little pacman.zig toy project [0]. This is cheating a bit by using the Emscripten SDK as 'sysroot' (needed for the Emscripten headers to provide the glue to web APIs), and the Emscripten linker to create the additional html and js output file, but the actual code is all compiled with the Zig compiler to WASM, emcc is only used for linking.

The interesting part is that the platform abstraction is provided by the sokol C headers [1], with auto-generated Zig bindings [2]. It's interesting because the C headers use "Emscripten magic" (mainly embedding Javascript snippets in the C sources via the EM_JS() macro), and the Zig compiler is able to compile this (when it has access to the Emscripten headers).

It would be nice if the "Emscripten platform" could get the same type of cross-compilation support as the desktop platforms eventually, but apart from bundling the Emscripten headers, this would also require to implement some of the "Emscripten magic" in the Zig linker.

Maybe projects like WaJIC [3] can help with this (this basically implements the "Emscripten magic" of embedding Javascript snippets in C/C++ source code, but without Emscripten (only the wasm-opt tool is needed AFAIK).

Anyway... it's a lot of fun to tinker around with this stuff in Zig :)

[0] https://github.com/floooh/pacman.zig

[1] https://github.com/floooh/sokol

[2] https://github.com/floooh/sokol-zig

[3] https://github.com/schellingb/wajic

Shameless plug: It's not C++ (but C instead, but of course also usable from C++), and not "great" as in "created by a big Silicon Valley company", but check out the sokol headers:

https://github.com/floooh/sokol

...live samples:

https://floooh.github.io/sokol-html5/index.html

Quick shout-out to a graphics abstraction library that works quite well: sokol.

https://github.com/floooh/sokol

It has DX11, Metal, and OpenGL backends (with optional shader compilation tool from GLSL to each target), which is probably all you need to get cross-platform support for all desktop and mobile targets. Rewrote my OpenGL code to this, was a pretty nice experience. The subset of graphical features it exposes seems more than good enough for simple 2D games (probably enough for simple 3D ones also). Can't say more than that though, since I haven't seen a shipped 3D game on Steam using it yet.

Though what we ultimately need for the future is a Metal-like API that runs on all platforms (since from what I've heard from other graphics developers Metal's API design is quite nice and finds the right balance between low-level control and high-level usability). The experimental SDL_gpu development (https://gist.github.com/icculus/f731224bef3906e4c5e8cbed6f98...) strives to achieve this, although it's still in the early stages...

Some other interesting libraries I've seen along these lines:

- Sokol (sokol_gfx in particular): https://github.com/floooh/sokol

- wgpu (see wgpu-native for the C API): https://github.com/gfx-rs/wgpu

It kind of seems like graphics abstractions for modern hardware are getting pretty "figured out". There are wrappers that work for most DirectX/Metal/OpenGL applications so they can run just about anywhere, and new 2D/3D applications have a lot of accessible/open-source options to build on top of. Projects like Mesa's Zink will centralize the burden of maintaining legacy APIs away from hardware manufacturers. Valve's Proton is making waves. WebGPU is on the way.

The future looks bright.

> This isn't exactly a massive obstacle if you've set out to build a complex game in the browser.

It is an obstacle (at least a massive annoyance) for library authors (like this: https://github.com/floooh/sokol). Those libraries can be used for extremely simple and small WASM snippets embedded in blog posts (like here: https://floooh.github.io/2019/01/05/wasm-embedding.html), or in "proper" games hosted through "proper" hosting services which allow to set the response headers.

Right now the choice is to either support WASM threading, but tell library users that the library will most likely not work on the hosting solution of their choice, or not support WASM threading and work everywhere. At least to me it's clear that "works everywhere" is better than "it's complicated", so I'll ignore WASM threading until the problem is solved somehow (either most hosting services turn on those response headers, or there's another way to enable threading without requiring control over the web server configuration).

The library itself doesn't depend on anything, instead it delegates the "platform integration" (rendering and input) to outside code.

The examples somehow need to connect to the underlying operating system, and that's why they depend on GLFW as intermediate layer, but this could also be SDL, or - shameless plug - the sokol headers (https://github.com/floooh/sokol), or (more commonly) a game engine like Unity, Unreal Engine, or your own code.

Regarding the "emscripten-imposed file size problem", I've written a couple of alternative cross-platform headers which might help in this case (e.g. avoiding SDL). These enable WASM apps in the "dozens of KBytes" range, and you get native-platform support "for free":

https://github.com/floooh/sokol

Check out these samples and have a look at the size in the browser devtools which are IMHO quite sensible:

https://floooh.github.io/sokol-html5/

https://floooh.github.io/tiny8bit/

PS: really great writeup btw :)

Vulkan is too complex and is not supported by Apple and older hardware.

We use Sokol, an amazing wrapper library, and it only supports the big 3.

https://github.com/floooh/sokol

Shameless plug, check out sokol_gfx.h (and maybe sokol_gl.h, which is a simple GL 1.x style API on top of sokol_gfx.h):

https://github.com/floooh/sokol

Shameless plug, but check out the Sokol libraries (there's also a header with a Dear ImGui rendering backend sitting on top of sokol_app.h and sokol_gfx.h):

https://github.com/floooh/sokol

...and here's a minimal standalone starter project for writing Dear ImGui apps in C I just created a couple of days ago:

https://github.com/floooh/cimgui-sokol-starterkit

The author of this also created the excellent Sokol cross-platform graphics/sound library, which is being used here.

https://github.com/floooh/sokol