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.
- 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
- locus generation shows how spn::rmgui can be used for controlling two indpendantly rotating links
- 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
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.
Five keys are handled in the engine:
| Key | Behaviour |
|---|---|
Esc |
Application closes |
F12 |
A screenshot is saved with the current timestamp |
F8 |
Screen recording starts; recording indication is shown in the screen |
F10 |
Screen recording ends; the gif is saved with the current time stamp |
F6 |
Screen recording aborts; no file is saved |
#include <iostream>
#include <spn_canvas.h>
#include <spn_core.h>
void UpdateAndRender(spn::Canvas* canvas) {
//Draw something with the canvas
}
void HandleInput(const SDL_Event* sdlEvent) {
//std::cout << "*";
}
int main(int argc, char* argv[])
{
spn::SpinachCore sc;
if (!sc.Init(640, 480, "../res/")) {
std::cout << "initialization failed with error "
<< sc.GetInitializationResult()
<< std::endl;
return 1;
}
sc.SetUpdateAndRenderHandler(UpdateAndRender);
sc.SetInputHandler(HandleInput);
sc.SetWindowTitle("Spinach Demo");
sc.GetCanvas()->SetPrimaryColor(255, 255, 0);
sc.SetTargetFramesPerSecond(30);
sc.LockFps(true);
sc.MainLoop();
return 0;
}