/FWK

3D game framework in C, with Luajit bindings now.

Primary LanguageC

3D game framework in C, with Luajit bindings now.


Goals

  • C++. C.
  • Fast. Naive.
  • Modern. Simple.
  • Full featured. Small.
  • Rich build system. Single file.
  • Royaltie fee. Free and unlicensed.

Features ᕦ(ᐛ)ᕤ

  • Pipeline: configurable and integrated asset pipeline.
  • Embedded: single-file, all dependencies included.
  • Compiler: MSVC, MINGW64, TCC, GCC, clang and emscripten.
  • Platform: Windows, Linux and OSX. Partial HTML5/Web support.
  • DS: hash, sort, array/vector, map, set.
  • Math: rand, noise, ease, vec2/3/4, mat33/34/44, quat.
  • Geometry: ray, line, plane, aabb, sphere, capsule, triangle, poly and frustum.
  • Window: windowed, soft/hard fullscreen, msaa, icon, cursor handling.
  • Input: keyboard, mouse and gamepads.
  • Script: Lua scripting, Luajit bindings.
  • Network: downloads (HTTPS) and sockets (TCP/UDP).
  • UI: color3/4, button, list, slider, toggle, checkbox, editbox, dialog, image, menus.
  • Font: TTF and TTC. Basic syntax highlighter. Unicode ranges, atlasing, I18N.
  • Image: JPG, PNG, BMP, PSD, PIC, PNM, ICO.
  • Texture: KTX/2, PVR, DDS, ASTC, BASIS, HDR, TGA.
  • Texel: Depth, R, RG, RGB, RGBA, BC1/2/3/4/5/6/7, PVRI/II, ETC1/2, ASTC.
  • Audio: WAV/FLAC, OGG/MP1/MP3, MOD/XM/S3M/IT, SFXR and MID.
  • Video: MP4, MPG, OGV, MKV, WMV and AVI. Also, MP4 recording with MPEG-1 fallback.
  • Model: IQM/E, GLTF/2, GLB, FBX, OBJ, DAE, BLEND, MD3/5, MS3D, SMD, X, 3DS, BVH, DXF, LWO.
  • Render: PBR (metallic-roughness) workflow.
  • Render: Cubemaps, panoramas and spherical harmonics. Rayleigh/Mie scattering.
  • Render: Post-effects (SSAO,FXAA1/3,CRT,Contrast,Grain,Outline,Vignette...).
  • Render: 3D Anims, skeletal anims, hardware skinning and instanced rendering.
  • Render: 3D Debugdraw, batching and vectorial font.
  • Render: 2D Sprites, spritesheets, AA zooming and batching.
  • Compression: DEFLATE, LZMA, LZ4, ULZ, BALZ, BCM, CRUSH, LZW3, LZSS and PPP.
  • Virtual filesystem: ZIP, PAK, TAR and DIR.
  • Level data: JSON, JSON5, SJSON, XML.
  • Disk cache.
  • Scene handling.
  • Profiler, stats and leaks finder.
  • Documentation (wip).

Roadmap ᕕ(ᐛ)ᕗ (in order of arrival; ✱: partial support)

  • Editor: gizmos✱, scene tree, property editor, load/save, undo/redo, copy/paste.
  • Level objects: volumes✱, triggers, platforms, streaming.
  • World: W/ECS, gameobj, serialization/merge, diff/patch.
  • Scene: toggles on/off (billboards✱, materials, un/lit, cast shadows, wireframe, skybox/mie, collide, physics).
  • Scene: node singleton display, node console, node labels, node outlines.
  • Math: quat2, bezier, catmull.
  • Render: Materials (colors✱, textures✱, matcaps✱, videos✱, shadertoys✱). Shadertoys as post-fx✱.
  • Render: Hard/soft shadow mapping and baked lightmaps.
  • Script: DLL✱ (module->plugin/sys), Lua✱, Luajit✱, Teal✱ and TypeScript.
  • Network: NAT traversal. Socketless API, message API and pub/sub wrappers (enet/websocket).
  • Pipeline: Extend: shaders, bindings. Per-platform✱, per-type✱, per-asset options. GIF, PKM.
  • Pipeline: Extend atlas (sprite/lightmaps). Fit packing (sprites).
  • Pipeline: Extend bindings and messaging: parse C headers during cooking stage.
  • Maybe: AI/Logic pass.
  • Maybe: Animation pass.
  • Maybe: VM/Replication pass.
  • Maybe: Mobile/WASM/HTML5✱ pass.
  • Maybe: Lighting pass.
  • Maybe: Node/Graph editor.
  • Maybe: Tiled maps and 2D spines. Sprite parallaxs.
  • Maybe: Font text layout and shaping, underlining, soft/hard shadows, outlines.
  • API: Fewer and better examples.
  • API: Discuss API and freeze it.
  • API: Document everything.

