SkillAgentSearch skills...

Tofu

Multiplatform lightweight 2D game-engine, retro-game inspired. Uses OpenGL through GLFW3. Scripted in Lua. Aiming zero run-time dependencies.

Install / Use

/learn @tofuengine/Tofu

README

<p align="center"> <a href="https://tofuengine.org"><img src="./extras/images/logo_with_payoff-512x160.png" alt="Tofu Engine"></a> <br /> <strong>A 2D GAME ENGINE W/ AN ECO-FRIENDLY PIXEL-ART RETRO-SOUL</strong> </p> <p align="center"> <a href="LICENSE.md"><img src="https://img.shields.io/github/license/tofuengine/tofu" alt="license"></a> <img src="https://img.shields.io/website?url=https%3A%2F%2Ftofuengine.org%2F" alt="site"> <a href="https://bsky.app/profile/mode13h.dev"><img src="https://img.shields.io/badge/Bluesky-0285FF?logo=bluesky&logoColor=fff&style=flat" alt="bluesky"></a> </p> <p align="center"> <a href="https://github.com/tofuengine/tofu/tags"><img src="https://img.shields.io/github/v/tag/tofuengine/tofu?color=orange" alt="version"></a> <a href=""><img src="https://img.shields.io/badge/platforms-windows%20%7C%20linux%20%7C%20raspberry-red" alt="platforms"></a> </p> <p align="center"> <img src="https://img.shields.io/github/issues/tofuengine/tofu" alt="issues"> <img src="https://img.shields.io/github/last-commit/tofuengine/tofu/dev" alt="last-commit"> <img src="https://img.shields.io/github/commit-activity/m/tofuengine/tofu/dev" alt="commit-activity"> </p>

Introduction

Welcome to Tofu Engine!

Make yourself comfortable, and join for a ride through a mixture of old-fashioned and modern game development! :)

Highlights

  • Carefully crafted C99 code.
  • Self-contained, no additional runtime modules/libraries required ("standard" system-wide libraries excluded).
  • Multi-platform support through cross-compilation (Windows, Linux, Raspberry-Pi, and other ARM platforms as long they are running on Linux -- macOS currently not supported, possibly WebAssembly in the not-so-distant future).

For the courious ones, these are the current statistics of the game-engine codebase:

| Language | Files | Blank | Comment | Code | | -------------- | ------ | ------ | -------- | ------ | | C | 80 | 3348 | 2496 | 16777 | | C/C++ Header | 88 | 698 | 2408 | 2144 | | Lua | 22 | 296 | 497 | 1708 | | GLSL | 12 | 118 | 282 | 422 | | | 202 | 4460 | 5683 | 21051 |

