Simple STB-style cross-platform libraries for C and C++, written in C.
See what's new (15-Mar-2025 sokol_gfx.h: new vertex formats and related behaviour cleanup)
-
Live Samples via WASM (source)
-
Doom Shareware ported to the Sokol headers (source)
-
Everybody Wants to Crank the World demo by Aras Pranckevičius, PC/web port via sokol (source).
-
sokol_gp.h a 2D shape drawing library on top of sokol_gfx.h
-
Dear ImGui starterkit a self-contained starterkit for writing Dear ImGui apps in C.
-
qoiview a basic viewer for the new QOI image file format
-
A 'single-file' Pacman clone in C99, also available in Zig
-
Solar Storm, a turn-based scifi artillery game built with Odin and Sokol, released on Steam.
-
Spanking Runners (Samogonki), arcade racing in a bright and unusual world, released on Steam.
-
MEG-4 a virtual fantasy console emulator in C89, ported to sokol
-
A Minigolf game (source).
-
hIghQube A game demo that used sokol rendering extensively
-
Senos A music app that uses sokol as backend
-
Command line tools (shader compiler)
-
How to build without a build system: useful details for integrating the Sokol headers into your own project with your favourite C/C++ build system
- sokol_gfx.h: 3D-API wrapper (GL/GLES3/WebGL2 + Metal + D3D11 + WebGPU)
- sokol_app.h: app framework wrapper (entry + window + 3D-context + input)
- sokol_time.h: time measurement
- sokol_audio.h: minimal buffer-streaming audio playback
- sokol_fetch.h: asynchronous data streaming from HTTP and local filesystem
- sokol_args.h: unified cmdline/URL arg parser for web and native apps
- sokol_log.h: provides a standard logging callback for the other sokol headers
- sokol_imgui.h: sokol_gfx.h rendering backend for Dear ImGui
- sokol_nuklear.h: sokol_gfx.h rendering backend for Nuklear
- sokol_gl.h: OpenGL 1.x style immediate-mode rendering API on top of sokol_gfx.h
- sokol_fontstash.h: sokol_gl.h rendering backend for fontstash
- sokol_gfx_imgui.h: debug-inspection UI for sokol_gfx.h (implemented with Dear ImGui)
- sokol_debugtext.h: a simple text renderer using vintage home computer fonts
- sokol_memtrack.h: easily track memory allocations in sokol headers
- sokol_shape.h: generate simple shapes and plug them into sokol-gfx resource creation structs
- sokol_color.h: X11 style color constants and functions for creating sg_color objects
- sokol_spine.h: a sokol-style wrapper around the Spine C runtime (http://en.esotericsoftware.com/spine-in-depth)
These are automatically updated on changes to the C headers:
WebAssembly is a 'first-class citizen', one important motivation for the Sokol headers is to provide a collection of cross-platform APIs with a minimal footprint on the web platform while still being useful.
The core headers are standalone and can be used independently from each other.
- easier integration with other languages
- easier integration into other projects
- adds only minimal size overhead to executables
A blog post with more background info: A Tour of sokol_gfx.h
- simple, modern wrapper around GLES3/WebGL2, GL3.3, D3D11, Metal, and WebGPU
- buffers, images, shaders, pipeline-state-objects and render-passes
- does not handle window creation or 3D API context initialization
- does not provide shader dialect cross-translation (BUT there's now an 'official' shader-cross-compiler solution which seamlessly integrates with sokol_gfx.h and IDEs: see here for details
A minimal cross-platform application-wrapper library:
- unified application entry
- single window or canvas for 3D rendering
- 3D context initialization
- event-based keyboard, mouse and touch input
- supported platforms: Win32, MacOS, Linux (X11), iOS, WASM, Android, UWP
- supported 3D-APIs: GL3.3 (GLX/WGL), Metal, D3D11, GLES3/WebGL2
The vanilla Hello-Triangle using sokol_gfx.h, sokol_app.h and the sokol-shdc shader compiler (shader code not shown):
A minimal audio-streaming API:
- you provide a mono- or stereo-stream of 32-bit float samples which sokol_audio.h forwards into platform-specific backends
- two ways to provide the data:
- directly fill backend audio buffer from your callback function running in the audio thread
- alternatively push small packets of audio data from your main loop, or a separate thread created by you
- platform backends:
- Windows: WASAPI
- macOS/iOS: CoreAudio
- Linux: ALSA
- emscripten: WebAudio + ScriptProcessorNode (doesn't use the emscripten-provided OpenAL or SDL Audio wrappers)
A simple mono square-wave generator using the callback model:
The same code using the push-model
Load entire files, or stream data asynchronously over HTTP (emscripten/wasm) or the local filesystem (all native platforms).
Simple C99 example loading a file into a static buffer:
Simple cross-platform time measurement:
Unified argument parsing for web and native apps. Uses argc/argv on native platforms and the URL query string on the web.
Example URL with one arg:
https://floooh.github.io/tiny8bit/kc85.html?type=kc85_4
The same as command line app:
kc85 type=kc85_4
Parsed like this:
See the sokol_args.h header for a more complete documentation, and the Tiny Emulators for more interesting usage examples.