Spinach
Easy to use SDL3 based framework for software rendering, image processing and similar experiments
Install / Use
/learn @mmj-the-fighter/SpinachREADME
Spinach
A framework for starting with computer graphics. It uses SDL3 library.
But can be retargetted to other windowing frameworks by modifying the source code.
Presentation on YouTube with synthetic voice
Useful for:
- Writing lab programs in a first course for computer graphics
(pixels, lines, polygons, circles, ellipses, filling, clipping, transforms etc.) - Writing raytracers
- Writing programs for advanced curves
- Writing software rasterizers
- Writing image processing routines
- Games
- and so on.
Examples / Tutorials
- render loop skelton app demonstration of rendering rapidly changing pixels. use case for software rasterization and raytracing
- without render loop shows how Spinach can be used without render loop. examples: sierpienski triangle, rendering svg and sepia filter
- logarithmic spiral shows how Spinach can be used to make a logarithmic spiral, it includes an imgui checkbox too
- spirograph simulation with spn::rmgui shows how rmgui in Spinach can be used for controling a spirograph
- game of life simulation shows how Spinach can be used for programming game of life. this involves using std::thread
- mine sweeper clone shows how a clone of mine sweeper game can be developed using Spinach
- flappy bird clone shows how a flappy bird like game can be made
- snake clone shows how a snake like game can be made
- picture puzzle game shows how a picture puzzle game can be made
- image processing example with spn::rmgui shows how Spinach can be used for image processing and how rmgui of Spinach can be used for that.
- raytracing example shows how Spinach can be used for raytracing
- software rendering example implementation of a wireframe renderer
Build / Project Generation
Prerequisites
- The root folder must contain the
resdirectory. - CMake must be installed.
Steps
- Create a directory named
buildin the project root. - Open a terminal in the project root and run:
cd build
cmake ../
This will generate the project files inside the build directory.
Key Bindings
Two keys are handled in the engine:
| Key | Behaviour |
|-----|-----------|
| Esc | Application closes |
| F12 | A screenshot is saved with the current timestamp |
Projects that use Spinach
App Skeleton
#include <iostream>
#include <spn_canvas.h>
#include <spn_core.h>
void UpdateAndRender(spn::Canvas* canvas) {
// Use the canvas to draw something
}
void HandleInput(const SDL_Event* sdlEvent) {
// Process input events
}
int main(int argc, char* argv[])
{
spn::SpinachCore sc(640, 480, "../res/");
if (sc.IsInitFailed()) {
std::cout << "Initialization failed with error "
<< sc.GetInitializationResult()
<< std::endl;
return 1;
}
sc.SetUpdateAndRenderHandler(UpdateAndRender);
sc.SetInputHandler(HandleInput);
sc.SetWindowTitle("Spinach App");
sc.GetCanvas()->SetPrimaryColorUint(0x0000ff);
sc.GetCanvas()->SetClearColorUint(0x0);
sc.SetTargetFramesPerSecond(30);
sc.MainLoop();
return 0;
}
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.6kCommit, push, and open a PR
