{"id":15049350,"url":"https://github.com/tofuengine/tofu","last_synced_at":"2025-04-10T02:08:15.618Z","repository":{"id":49720083,"uuid":"232528191","full_name":"tofuengine/tofu","owner":"tofuengine","description":"Multiplatform lightweight 2D game-engine, retro-game inspired. Uses OpenGL through GLFW3. Scripted in Lua. Aiming zero run-time dependencies.","archived":false,"fork":false,"pushed_at":"2024-05-22T23:04:05.000Z","size":38145,"stargazers_count":64,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-22T23:23:47.569Z","etag":null,"topics":["2d","c99","cross-platform","game-development","game-engine","gamedev","gamedev-framework","glfw","linux","lua","opengl","raspberry-pi","windows"],"latest_commit_sha":null,"homepage":"https://tofuengine.org","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tofuengine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-08T09:35:10.000Z","updated_at":"2024-05-22T23:23:54.667Z","dependencies_parsed_at":"2024-03-20T23:46:29.414Z","dependency_job_id":"86f180a3-514d-45f4-b774-acf9d9a532d5","html_url":"https://github.com/tofuengine/tofu","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofuengine%2Ftofu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofuengine%2Ftofu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofuengine%2Ftofu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tofuengine%2Ftofu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tofuengine","download_url":"https://codeload.github.com/tofuengine/tofu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142919,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d","c99","cross-platform","game-development","game-engine","gamedev","gamedev-framework","glfw","linux","lua","opengl","raspberry-pi","windows"],"created_at":"2024-09-24T21:19:55.346Z","updated_at":"2025-04-10T02:08:15.585Z","avatar_url":"https://github.com/tofuengine.png","language":"C","readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://tofuengine.org\"\u003e\u003cimg src=\"./extras/images/logo_with_payoff-512x160.png\" alt=\"Tofu Engine\"\u003e\u003c/a\u003e\n    \u003cbr /\u003e\n    \u003cstrong\u003eA 2D GAME ENGINE W/ AN ECO-FRIENDLY PIXEL-ART RETRO-SOUL\u003c/strong\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE.md\"\u003e\u003cimg src=\"https://img.shields.io/github/license/tofuengine/tofu\" alt=\"license\"\u003e\u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/website?url=https%3A%2F%2Ftofuengine.org%2F\" alt=\"site\"\u003e\n    \u003ca href=\"https://mastodon.gamedev.place/@mode13h\"\u003e\u003cimg src=\"https://img.shields.io/mastodon/follow/108299766418271519?color=blue\u0026domain=https%3A%2F%2Fmastodon.gamedev.place/\u0026label=mastodon\u0026logo=mastodon\u0026style=flat\" alt=\"mastodon\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/tofuengine/tofu/tags\"\u003e\u003cimg src=\"https://img.shields.io/github/v/tag/tofuengine/tofu?color=orange\" alt=\"version\"\u003e\u003c/a\u003e\n    \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/platforms-windows%20%7C%20linux%20%7C%20raspberry-red\" alt=\"platforms\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/tofuengine/tofu\" alt=\"issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/last-commit/tofuengine/tofu/dev\" alt=\"last-commit\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/commit-activity/m/tofuengine/tofu/dev\" alt=\"commit-activity\"\u003e\n\u003c/p\u003e\n\n# Introduction\n\nWelcome to `Tofu Engine`!\n\nMake yourself comfortable, and join for a ride through a mixture of old-fashioned and modern game development! :)\n\n## Highlights\n\n* Carefully crafted C99 code.\n* Self-contained, no additional runtime modules/libraries required (\"standard\" system-wide libraries excluded).\n* Multi-platform support through cross-compilation (Windows, Linux, [Raspberry-Pi](https://www.raspberrypi.org/), and other ARM platforms as long they are running on Linux -- macOS currently not supported, possibly WebAssembly in the not-so-distant future).\n\nFor the courious ones, these are the current statistics of the game-engine codebase:\n\n| Language       | Files  | Blank  | Comment  | Code   |\n| -------------- | ------ | ------ | -------- | ------ |\n| C              |    80  |  3348  |    2496  |  16777 |\n| C/C++ Header   |    88  |   698  |    2408  |   2144 |\n| Lua            |    22  |   296  |     497  |   1708 |\n| GLSL           |    12  |   118  |     282  |    422 |\n|                |   202  |  4460  |    5683  |  21051 |\n\n## Features\n\n* [x] Fully scripted in [Lua](https://www.lua.org/).\n* [x] Straight multimedia support, no intermediate third-party libraries (OpenGL 2.1 required).\n* [x] Windowed/fullscreen display with best-fit integer automatic scaling.\n* [x] Array of predefined common/famous resolutions (e.g. C64, Capcom's arcades, Nintendo DS, Sony PSP, etc...).\n* [x] Internal software renderer. OpenGL is used only to present the framebuffer to the user (and apply post-process effects).\n* [x] Fixed- and variable-size *Blitter OBjects* drawing with rotation/scaling/flipping.\n* [x] Support for both proportional and non-proportional bitmap-based fonts (alphabet subset can be specified, if required).\n* [x] Sprite batching for optimized (ehm) batch drawing.\n* [x] Tiles drawing with offset/scaling/flipping.\n* [x] Palette-based graphics w/ 256 colors.\n* [x] Predefined library of 8/16/32/64 colors palettes.\n* [x] Banked palette support w/ color bias during VRAM transfer.\n* [x] Automatic nearest-matching-color palette indexing of [RGBA8888](https://en.wikipedia.org/wiki/RGBA_color_model) images.\n* [x] Per-color re-indexing (*shifting*) and transparency, affecting drawing operations (both per-draw and during VRAM transfer).\n* [x] Multiple (offscreen) canvas w/ drawing state stack support.\n* [x] SNES' Mode7-like transforms, with scanline based ([HDMA](https://wiki.superfamicom.org/grog's-guide-to-dma-and-hdma-on-the-snes)) changes.\n* [x] Amiga's Copper-like programs, with pixel-wide resolution.\n* [x] Image programmable copy functions, to implement *script-shaders*.\n* [x] Image stencil copy function, with used definable *threshold function*.\n* [x] Image blend copy, with user definable *blending function* (`repeat`, `add`, `sub`, `multiply`, `min`, `max`).\n* [x] Post-effect display-wise fragment shaders.\n* [x] Library of \"retro-feel\" post-effects (LCD, CRT, color-blindness, etc...).\n* [x] Audio support w/real-time sound streaming on a separate thread.\n* [x] On-the-fly audio mixing w/ per voice looping/panning/balance/gain/speed control.\n* [x] Static and streamed audio data playback (FLAC format).\n* [x] Module playback support (MOD, S3M, XM, and IT).\n* [x] Out-of-the-box timers support.\n* [x] Ready-to-use 2D vector class and higher-order iterators.\n* [x] 2D physics-engine.\n* [x] Customizable application icon.\n* [x] Support for *archived games*, via custom \"packed\" format (w/ optional encryption). Multiple archives are supported, with root directory override.\n* [x] Resource manager w/ caching I/O and single instance object loading/reuse.\n* [x] Multiple player support w/ up to 4 simultaneous game controllers. Mouse emulation is supported. Controllers #0 and #1 can be keyboard emulated.\n* [x] Screen capture and recording.\n* [x] Framebuffer offsetting (e.g. for screen-shaking effect).\n* [x] Out-of-the-box 'tweening functions support (optimized [Penner's](http://robertpenner.com/easing/) set).\n* [x] Noise generators (Perlin, simple, and cellular).\n* [x] Logging facility (w/ selectable severity level).\n* [x] Run-time signature check for Lua's API functions (debug build). Also, UDTs are typed-checked with a custom [RTTI](https://en.wikipedia.org/wiki/Run-time_type_information) implementation.\n* [x] Crash screen (debug build).\n* [x] Game window focus detection (for game-pause).\n* [x] Real-time performance statistics (FPS and frame times) and resource usage (memory).\n* [x] User-dependent I/O functions to load/store game data.\n* [x] Configuration override through command-line arguments.\n\n## Dependencies\n\nAlthough I have been known to take pleasure in reinventing the wheel at every possible opportunity, Tofu Engine leverages some *awesome* libraries:\n\n* [cglm](https://github.com/recp/cglm) v0.9.4\n* [Chipmunk2D](https://chipmunk-physics.net/) v7.0.3\n* [dr_libs](https://github.com/mackron/dr_libs) v0.12.42, v0.6.39, v0.13.16\n* [FastNoiseLite](https://github.com/Auburn/FastNoiseLite) v1.0.1\n* [Glad](https://gen.glad.sh/) v2.0.6\n* [GLFW](https://www.glfw.org/) v3.4.0\n* [libspng](https://libspng.org/) v0.7.4\n* [libxmp](https://xmp.sourceforge.net/) v4.6.1\n* [Lua](https://lua.org/) v5.4.7\n* [miniaudio](https://github.com/dr-soft/miniaudio) v0.11.21\n* [miniz](https://github.com/richgel999/miniz) v3.0.2\n* [SDL_GameControllerDB](https://github.com/gabomdq/SDL_GameControllerDB)\n* [spleen](https://github.com/fcambus/spleen) v1.9.3\n* [Stefan Gustavson's noise library](https://github.com/stegu/perlin-noise.git)\n* [stb](https://github.com/nothings/stb) revision w/ date `20240213`\n\n## Inspirations\n\n**Tofu Engine** is an original software, result of the experience gained from ~30 years in programming on a broad range of platforms (some concept even stems back to *ancient* platforms like the [Amiga](https://en.wikipedia.org/wiki/Amiga) and the [SNES](https://en.wikipedia.org/wiki/Super_Nintendo_Entertainment_System), and *arcane* languages like [AMOS](https://en.wikipedia.org/wiki/AMOS_(programming_language)) and [Blitz BASIC 2](https://en.wikipedia.org/wiki/Blitz_BASIC)). However, it has also been influenced by modern similar/other software in one way or another. Here's a brief list.\n\n* [Love2D](https://love2d.org/)\n* [Pico-8](https://www.lexaloffle.com/pico-8.php)\n* [picolove](https://github.com/picolove/picolove/)\n* [Defold](https://defold.com/)\n* [raylib](https://www.raylib.com/)\n\n## Credits\n\nThe lovely game-engine logo has been designed by [Blort](https://social.tchncs.de/@Blort).\n\n# Compiling\n\nIn order to compile `Tofu Engine`, a Linux machine in required (either physical or virtual). A Debian-based distribution is suggested, although I've been using Ubuntu during the development. One can use the following commands to install all the required dependencies:\n\n```bash\nsudo apt install build-essential\nsudo apt install mingw-w64\n\nsudo apt install xorg-dev libx11-dev libwayland-dev libxkbcommon-dev wayland-protocols mesa-common-dev libgles2-mesa-dev\n\nsudo apt install lua5.4 liblua5.4-dev luarocks\n\nsudo luarocks --lua-version=5.4 install argparse\nsudo luarocks --lua-version=5.4 install luafilesystem\nsudo luarocks --lua-version=5.4 install luacheck\nsudo luarocks --lua-version=5.4 install luazen\n```\n\nPlease note that [MinGW](https://en.wikipedia.org/wiki/MinGW) is required only to obtain the Windows build through [cross-compilation](https://en.wikipedia.org/wiki/Cross_compiler). One can simply use MinGW on Windows to build the engine binary as it is.\n\nOf course, `git` should also be installed to clone the repository.\n\n```bash\nsudo apt install git\n```\n\nProceed in creating a local clone of the repository with the command\n\n```bash\ngit clone https://github.com/tofuengine/tofu.git\n```\n\ninto a suitable work directory. Move into the `tofu` directory you've just created and use `make` to build the executable. You can use the following command-line parameters to control the build process:\n\n* `BUILD`, can be either `debug` or `release` with the usual meaning. If not specified, the build is assumed in **debug** mode.\n* `PLATFORM`, can be either `linux` or `windows`. If not specified, the build is assumed for **Linux** platform.\n* `WINDOWING`, can be `x11`, `wayland`, `gdi`, or `mesa`. If not specified, the build assumes `gd1` for the **Windows** platform, `x11` otherwise for the **Linux** one. Please note that `mesa` is not really supported and `wayland` is experimental (but should work).\n* `ARCHITECTURE`, can be `x64`, `x32`, `arm64` or `armhf`. If not specified the current host architecture is used as target.\n\nThe build artifacts will be placed in the `build` directory.\n\n\u003e Alternatively, if you prefer not to tamper with your system, you can use a [Docker](https://docker.io) container for the build process. For that purpose, a ready-to-use *Dockerfile* can be found in the `extras/docker` directory. Use the `make docker-create` command to build the container and `make docker-launch` to start it in the current folder.\n\n# Cross-Compiling\n\nA note about **cross-builds** of the game-engine. The project has been designed with Linux as a development machine, with the distinct platform-dependent build archived through [cross-compilation](https://en.wikipedia.org/wiki/Cross_compiler). As said, the Windows build is obtained thanks to MinGW, which includes all the required dependencies (i.e. development libraries). To obtain the ARM builds through cross-compilation, as well, [Multiarch](https://wiki.debian.org/Multiarch) is to be used. The steps to add support are the following.\n\nFirst and foremost the `arm64` (for 64-bit ARM) and `armhf` (for 32-bit ARM) architectures need to be added\n\n```bash\nsudo dpkg --add-architecture arm64\nsudo dpkg --add-architecture armhf\n```\n\nThen, the `apt` sources for this architecture need to be configured, by creating a new file `/etc/apt/sources.list.d/arm64-sources.list` with this content (which mirrors the `sources.list` file, minus the security sources which are not required):\n\n```bash\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) main restricted\" | sudo tee /etc/apt/sources.list.d/arm64-sources.list \u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates main restricted\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) universe\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates universe\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs) multiverse\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-updates multiverse\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\necho \"deb [arch=arm64,armhf] http://ports.ubuntu.com/ $(lsb_release -cs)-backports main restricted universe multiverse\" | sudo tee -a /etc/apt/sources.list.d/arm64-sources.list \u003e\u003e /dev/null\n```\n\nAt the same time, the current content `/etc/apt/sources.list` file need to be patched so that it refers to the actual host architecture. If it isn't already configured as such you can use the following command to patch the file:\n\n```bash\nsudo sed -i \"s/deb http/deb [arch=$(dpkg --print-architecture)] http/\" /etc/apt/sources.list\n```\n\nRemember to issue a `sudo apt update` command to refresh the APT database and, finally, install GCC's backends and the library dependencies we need:\n\n```bash\nsudo apt install gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu\nsudo apt install gcc-arm-linux-gnueabihf binutils-arm-linux-gnueabihf\nsudo apt install --no-install-recommends libx11-dev:arm64 libx11-dev:armhf\n```\n\nwhich will also install any required package.\n\n## Sample projects\n\nAlong with the game engine source, there are a bunch of (basic) demo projects. They are located in the `demos` sub-directory and can be launched using `make`, passing the name of the project as a target (e.g. `make splash`).\n\n# Addenda\n\n## Contributing\n\nIf **Tofu Engine** appeals you and\n\n* you are experiencing some issues (hopefully not too much of them!),\n* you are seeing some unexpected behaviour (d'oh!),\n* you have some cool ideas do you want to share,\n* you feel the urge to implement a feature from the \"desiderata\" below, or\n* you want to write some examples and/or documentation\n\nplease don't hold you back and [contribute!](CONTRIBUTING.md) :)\n\n## Desiderata\n\nFollows a brief (and incomplete) list of additional features somewhen in the future I'd like to implement.\n\n### Core\n\n* [ ] Boot splash-screen w/ resource preloading support (much like older consoles).\n* [ ] On-screen overlay w/ performance information (FPS, graph, frame-time, etc...).\n* [ ] Logging to file.\n* [ ] Asynchronous resource loading/decoding with callback (maybe just some kind of pre-loading? With coroutines?)\n* [ ] Webassembly build via [Emscripten](https://www.jamesfmackenzie.com/2019/12/01/webassembly-graphics-with-sdl/) to [HTML5](https://uncovergame.com/2015/01/21/porting-a-complete-c-game-engine-to-html5-through-emscripten/).\n* [ ] Use a custom memory-management allocator.\n* [ ] Multi-threaded parallel rendering (w/ double/triple buffering).\n* [ ] Framebuffer rotations? Or does Mode7 suffices? But copperlists are not rendered on canvases...\n* [ ] (Script-level) game state/screen transitions, something similar to the concept of \"rooms\" that many engines offer.\n* [ ] Tweakable game-time management, to control the actual real-time game speed (speed up, slow down, pause, etc...)\n\n### Graphics\n\n* [ ] Move to full GPU use (beware of the diamond-exit-rule and ensure pixel-perfect positioning).\n* [ ] Adopt another (more simple to merge into) pixel font.\n* [ ] Switch to [Vulkan API](https://www.khronos.org/vulkan/) (through [GLFW](https://www.glfw.org/)).\n* [ ] Animation support w/ frameset DSL (i.e. compiling a string where each token can be a single frame, a range or a \"keep-current-frame for some time\" command). Each frameset can have its one update period, and will be most likely based upon a timer.\n* [ ] Tiled-map support w/ camera support (zoom and scrolling).\n* [ ] Custom \"raw\" graphics and sound formats, with on-the-fly LZ4 (stream?) compression.\n\n### Audio\n\n* [ ] On-the-fly (could pre-cache it for later usage) sound synthesizer, similar to [srfx](https://github.com/grimfang4/sfxr).\n* [ ] Audio channels support -- each source is to associated to a channel.\n* [ ] Real-time audio effects (noise, reverb, filters, [spatialization](https://www.sfml-dev.org/tutorials/2.6/audio-spatialization.php), etc...).\n\n### Input\n\n* [ ] Rumble and force feedback support -- this might be implemented with a specific library as GLFW doesn't support it (perhaps taken from [SDL_syshaptic](https://github.com/libsdl-org/SDL/blob/main/src/haptic/SDL_syshaptic.h)?).\n* [ ] Analogue support for shoulder and trigger axes.\n* [ ] Better input handling by leveraging an event-driver approach -- this should reduce the current sub-system complexity (as it polled).\n* [ ] Apply filtering for the analogs, either with a low pass filter (page 591) or moving average.\n* [ ] Implement buttons state check with XOR (page 594)\n* [ ] chords and gestures detection, for example for Street Fighter II-like combos.\n\n## Profiling\n\n```bash\nmake bunnymark BUILD=profile\ngprof ./tofu  gmon.out \u003e analysys.txt\ngprof ./tofu  gmon.out | ./extras/gprof2dot.py | dot -Tpng -o analysys.png\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftofuengine%2Ftofu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftofuengine%2Ftofu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftofuengine%2Ftofu/lists"}