Dangerzone

A tiny game engine / software renderer using SDL for framebuffer visualization.

Features

  1. Put Pixel - Lets you color one given pixel in the framebuffer.
void put_pixel(uint32_t x, uint32_t y, uint32_t color);
  1. Clear Framebuffer - Lets you fill the entire framebuffer with one color.
void clear_framebuffer(uint32_t color);
  1. Put String - Lets you display multiline text with a size, foreground and background color on a given (x,y). You can specify the spacing between letters and lines. Supported characters are in text.c - feel free to add some if you want to.
void
put_string(
    const char *text,
    uint32_t x,
    uint32_t y,
    uint32_t size,
    uint32_t spacing,
    uint32_t line_spacing,
    uint32_t fg_color,
    uint32_t bg_color
);

Usage

The main function of a program that uses this engine should look something like this:

int main() {
	// initialize the engine
	if (engine_init(
		client_poll_event,
		client_update_framebuffer
	)) {
		// start the main game loop
		engine_start();
		// once the engine finishes, end gracefully
		engine_stop();
		return 0;
	} else {
		return 1;
	}
}

The client_poll_event() and client_update_framebuffer() are two special functions that let you poll events and update the framebuffer respectively. (Shocking, I know.) You are supposed to define them yourself and pass them as function pointers to engine_init().

Polling events allows you to handle mouse clicks, keyboard key presses, quitting the program and so on.

Updating the framebuffer means changing color values in the respective struct and thus getting an image on the screen.

An excerpt from the main game loop is below:

...

// main game loop
while(game_state->is_running) {
	uint64_t start = SDL_GetPerformanceCounter();

	// poll events
	while (SDL_PollEvent(&game_state->event)) {
		internal_state->engine_poll_events();
	}

	// call the user-defined framebuffer manipulation function
	internal_state->engine_update_framebuffer();

	...
}

...

If you want to modify the values for things like the window size or window name, (for now) go into include/engine.h and change them there on the #define lines.

S
Description
a very simple game engine / software renderer in C using SDL for visualizing the framebuffer
Readme GPL-3.0
166 KiB
0.2
Latest
2026-10-10 14:46:22 +02:00
Languages
C 96.1%
CMake 3.9%