Features

  • [x] Fully scripted in Lua.
  • [x] Straight multimedia support, no intermediate third-party libraries (OpenGL 3.3 Core required).
  • [x] Windowed/fullscreen display with best-fit integer automatic scaling.
  • [x] Tweakable run-time parameters, either from the configuration file and/or command-line arguments (w/ parameters override through command-line arguments).
  • [x] Array of predefined common/famous resolutions (e.g. C64, Capcom's arcades, Nintendo DS, Sony PSP, etc...).
  • [x] Internal software renderer. OpenGL is used only to present the framebuffer to the user (and apply post-process effects).
  • [x] Fixed- and variable-size Blitter OBjects drawing with rotation/scaling/flipping.
  • [x] Support for both proportional and non-proportional bitmap-based fonts (alphabet subset can be specified, if required).
  • [x] Sprite batching for optimized (ehm) batch drawing.
  • [x] Tiles drawing with offset/scaling/flipping.
  • [x] Custom image format, optimized for blazing-fast loading time. A support tool for converting from standard formats is provided, supporting also image palette optimization (via median-cut color reduction) and/or matching.
  • [x] Palette-based graphics w/ 256 colors.
  • [x] Predefined library of 8/16/32/64 colors palettes.
  • [x] Palette selection from the configuration file or run-time redefined.
  • [x] Automatic clear of the default image buffer on each loop (configurable).
  • [x] Banked palette support (two banks of 128-color palettes) w/ color bias during VRAM transfer.
  • [x] Automatic nearest-matching-color palette indexing of RGBA8888 images.
  • [x] Internal 16-bit (RGB565) pixel format used for indexed-to-texture rendering, matching X68000 aesthetics.
  • [x] Per-color transparency and re-indexing (shifting), in this order, affecting drawing operations (both per-draw and during VRAM transfer).
  • [x] Multiple (offscreen) canvas w/ drawing state stack support.
  • [x] SNES' Mode7-like transforms, with scanline based (HDMA) changes.
  • [x] Amiga's Copper-like programs, with pixel-wide resolution.
  • [x] Image programmable copy functions, to implement script-shaders.
  • [x] Image stencil copy function, with used definable threshold function.
  • [x] Image blend copy, with user definable blending function (repeat, add, sub, multiply, min, max).
  • [x] Post-effect display-wise fragment shaders.
  • [x] Library of "retro-feel" post-effects (LCD, CRT, color-blindness, etc...).
  • [x] Audio support w/real-time sound streaming on a separate thread.
  • [x] On-the-fly audio mixing w/ per voice looping/panning/balance/gain/speed control.
  • [x] Static and streamed audio data playback (FLAC format).
  • [x] Module playback support (MOD, S3M, XM, and IT).
  • [x] Out-of-the-box timers support.
  • [x] Ready-to-use 2D vector class and higher-order iterators.
  • [x] 2D physics-engine.
  • [x] Support for archived games, via custom "packed" format (w/ optional encryption). Multiple archives are supported, with root directory override.
  • [x] Resource manager w/ caching I/O and single instance object loading/reuse.
  • [x] Multiple player support w/ up to 4 simultaneous game controllers. Mouse emulation is supported. Controllers #0 and #1 can be keyboard emulated.
  • [x] Screen capture and recording.
  • [x] Framebuffer offsetting (e.g. for screen-shaking effect).
  • [x] Out-of-the-box 'tweening functions support (optimized Penner's set).
  • [x] Noise generators (Perlin, simple, and cellular).
  • [x] Logging facility (w/ selectable severity level).
  • [x] Run-time signature check for Lua's API functions (debug build). Also, UDTs are typed-checked with a custom RTTI implementation.
  • [x] Crash screen (debug build).
  • [x] Performance profiling (debug build).
  • [x] Game window focus detection (for game-pause).
  • [x] Real-time performance statistics (FPS and frame times) and resource usage (memory).
  • [x] User-dependent I/O functions to load/store game data.

Dependencies

Although I'm used to take pleasure in reinventing the wheel at every possible opportunity, Tofu Engine leverages some awesome libraries:

Inspirations

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 and the SNES, and arcane languages like AMOS and Blitz BASIC 2). However, it has also been influenced by modern similar/other software in one way or another. Here's a brief list.

Credits

The lovely game-engine logo has been designed by Blort.

Compiling

In order to compile Tofu Engine, a Linux machine in required (either physical or virtual). A Debian-based distribution is suggested, as I've been using Ubuntu since the beginning of its development. One can use the following commands to install all the required dependencies:

sudo apt install build-essential
sudo apt install mingw-w64

sudo apt install xorg-dev libx11-dev libwayland-dev libxkbcommon-dev wayland-protocols mesa-common-dev libgles2-mesa-dev

sudo apt install valgrind cloc bear

sudo apt install libvips libvips-dev
sudo apt install lua5.4 liblua5.4-dev luarocks

sudo luarocks --lua-version=5.4 install argparse
sudo luarocks --lua-version=5.4 install luafilesystem
sudo luarocks --lua-version=5.4 install luacheck
sudo luarocks --lua-version=5.4 install luazen
sudo luarocks --lua-version=5.4 install lua-vips
sudo luarocks --lua-version=5.4 install luaffi-tkl

Please note that MinGW is required only to obtain the Windows build through cross-compilation. One can simply use MinGW on Windows to build the engine binary as it is.

Of course, git should also be installed to clone the repository.

sudo apt install git

Proceed in creating a local clone of the repository with the command

git clone https://github.com/tofuengine/tofu.git

into 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 parame

View on GitHub
GitHub Stars83
CategoryDevelopment
Updated14h ago
Forks4

Languages

C

Security Score

100/100

Audited on Mar 24, 2026

No findings