Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

sokol

> 编程语言
Open source

minimal cross-platform standalone C headers

10.2K stars0 likes1 views
WebsiteGitHub

About

minimal cross-platform standalone C headers



Simple STB-style cross-platform libraries for C and C++, written in C.

Sokol

See what's new (14-Sep-2026: sokol_app.h: changed mouse-locking behaviour on Linux)

Examples and Related Projects

  • Live Samples via WASM (source)

  • Doom Shareware ported to the Sokol headers (source)

  • Syntonic Dentiforms Redux demo remaster by Aras Pranckevičius (blog post).

  • 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

  • NanoVG backend a sokol_gfx backend for the amazing NanoVG library.

  • 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

  • Tiny 8-bit emulators

  • A 'single-file' Pacman clone in C99, also available in Zig

  • Soluna, a framework to make 2D games in Lua by @cloudwu

  • Deep Future: ...and a game implemented with Soluna

  • 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

  • 'Dealer's Dungeon' (lower graphics quality, source)

  • 'Brick Warrior' - a 1990's Breakout clone ported to Sokol :)

  • LearnOpenGL examples ported to sokol-gfx (may be outdated) (git repo)

  • 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

Core libraries

  • 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

Utility libraries

  • 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_app_imgui.h: debug-inspection UI for sokol_app.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)
  • sokol_letterbox.h: compute viewport params for rendering fixed-aspect-ratio content in a variable-aspect-ratio canvas
  • sokol_framebuffer.h: provides CPU-framebuffers rendered via sokol_gfx.h
  • sokol_cmdbuf.h record/replay for sokol_gfx.h apply/draw/dispatch

'Official' Language Bindings

These are automatically updated on changes to the C headers:

  • sokol-zig
  • sokol-odin
  • sokol-nim
  • sokol-rust
  • sokol-d
  • sokol-jai
  • sokol-c3

Notes

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.

Why C:

  • 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

Quick build troubleshooting

When a first Sokol integration fails to compile or link, the problem is usually one of the following configuration mismatches:

  • Define SOKOL_IMPL (or the per-header SOKOL_*_IMPL define) in exactly one C or C++ translation unit before including the Sokol headers. Other files should include the headers without the implementation define.
  • Select exactly one rendering backend in that same implementation translation unit, for example SOKOL_GLCORE, SOKOL_GLES3, SOKOL_D3D11, SOKOL_METAL, SOKOL_WGPU or SOKOL_VULKAN. The backend define must match the shader code and any window/context setup code you use.
  • If sokol_gfx.h and sokol_app.h are used together, use the same backend define for both headers. sokol_app.h creates the matching window and 3D API context; sokol_glue.h then forwards the platform-specific environment via sglue_environment() and sglue_swapchain().
  • macOS and iOS builds which use sokol_app.h or Metal must compile the implementation file as Objective-C or Objective-C++ (.m or .mm, or the equivalent compiler flag), and link the frameworks listed in the header docs.
  • Emscripten WebGL2 builds require the linker option -s USE_WEBGL2=1 when using SOKOL_GLES3. WebGPU builds use SOKOL_WGPU and need the WebGPU port/options described in the sokol_gfx.h header comments.
  • On Linux, OpenGL builds commonly need the GL/X11 development packages installed by the platform package manager. SOKOL_GLCORE uses GLX by default; define SOKOL_FORCE_EGL if your build intentionally uses EGL instead.
  • On Windows, MSVC and Clang builds usually pick up common system libraries via in-source #pragma comment(lib, ...) directives. MinGW/MSYS2 builds may need explicit linker flags such as -ld3d11 for SOKOL_D3D11.
  • For shader-related errors, confirm that generated shader headers come from a sokol-shdc version compatible with the Sokol headers and were generated for the same backend(s) selected at compile time.

For exact per-header compiler and linker requirements, see the comment block at the top of each Sokol header and the build notes in sokol-samples.

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

sokol_app.h

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):

…

sokol_audio.h

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:
    1. directly fill backend audio buffer from your callback function running in the audio thread
    2. 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)

Issues· 133 open

View all issuesOpen on GitHub
  • #1344

    Sporadic input delay on MacOS Tahoe 26.0.1 (1000Hz mouse)

    sokol-appmacosUpdated Sep 29, 2026
  • #1611

    Revamp usage buffer/image usage flags

    sokol-gfxUpdated Sep 26, 2026
  • #1610

    Customizing Sokol GL shader

    Updated Sep 20, 2026
  • #1547

    Brain dump new resource update api

    sokol-gfxUpdated Sep 15, 2026
  • #1302

    Resource views update 2

    planningsokol-gfxUpdated Sep 14, 2026
  • #1594

    sokol_gfx.h: Feature request fragment-writeable storage buffers

    sokol-gfxUpdated Sep 11, 2026
  • #1591

    Raspberry Pi error in _sg_gl_create_buffer

    Updated Sep 2, 2026
  • #1589

    sokol_framebuffer.h: post write-api modernizations

    sokol-framebufferUpdated Aug 27, 2026
  • #1556

    Feature Request: Add support for Indirect Draw Calls (sg_draw_indirect)

    sokol-gfxfeature requestUpdated Aug 19, 2026
  • #853

    Windows Resize Event Delay

    sokol-appwindowsUpdated Aug 12, 2026

> Tags

C

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言