• Stars
    star
    527
  • Rank 81,110 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample code for https://github.com/floooh/sokol

sokol-samples

Sample code for https://github.com/floooh/sokol

asm.js/wasm live demos: https://floooh.github.io/sokol-html5/index.html

Minimal 8-bit emulators using the sokol headers: https://floooh.github.io/tiny8bit

Build Status:

Platform Build Status
GH Actions (OSX/Linux/Win+VS2019/iOS/WASM/Android) Build Status

How to Build on Windows, Linux and macOS

First check that the following tools are in the path. Exact versions shouldn't matter (on Windows you can use scoop.sh to easily install the required tools from the command line):

> git --version
2.x.x (any version should do)
> python --version
Python 3.x or 2.x
> cmake --version
cmake version 3.8.x or later
# on OSX (on Windows you just need a recent VS)
> xcodebuild -version
Xcode 10.x (or later)
# make is only needed on Linux or when building the WASM samples
> make --version
GNU Make 3.81
# ninja is only needed for VSCode support on macOS and Linux
> ninja --version
1.x.y

NOTE: on Linux you'll also need to install the OpenGL, X11 and ALSA development packages (e.g. mesa-common-dev, libx11-dev and libasound2-dev).

Create a scratch/workspace dir and clone the project:

> mkdir ~/scratch
> cd ~/scratch
> git clone https://github.com/floooh/sokol-samples
> cd sokol-samples

Select a build config for your platform and 3D backend combination:

# macOS with Metal:
> ./fips set config sapp-metal-osx-xcode-debug
# macOS with OpenGL:
> ./fips set config sapp-osx-xcode-debug
# Windows with D3D11:
> ./fips set config sapp-d3d11-win64-vstudio-debug
# Windows with OpenGL:
> ./fips set config sapp-win64-vstudio-debug
# Linux:
> ./fips set config sapp-linux-make-debug

Build the project (this will also fetch additional dependencies):

> ./fips build

List and run the build targets:

> ./fips list targets
...
> ./fips run triangle-sapp

...to open the project in Visual Studio or Xcode:

> ./fips gen
> ./fips open

...you can also open the project in VSCode (with the MS C/C++ extension), for instance on Linux:

> ./fips set config linux-vsocde-debug
> ./fips gen
> ./fips open

For additional platforms (like iOS/Android/UWP), continue reading the README past the What's New section.

For more information on the fips build system see here: https://floooh.github.io/fips/

