The main goal of the library is to provide fast, easy, and efficient tool for rendering, playback and input proccesing.
It was originally intended to be used to create traditional roguelikes.
The library uses 8x8 EGA font on 80x45 screen. Used 16 colors from default EGA palette.
The font used for graphics is built into the header code.
The library uses batching for rendering tiles, tile culling has been implemented.
The library has VSync only as a frame rate cap.
The graphics API provided by SDL2 (opengl or direct2d, etc.)
Software (CPU) rendering is used as a fallback.
The library uses the keyboard and mouse as input.
The library supports loading sounds from .wav files and playing them.
I tested it on Windows 10, Debian 12, and macOS 10.13,
and all functions worked correctly across these platforms.
The library should be compatible with all platforms supported by SDL2.
Yes, the library has been tested with C++ and works pretty well.
The library is fully tested with Rust
I’m even developing my own game using this library and Rust.
Engine is based on SDL2.
You just need to copy the src/core.h file to your working directory and then link project with SDL2.
Perhaps this will help you
All necessary assets are built into your library's core.h file,
and if you use sounds in your game, you'll also need to distribute them along with your executable file.
If you have chosen the dynamic linking type with SDL2, place this .dll for x86 or this for x64 in the same folder with .exe
Make sure you have git, cmake, ninja or make, sdl2-dev-package installed.
git clone https://github.com/Ztry8/Termlib.git
cd Termlib/
mkdir build/
cd build/
For ninja (Recommended):
cmake ../src -G Ninja
ninja
For make:
cmake ../src
make
After that, you can see your application as build/Termlib-App.
If you compiled the game using the instructions above,
the player just need install SDL2 on his system using the following commands:
Debian-based:
sudo apt update
sudo apt install libsdl2-2.0-0RHEL-based:
sudo dnf check-update
sudo dnf install SDL2Arch-based:
sudo pacman -Sy
sudo pacman -S sdl2MacOs:
sudo port selfupdate
sudo port install libsdl2and if you use sounds in your game, you'll also need to distribute them along with your executable file.
// #define SHOW_FPS
#include "core.h"
wav_sound *drink;
void keyboard_game(SDL_Scancode key, renderer* renderer) {
if (key == SDL_SCANCODE_E) play_wav(drink, renderer);
}
void mouse_game(renderer* renderer, signed x, signed y, char button) {
if (button == 0) draw_tile(renderer, '@', BRIGHT_YELLOW, x, y);
else draw_tile(renderer, '@', MAGENTA, x, y);
}
void update_game(renderer* renderer, float frame_time) {
for (unsigned char i = 0; i < 255; i++) {
draw_tile(renderer, i, BRIGHT_YELLOW, 15 + i%16, i/16);
}
print(renderer, "Hello World!", BLUE, 0, 0);
print(renderer, "Hello World!", GREEN, 0, 1);
print(renderer, "Hello World!", CYAN, 0, 2);
print(renderer, "Hello World!", RED, 0, 3);
print(renderer, "Hello World!", MAGENTA, 0, 4);
print(renderer, "Hello World!", BROWN, 0, 5);
}
void shutdown_game() {}
int main() {
renderer core;
if (init_renderer(&core, 1, 2, "MyGame")) return 1;
drink = load_wav("../assets/drink.wav", &core);
run_render(&core);
shutdown_renderer(&core);
return 0;
}Define SHOW_FPS before including header for displaying fps instead of app name.
In the main files, you need to create and initialize the Core using the init_renderer() function, which takes a renderer*, vsync, scale as an arguments.
scale = 1: 640x360 resolution,
scale = 2: 1280x720 resolution, etc.
Then, activate and run the renderer using the run_render(renderer*) function.
Finally, release and free the renderer by using the shutdown_renderer(renderer*) function.
keyboard_game(SDL_Scancode key, renderer* renderer)Used for processing keyboards's input, see SDL_Scancode
mouse_game(renderer* renderer, int x, int y, char button)Used for processing mouse's input, x and y is coordinates of cursor,
| char button value | meaning |
|---|---|
| 0 | No button was pressed |
| 1 | Left button was pressed |
| 2 | Right button was pressed |
| 3 | Middle button was pressed |
update_game(renderer*)Used for processing graphics and is called every frame.
shutdown_game()Used for free up resources in your game.
draw_tile(renderer*, char, unsigned char*, int, int)Used for displaying and drawing tiles.
The second argument is a character to draw. '#' or '@' for example.
The third argument is color. You can also look at the names in the header or make up own.
The fourth and fifth arguments are the x and y coordinates.
draw_tile_camera(renderer*, char, unsigned char*, int, int, int, int)Used for displaying and drawing tiles relative to the center of the screen.
The second argument is a character to draw. '#' or '@' for example.
The third argument is color. You can also look at the names in the header or make up own.
The fourth and fifth arguments are the x and y coordinates.
The sixth and seventh arguments are the x and y coordinates of the camera.
print(renderer*, const char*, unsigned char*, long, long)Used for displaying text.
The second argument is a text to display.
The third argument is color. You can also look at the names in the header or make up own.
The fourth and fifth arguments are the x and y coordinates.
load_wav(const char*, renderer*)Used for loading sound in WAV format. The first argument is a path to file. Returns wav_sound*
void play_wav(wav_sound*, renderer* core)Used for playing sound in WAV format. The first argument is a sound to play.
- Added tile culling and camera support.
- Added print function.
- Added support for sound.
- Added mouse support
- Add feature for using own font
- Add cross-compiling
Any issues and pull requests are welcome!
Feel free to suggest improvements, report bugs, or add new features.
Please keep in mind the main goal of this project: a single header and simplicity.
assets/drink.wav and font in core.h under CC0 license