Gallery


Hello FWK

#include "fwk.h" // Minimal C sample
int main() {
    window_create(75.0, 0); // 75% size, no extra flags
    while( window_swap() && !input(KEY_ESC) ) { // game loop
        puts("hello FWK from C!");
    }
}
local fwk = require("fwk") -- Minimal Lua sample
fwk.window_create(75.0,0) -- 75% size, no extra flags
while fwk.window_swap() and fwk.input(fwk.KEY_ESC) == 0 do -- game loop
    print("hello FWK from Lua!")
end
#include "fwk.h" // Minimal HTML5 sample
void render(void *arg) {
    if( !input(KEY_ESC) ) { 
        puts("hello FWK from HTML5!");
    }
}
int main() {
    window_create(75.0, 0); // 75% size, no extra flags
    window_loop(render, NULL); // game loop
}

Build (as static library)

Type MAKE.bat (Win) or sh MAKE.bat (Linux/OSX) to build everything. Alternatively,

echo Windows (vc+tcc)      && cl  demo.c       fwk.c
echo Windows (mingw64)     && gcc demo.c       fwk.c -o demo -w -lws2_32 -lgdi32 -lwinmm -ldbghelp
echo Linux (gcc+clang+tcc) && cc  demo.c       fwk.c -o demo -w -lm -ldl -lpthread -lX11
echo OSX (gcc+clang)       && cc  demo.c -ObjC fwk.c -o demo -w -framework cocoa -framework iokit
  • Note: TCC is partially supported on Windows+Linux. Beware, no threading.

Build (as dynamic library)

Type MAKE.bat dll or sh MAKE.bat dll (Linux/OSX) to build FWK as a dynamic library. Alternatively,

echo Windows && cl fwk.c /LD /DAPI=EXPORT
echo Linux   && cc -fPIC fwk.c -shared -o libfwk.so -w -lX11
echo OSX     && cc -ObjC -dynamiclib -o libfwk.dylib fwk.c -framework cocoa -framework iokit -w
  • Quick test on Windows: cl demo.c fwk.lib /DAPI=IMPORT
  • Or also, copy the dynamic library into demos/lua and then run luajit demo_luajit_model.lua from there.

Amalgamation

  • Split FWK into separate files by running MAKE.bat split (or sh MAKE.bat split in Linux/OSX).
  • Merge those files back into FWK by running MAKE.bat join (or sh MAKE.bat join in Linux/OSX).
  • Optionally, generate a single-header distribution by executing following script:
echo // This C file is a header that you can #include. Do #define FWK_C  > fwk-single-header.c
echo // early in **one** compilation unit to unroll the implementation. >> fwk-single-header.c
type fwk.h           >> fwk-single-header.c
echo #ifdef FWK_C    >> fwk-single-header.c
echo #pragma once    >> fwk-single-header.c
type fwk.c           >> fwk-single-header.c
echo #endif // FWK_C >> fwk-single-header.c

Extra tips

  • Dropped files into game window will be imported & saved into editor/import folder.
  • Linux/OSX users can optionally install wine to use the Windows pipeline as an alternate asset pipeline (use --with-wine flag).
  • Although not recommended, you can remove the cooking stage by invoking --with-cook-jobs=0 or by removing the editor/tools folder.
  • Depending on your IDE, you might need to split all amalgamated files when debugging FWK.

Bindings

  • Luajit: Luajit bindings are provided in the fwk.lua auto-generated file.
  • Nelua: Nelua bindings provided by Rabia Alhaffar.

License

This software is released into the public domain.
Also dual-licensed as 0-BSD or MIT (No Attribution) for those countries where public domain is a concern (sigh).
Any contribution to this repository is implicitly subjected to the same release conditions aforementioned.

Credits (Artwork + demos)

  • DavidLam, for tokamak physics engine (ZLIB).
  • FMS_Cat, for nicest VHS/VCR shader around (MIT).
  • Goblin165cm, for witch 3D model (CC BY 4.0).
  • Nanofactory, for kgirls01 3D model (CC BY-NC-ND 4.0).
  • Quaternius, for the lovely 3D robots (CC0).
  • Rxi, for lovely sprites & cats demo (MIT).
  • wwwtyro, for nicest rayleigh/mie scattering shader around (CC0).

Credits (Tools)

Credits (Runtime)

Links

Issues Discord

Still looking for alternatives? amulet, aroma, astera, blendelf, bullordengine, candle, cave, chickpea, corange, cute, dos-like, ejoy2d, exengine, gunslinger, hate, island, juno, l, lgf, limbus, love, lovr, mini3d, mintaro, mio, opensource, ouzel, pez, pixie, punity, ricotech, rizz, tigr,