What's New:

  • 23-Sep-2020: samples can now be built for UWP using the sapp-uwp-vstudio-debug and sapp-uwp-vstudio-release build configs NOTE that fips support for UWP built apps is incomplete (e.g. fips run doesn't work, and UWP app bundle creation is also not supported)

  • 27-May-2020: four new test and demonstration samples for the new sokol_debugtext.h header

  • 30-Apr-2020: New sokol_gfx.h WebGPU backend samples, and updated all other samples for the breaking changes in sokol_gfx.h initialization, see the Updates section in the sokol_gfx.h README for details!

  • 24-Feb-2020: I have added a section to the readme with examples of how to build (most of) the examples without a build system by invoking the C compiler directly on the command line. This might be useful for integration of the sokol headers into your own projects using your own preferred build system.

  • 22-Jan-2020: New sample to demonstrate how to render from inside a Dear ImGui user draw callback: imgui-usercallback-sapp

  • 26-Aug-2019: New sample: fontstash-sapp

  • 06-Jul-2019: Two new samples for the new sokol_fetch.h header:

  • 04-Jun-2019: New sample on how to compile and use the sokol headers as DLL (currently only on Windows). This demonstrates the new SOKOL_DLL configuration define which annotates public function declarations with __declspec(dllexport) or __declspec(dllimport). See here for the DLL, and here for the example code using the DLL.

  • 15-May-2019: the sokol-app samples in the sapp directory have been "ported" to the new shader-cross-compiler solution (see here for details). Shaders are written as 'annotated GLSL', and cross-compiled to various GLSL dialects, HLSL and MSL through a custom-build job which invokes the sokol-shdc command line tool.

  • 01-Apr-2019: sample code for the new sokol_gl.h header:

  • 05-Mar-2019: the sokol-app samples (in the sapp directory) now come with optional debugging UIs implemented via the new Dear ImGui based debug-inspection headers, these are compiled as separate executables, so the executable-versions without UI are still as small as possible.

  • 19-Feb-2019: a new sokol_app.h sample has been added to demonstrate the new SOKOL_NO_ENTRY feature (in which sokol_app.h doesn't hijack the main function): sapp/noentry-sapp.c

  • 26-Jan-2019: The sokol_app.h samples now also work on Android. See below for build instructions.

  • 12-Apr-2018: New samples have been added to demonstrate the new optional vertex-buffer- and index-buffer-offsets in the sg_draw_state struct. Also the location of fips build-system files have changed, please update fips with a 'git pull' from the fips directory.

  • 27-Mar-2018: The Dear Imgui fips wrapper has recently been moved to a new repository at https://github.com/fips-libs/fips-imgui and updated to the latest ImGui version which required some code changes. If you already had checked out sokol-samples, perform the following steps to udpate:

    1. delete the fips-imgui directory
    2. in the sokol-samples directory, run ./fips fetch

Building the platform-specific samples

There are two types of samples, platform-specific samples in the folders d3d11, glfw, html5 and metal, and platform-agnostic samples using the sokol_app.h application-wrapper header in the folder sapp.

To build the GLFW samples on Linux, MacOS and Windows:

> mkdir ~/scratch
> cd ~/scratch
> git clone https://github.com/floooh/sokol-samples
> cd sokol-samples
> ./fips build
...
> ./fips list targets
...
> ./fips run triangle-glfw
...

On Linux you'll need to install a couple of development packages for GLFW: http://www.glfw.org/docs/latest/compile.html#compile_deps_x11

To build for Metal on OSX:

> cd ~/scratch/sokol-samples
> ./fips set config metal-osx-xcode-debug
> ./fips build
...
> ./fips list targets
...
> ./fips run triangle-metal

To build for Metal on iOS:

> cd ~/scratch/sokol-samples
> ./fips set config metal-ios-xcode-debug
> ./fips set iosteam [YOUR-TEAM-ID]
> ./fips gen
> ./fips open
# Xcode should open now, where you can build and run the iOS code as usual

The [YOUR-TEAM-ID] must be replaced with your Apple Developer Team ID, this is a 10-character string which you can look up on https://developer.apple.com/account/#/membership. If you get build errors about 32-bit targets, exit Xcode, run ./fips clean, ./fips gen and ./fips open again. This is a known but unsolved issue which I need to investigate.

Another known issue: The arraytex-metal sample currently has a weird rendering artefact at least on my iPad Mini4 which looks like Z-fighting.

To build for D3D11 on Windows:

> cd /scratch/sokol-samples
> fips set config d3d11-win64-vstudio-debug
> fips build
...
> fips list targets
...
> fips run triangle-d3d11

To build for emscripten:

> cd ~/scratch/sokol-samples
> ./fips setup emscripten
[...this will take a while]
> ./fips set config webgl2-emsc-make-release
> ./fips build
...
> ./fips list targets
...
> ./fips run triangle-emsc
...

To build for Android:

Plug an Android device into your computer, and then:

> cd ~/scratch/sokol-samples
> ./fips setup android
[...this will install a local Android SDK/NDK under ../fips-sdks/android]
> ./fips set config sapp-android-make-debug
> ./fips build
...
> ./fips list targets
...
> ./fips run triangle-sapp
...

The last command should install and run the triangle-sapp sample on the connected Android device.

To debug Android applications I recommend using Android Studio with "Profile or debug APK". You can find the compiled APK files under ../fips-deploy/[project]/[config].

Building the platform-agnostic samples for additional platforms:

Building the sokol_app.h samples is currently supported for MacOS, Windows, Linux, iOS, HTML5 and Android (RaspberryPi is planned).

Use any of the following custom build configs starting with sapp- which matches your platform and build system:

> ./fips list configs | grep sapp-
  sapp-android-make-debug
  ...
  sapp-d3d11-win64-vs2017-debug
  sapp-d3d11-win64-vs2017-release
  sapp-d3d11-win64-vscode-debug
  sapp-d3d11-win64-vstudio-debug
  sapp-d3d11-win64-vstudio-release
  sapp-ios-xcode-debug
  ...
  sapp-win64-vstudio-debug
  sapp-win64-vstudio-release
  sapp-uwp-vstudio-debug
  sapp-uwp-vstudio-release
> ./fips set config sapp-...
> ./fips build
> ./fips list targets
> ./fips run cube-sapp

Note the following caveats:

  • for HTML5, first install the emscripten SDK as described above in the native HTML5 sample section
  • for iOS, set the developer team id, as described above in the iOS section
  • for UWP you need a bleeding edge Visual Studio and Windows SDK version (at least VS2019 and SDK 10.0.19041.0)
  • fips build support for UWP is incomplete, you only get "raw" UWP executables out of the build process, but not packaged and signed application bundles. This is enough for running and debugging the samples inside Visual Studio, but not for much else.

How to build without a build system

Many samples are simple enough to be built directly on the command line without a build system, and the following examples of that might be helpful for integrating the sokol headers and/or the sokol sample code into your own project with the build system of your choice.

The expected directory structure for building the sokol-samples manually is as follows (e.g. those directories must be cloned side-by-side):

sokol-samples
sokol
sokol-tools-bin

For instance:

> mkdir scratch
> cd scratch
> git clone https://github.com/floooh/sokol-samples
> git clone https://github.com/floooh/sokol
> git clone https://github.com/floooh/sokol-tools-bin

Of course, in your own project you can put the sokol headers wherever you want (I recommend copying them somewhere into your source directory), and you don't have to use the prebuilt sokol-shdc shader compiler either.

NOTE: for Release builds, you might want to add the compiler's respective optimization flags, and provide an NDEBUG define so that assert() checks and the sokol-gfx validation layer are removed (BUT please don't do this for the Debug/Dev builds because asserts() and the validation layer give useful feedback if something goes wrong).

Building manually on macOS with clang

To build one of the Metal samples:

> cd sokol-samples/metal
> cc cube-metal.c osxentry.m sokol_gfx.m -o cube-metal -fobjc-arc -I../../sokol -framework Metal -framework Cocoa -framework MetalKit -framework Quartz

To build one of the GLFW samples (requires a system-wide glfw install, e.g. brew install glfw):

> cd sokol-samples/glfw
> cc cube-glfw.c flextgl/flextGL.c -o cube-glfw -I../../sokol -lglfw -framework OpenGL -framework Cocoa

To build one of the sokol-app samples for Metal:

> cd sokol-samples/sapp
> ../../sokol-tools-bin/bin/osx/sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l metal_macos
> cc cube-sapp.c ../libs/sokol/sokol.m -o cube-sapp -DSOKOL_METAL -fobjc-arc -I../../sokol -I ../libs -framework Metal -framework Cocoa -framework MetalKit -framework Quartz -framework AudioToolbox

To build one of the sokol-app samples for GL on macOS:

> cd sokol-samples/sapp
> ../../sokol-tools-bin/bin/osx/sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l glsl330
> cc cube-sapp.c ../libs/sokol/sokol.m -o cube-sapp -fobjc-arc -DSOKOL_GLCORE33 -I../../sokol -I../libs -framework OpenGL -framework Cocoa -framework AudioToolbox

Building manually on Windows with MSVC

From the VSxxxx x64 Native Tools Command Prompt (for 64-bit builds) or Developer Command Prompt for VSxxxx (for 32-bit builds):

To build one of the D3D11 samples:

> cd sokol-samples\d3d11
> cl cube-d3d11.c d3d11entry.c /I..\..\sokol

To build one of the sokol-app samples for D3D11:

> cd sokol-samples\sapp
> ..\..\sokol-tools-bin\bin\win32\sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l hlsl5
> cl cube-sapp.c ..\libs\sokol\sokol.c /DSOKOL_D3D11 /I..\..\sokol /I..\libs

To build one of the sokol-app samples for GL on Windows:

> cd sokol-samples\sapp
> ..\..\sokol-tools-bin\bin\win32\sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l glsl330
> cl cube-sapp.c ..\libs\sokol\sokol.c /DSOKOL_GLCORE33 /I..\..\sokol /I..\libs kernel32.lib user32.lib gdi32.lib

Building manually on Windows with MSYS2/mingw gcc:

NOTE: compile with '-mwin32' (this defines _WIN32 for proper platform detection)

From the MSYS2 shell:

> cd sokol-samples/sapp
# compile shaders for HLSL and GLSL:
> ../../sokol-tools-bin/bin/win32/sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l hlsl5:glsl330
# build and run with D3D11 backend:
> gcc cube-sapp.c ../libs/sokol/sokol.c -o cube-sapp-d3d11 -mwin32 -O2 -DSOKOL_D3D11 -I../../sokol -I ../libs -lkernel32 -luser32 -lshell32 -ldxgi -ld3d11 -lole32 -lgdi32
> ./cube-sapp-d3d11
# build and run with GL backend:
> gcc cube-sapp.c ../libs/sokol/sokol.c -o cube-sapp-gl -mwin32 -O2 -DSOKOL_GLCORE33 -I../../sokol -I ../libs -lkernel32 -luser32 -lshell32 -lgdi32 -lole32
> ./cube-sapp-gl

Building manually on Windows with Clang:

NOTE: AFAIK Clang for Windows needs a working MSVC toolchain and Windows SDK installed, I haven't tested without.

Clang recognizes the #pragma comment(lib,...) statements in the Sokol headers, so you don't need to specify the link libraries manually.

> cd sokol-samples/sapp
# compile shaders for HLSL and GLSL:
> ..\..\sokol-tools-bin\bin\win32\sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l hlsl5:glsl330
# build and run with D3D11 backend:
> clang cube-sapp.c ../libs/sokol/sokol.c -o cube-sapp-d3d11.exe -O2 -DSOKOL_D3D11 -I ../../sokol -I ../libs
> cube-sapp-d3d11
# build and run with GL backend:
> clang cube-sapp.c ../libs/sokol/sokol.c -o cube-sapp-gl.exe -O2 -DSOKOL_GLCORE33 -I ../../sokol -I ../libs
> cube-sapp-gl

Building manually on Linux with gcc

On Linux you need the "usual" development-packages for OpenGL development, and for the GLFW samples, also the GLFW development package (on Ubuntu it's called libglfw3-dev).

To build one of the GLFW samples on Linux:

> cd sokol-samples/glfw
> cc cube-glfw.c flextgl/flextGL.c -o cube-glfw -I../../sokol -lGL -ldl -lm -lglfw3

To build one of the sokol-app samples on Linux:

> cd sokol-samples/sapp
> ../../sokol-tools-bin/bin/linux/sokol-shdc -i cube-sapp.glsl -o cube-sapp.glsl.h -l glsl330
> cc cube-sapp.c ../libs/sokol/sokol.c -o cube-sapp -DSOKOL_GLCORE33 -pthread -I../../sokol -I../libs -lGL -ldl -lm -lX11 -lasound -lXi -lXcursor

Many Thanks to:

Enjoy!

More Repositories

1

sokol

minimal cross-platform standalone C headers
C
5,629
star
2

oryol

A small, portable and extensible C++ 3D coding framework
C++
1,965
star
3

chips

8-bit chip and system emulators in standalone C headers
C
890
star
4

pacman.c

Simple Pacman clone written in C99.
C
464
star
5

fips

High-level build system for distributed, multi-platform C/C++ projects.
Python
457
star
6

chips-test

Tests and sample code for https://github.com/floooh/chips
C
366
star
7

sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
C
264
star
8

v6502r

visual6502 remixed
C
251
star
9

pacman.zig

Simple Pacman clone written in Zig.
Zig
197
star
10

sokol-tools

Command line tools for use with sokol headers
C++
190
star
11

cimgui-sokol-starterkit

A minimal self-contained Dear ImGui starter project for Windows, Linux and macOS.
C++
184
star
12

bookmarks

Links to stuff that looks useful.
139
star
13

qoiview

QOI image viewer on top of the Sokol headers
C
123
star
14

emu-info

Various emulator-related infos from all over the net.
Assembly
105
star
15

yakc

Yet another KC emulator
Assembly
104
star
16

oryol-samples

Oryol extension module samples
C++
81
star
17

rz80

Z80 chip family emulator library written in Rust.
Rust
72
star
18

sokol-nim

nim bindings for https://github.com/floooh/sokol
C
70
star
19

gliml

Minimalistic image loader library for GL projects
C++
62
star
20

fbxc

FBX cruncher (FBX + rules => JSON + vertex data blob)
C++
61
star
21

altai

Modern WebGL wrapper in TypeScript
TypeScript
53
star
22

sokol-odin

Odin bindings for the sokol headers (https://github.com/floooh/sokol)
C
46
star
23

sokol-rust

Rust bindings for the sokol headers (https://github.com/floooh/sokol)
C
44
star
24

kc85.zig

A KC85 emulator written in Zig
Zig
42
star
25

tiny8bit

WebPage for https://github.com/floooh/chips-test
HTML
36
star
26

docker-c64

C64 emulator running in docker
C
31
star
27

sokol-tools-bin

Binaries and fips integration for https://github.com/floooh/sokol-tools
Python
21
star
28

oryol-animation

Oryol animation and skinned-character-rendering modules
C++
19
star
29

oryol-imgui

Dear Imgui wrapper module for Oryol
C++
18
star
30

fips-bgfx

fipsified version of bgfx (https://github.com/bkaradzic/bgfx)
CMake
17
star
31

sokol-webgpu

HTML
15
star
32

floooh.github.io

Move blog and personal web page over to github (work in progress)
HTML
14
star
33

sokol-nim-samples

Example code for https://github.com/floooh/sokol-nim
Nim
13
star
34

vscode-kcide

Retro assembly IDE for VSCode
TypeScript
13
star
35

vscode-emscripten-debugging

Example repository for Emscripten WASM debugging in VSCode
C
11
star
36

visualz80remix

[WIP] WASM for https://github.com/floooh/v6502r with Z80 netlist
HTML
11
star
37

visual6502remix

Webpage for https://github.com/floooh/v6502r
HTML
11
star
38

oryol-tools

Asset exporter tools for Oryol engine
C++
10
star
39

drahtgitter

A toolkit for converting and processing 3d data in python.
Python
9
star
40

virtualkc

Webpage for the YAKC KC85 emulator
HTML
9
star
41

oryol-tbui

Integrate TurbobadgerUI with Oryol
C++
8
star
42

sokol-html5

webpage for https://github.com/floooh/sokol-samples
HTML
7
star
43

objc-ast-experiments

C
7
star
44

fibs

Nothing to see here, move along :)
TypeScript
7
star
45

fips-libcurl

Precompiled, stripped down libcurl libs for Oryol
C
6
star
46

visual2a03remix

webpage for the Ricoh 2A03 simulation
HTML
6
star
47

tiny8bitvs

Experiment to integrate a 'chips' WASM emulator into a VSCode tab.
TypeScript
6
star
48

kc85sdk

Experimental C-SDK for KC85 home computers
Python
6
star
49

fips-soloud

fipsified version of Soloud audio lib (https://github.com/jarikomppa/soloud)
CMake
6
star
50

voxel-test

Place to experiment with stb_voxel_renderer.h and Oryol
C
5
star
51

oryol-nuklear

Integrate Nuklear UI with Oryol engine
C++
5
star
52

oryol-test-app

Oryol testing app in its own repo
C++
5
star
53

fibs-hello-world

Most minimal fibs test project.
TypeScript
5
star
54

oryol-fileformats

Structure definitions for Oryol binary file formats.
C++
4
star
55

headeronly-perf

C
4
star
56

fibs-libs

Collection of fibs project wrappers for common 3rd-party libraries.
TypeScript
4
star
57

sokol-wgpu-preview

Temporary sneak preview website for sokol WebGPU samples.
HTML
4
star
58

emsc-interop-demo

Simple example to demonstrate calling a C function from Javascript.
HTML
4
star
59

easmx

A fork of the asmx assembler usable as embeddable library.
C
4
star
60

oryol-sound

Legacy Oryol sound module (uses OpenAL)
C++
3
star
61

docker-kc85

A KC85/4 emulator in Docker.
C
3
star
62

hcasm

8-bit home computer assembler in Typescript
TypeScript
3
star
63

fips-nuklear

fips build system wrapper for nuklear UI (https://github.com/vurtun/nuklear)
Python
3
star
64

chef-emscripten

Chef cookbook to setup an emscripten build environment.
Ruby
3
star
65

kcide-sample

Sample project for VSCode KC IDE extension
Assembly
3
star
66

oryol-webgl2

Webpage files for bleeding edge WebGL2 Oryol samples.
HTML
3
star
67

fips-hello-world

Test project for fips build system.
Python
3
star
68

fips-bullet

fips wrapper for bullet phyiscs
CMake
2
star
69

fips-spirvcross

fips wrapper for SPIRV-Cross
CMake
2
star
70

flohofwoe.www

JavaScript
2
star
71

fips-glfw

fipsified GLFW (https://github.com/glfw/glfw)
CMake
2
star
72

fips-cjson

fipsified cJSON lib
CMake
2
star
73

fibs-sokol-test

Fibs + sokol + sokol-shdc + stb
C
2
star
74

fips-cpptoml

fipsified cpptoml (https://github.com/skystrife/cpptoml)
2
star
75

fips-vld

Fipsified VLD (Visual Leak Detector)
C
2
star
76

fips-zlib

fipsified zlib
C
2
star
77

nvidia-driver-issue

C
1
star
78

fips-unittestpp

fipsified UnitTest++
C++
1
star
79

chef-cmake

Chef cookbook for installing cmake from source tarball
Ruby
1
star
80

webgl2-test

WebGL2 bug repro tests (wip)
JavaScript
1
star
81

chef-nacl

Chef cookbook to install the Google Native Client SDK
Ruby
1
star
82

fips-remotery

fipsified version of Remotery (https://github.com/Celtoys/Remotery)
CMake
1
star
83

tmp-http-test

TypeScript
1
star
84

fibs-test

Top level test project for https://github.com/floooh/fibs
C
1
star
85

oryol-simple

The most simple Oryol Gfx app
Python
1
star
86

fips-lua

fips wrapper for lua
CMake
1
star
87

fips-glm

Fipsified glm lib (https://github.com/g-truc/glm)
1
star
88

fibs-utils

Common helpers and utilities for fibs projects.
TypeScript
1
star
89

tiny8bit-preview

Temporary preview webpage repo for https://github.com/floooh/chips-test
HTML
1
star