{"id":15049199,"url":"https://github.com/ztry8/termlib","last_synced_at":"2026-02-06T09:03:53.432Z","repository":{"id":243668015,"uuid":"813081039","full_name":"Ztry8/Termlib","owner":"Ztry8","description":"Lightweight and simple Rust/C/C++ library with a single header for terminal graphics","archived":false,"fork":false,"pushed_at":"2025-11-15T12:06:41.000Z","size":355,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-15T14:18:00.054Z","etag":null,"topics":["c","console","cpp","gamedev","graphics-engine","header-only-library","one-header","roguelike-library","roguelikedev","rust-lang","terminal","terminal-emulator"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ztry8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-10T12:57:40.000Z","updated_at":"2025-11-15T12:06:46.000Z","dependencies_parsed_at":"2024-06-10T14:45:44.657Z","dependency_job_id":"7892d8f9-08a6-47f2-a5bb-6641a9c1a03f","html_url":"https://github.com/Ztry8/Termlib","commit_stats":null,"previous_names":["ztry8/ascii-engine","ztry8/termlib"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Ztry8/Termlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ztry8%2FTermlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ztry8%2FTermlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ztry8%2FTermlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ztry8%2FTermlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ztry8","download_url":"https://codeload.github.com/Ztry8/Termlib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ztry8%2FTermlib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29156402,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T07:18:23.844Z","status":"ssl_error","status_checked_at":"2026-02-06T07:13:32.659Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","console","cpp","gamedev","graphics-engine","header-only-library","one-header","roguelike-library","roguelikedev","rust-lang","terminal","terminal-emulator"],"created_at":"2024-09-24T21:19:03.464Z","updated_at":"2026-02-06T09:03:53.420Z","avatar_url":"https://github.com/Ztry8.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Termlib\n[![GitHub last commit](https://img.shields.io/github/last-commit/ztry8/termlib)](https://github.com/ztry8/termlib/commits)\n[![License](https://img.shields.io/github/license/ztry8/termlib)](https://github.com/ztry8/termlib/blob/main/LICENSE)\n## Lightweight and simple Rust/C/C++ library with a single header for terminal graphics written in C\n![screenshot](https://github.com/Ztry8/ASCII-Engine/blob/main/assets/3.png)\n![screenshot](https://github.com/Ztry8/ASCII-Engine/blob/main/assets/1.PNG)\n\n### About library\n\n#### Library Goals\nThe main goal of the library is to provide fast, easy, and efficient tool for rendering, playback and input proccesing.   \nIt was originally intended to be used to create [traditional roguelikes](https://roguebasin.com/index.php/Main_Page).\n\n#### Font\nThe library uses 8x8 EGA font on 80x45 screen. Used 16 colors from [default EGA palette](https://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter#Color_palette).  \nThe font used for graphics is built into the header code.\n\n#### Rendering\nThe library uses batching for rendering tiles, tile culling has been implemented.   \nThe library has VSync only as a frame rate cap.   \nThe graphics API provided by SDL2 (opengl or direct2d, etc.)   \nSoftware (CPU) rendering is used as a fallback.\n\n#### Input\nThe library uses the keyboard and mouse as input.\n\n#### Sounds\nThe library supports loading sounds from `.wav` files and playing them.\n\n#### What platforms does the library work on?\nI tested it on Windows 10, Debian 12, and macOS 10.13,   \nand all functions worked correctly across these platforms.   \nThe library should be compatible with all platforms supported by SDL2.\n\n#### Does it work with C++?\nYes, the library has been tested with C++ and works pretty well.\n\n#### Does it work with Rust?\nThe library is fully tested with Rust   \nI’m even developing my own game using this library and Rust.\n\n### [Building for Rust here](https://github.com/Ztry8/Termlib/blob/main/RustBuilding.md)\n\n### Building for C/C++\n\n#### Windows\nEngine is based on SDL2.    \nYou just need to copy the `src/core.h` file to your working directory and then link project with SDL2.   \n[Perhaps this will help you](https://wiki.libsdl.org/SDL2/Installation#windows_xpvista7810)\n\n#### Distributing your .exe\nAll necessary assets are built into your library's `core.h` file,   \nand if you use sounds in your game, you'll also need to distribute them along with your executable file.   \nIf you have chosen the dynamic linking type with SDL2, place [this .dll for x86](https://github.com/libsdl-org/SDL/releases/download/release-2.32.10/SDL2-2.32.10-win32-x86.zip) or [this for x64](https://github.com/libsdl-org/SDL/releases/download/release-2.32.10/SDL2-2.32.10-win32-x64.zip) in the same folder with .exe\n\n#### Linux/MacOs\nMake sure you have `git`, `cmake`, `ninja` or `make`, [`sdl2-dev-package`](https://github.com/Ztry8/Termlib/blob/main/RustBuilding.md#sdl2-dev-for-linux) installed.\n\n```\ngit clone https://github.com/Ztry8/Termlib.git\ncd Termlib/\nmkdir build/\ncd build/\n```\nFor  `ninja` (Recommended):\n```\ncmake ../src -G Ninja\nninja\n```\nFor  `make`:\n```\ncmake ../src\nmake\n```\nAfter that, you can see your application as `build/Termlib-App`.\n\n#### Distributing your game for Linux/MacOs\nIf you compiled the game using the instructions above,   \nthe player just need install SDL2 on his system using the following commands:\n\nDebian-based:\n```bash\nsudo apt update\nsudo apt install libsdl2-2.0-0\n```\nRHEL-based:\n```bash\nsudo dnf check-update\nsudo dnf install SDL2\n```\nArch-based:\n```bash\nsudo pacman -Sy\nsudo pacman -S sdl2\n```\nMacOs:\n```bash\nsudo port selfupdate\nsudo port install libsdl2\n```\n\nand if you use sounds in your game, you'll also need to distribute them along with your executable file.   \n\n### Usage\n\n#### Example\n```c\n// #define SHOW_FPS\n#include \"core.h\"\n\nwav_sound *drink;\n\nvoid keyboard_game(SDL_Scancode key, renderer* renderer) {\n\tif (key == SDL_SCANCODE_E) play_wav(drink, renderer);\n}\n\nvoid mouse_game(renderer* renderer, signed x, signed y, char button) {\n\tif (button == 0) draw_tile(renderer, '@', BRIGHT_YELLOW, x, y);\n\telse draw_tile(renderer, '@', MAGENTA, x, y);\n}\n\nvoid update_game(renderer* renderer, float frame_time) {\n\tfor (unsigned char i = 0; i \u003c 255; i++) {\n\t\tdraw_tile(renderer, i, BRIGHT_YELLOW, 15 + i%16, i/16);\n\t}\n\n\tprint(renderer, \"Hello World!\", BLUE, 0, 0);\n\tprint(renderer, \"Hello World!\", GREEN, 0, 1);\n\tprint(renderer, \"Hello World!\", CYAN, 0, 2);\n\tprint(renderer, \"Hello World!\", RED, 0, 3);\n\tprint(renderer, \"Hello World!\", MAGENTA, 0, 4);\n\tprint(renderer, \"Hello World!\", BROWN, 0, 5);\n}\n\nvoid shutdown_game() {}\n\nint main() {\n\trenderer core;\n\tif (init_renderer(\u0026core, 1, 2, \"MyGame\")) return 1;\n\n\tdrink = load_wav(\"../assets/drink.wav\", \u0026core);\n\n\trun_render(\u0026core);\n\tshutdown_renderer(\u0026core);\n\treturn 0;\n}\n```\nResult:\n![screenshot](https://github.com/Ztry8/ASCII-Engine/blob/main/assets/example.png)\n#### Run engine\nDefine `SHOW_FPS` before including header for displaying fps instead of app name.  \n\nIn 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.   \n`scale` = 1: 640x360 resolution,   \n`scale` = 2: 1280x720 resolution, etc.    \nThen, activate and run the `renderer` using the `run_render(renderer*)` function.   \nFinally, release and free the `renderer` by using the `shutdown_renderer(renderer*)` function.\n\n#### Functions\n\n##### Callbacks:\n```c\nkeyboard_game(SDL_Scancode key, renderer* renderer)\n```   \nUsed for processing keyboards's input, see [SDL_Scancode](https://wiki.libsdl.org/SDL2/SDL_Scancode)   \n\n```c\nmouse_game(renderer* renderer, int x, int y, char button)\n```   \nUsed for processing mouse's input, x and y is coordinates of cursor,\n| char button value  |   meaning    |\n| -------------      | --------     |\n| 0 | No button was pressed         |\n| 1 | Left button was pressed       | \n| 2 | Right button was pressed      | \n| 3 | Middle button was pressed     | \n\n```c\nupdate_game(renderer*)\n```  \nUsed for processing graphics and is called every frame.   \n\n```c\nshutdown_game()\n```   \nUsed for free up resources in your game.   \n\n##### Called function:   \n```c\ndraw_tile(renderer*, char, unsigned char*, int, int)\n```   \nUsed for displaying and drawing tiles.   \nThe second argument is a character to draw. '#' or '@' for example.   \nThe third argument is color. You can also look at the names in the header or make up own.   \nThe fourth and fifth arguments are the x and y coordinates.   \n\n```c\ndraw_tile_camera(renderer*, char, unsigned char*, int, int, int, int)\n```   \nUsed for displaying and drawing tiles relative to the center of the screen.   \nThe second argument is a character to draw. '#' or '@' for example.   \nThe third argument is color. You can also look at the names in the header or make up own.   \nThe fourth and fifth arguments are the x and y coordinates.   \nThe sixth and seventh arguments are the x and y coordinates of the camera.\n\n```c\nprint(renderer*, const char*, unsigned char*, long, long)\n```   \nUsed for displaying text.   \nThe second argument is a text to display.    \nThe third argument is color. You can also look at the names in the header or make up own.   \nThe fourth and fifth arguments are the x and y coordinates.\n\n```c\nload_wav(const char*, renderer*)\n```   \nUsed for loading sound in WAV format.\nThe first argument is a path to file.\nReturns wav_sound*\n\n```c\nvoid play_wav(wav_sound*, renderer* core)\n```   \nUsed for playing sound in WAV format.\nThe first argument is a sound to play.\n\n### TODO\n- [x] Added tile culling and camera support.\n- [x] Added print function.   \n- [x] Added support for sound.\n- [x] Added mouse support\n- [ ] Add feature for using own font\n- [ ] Add cross-compiling\n\n### Contributing\nAny issues and pull requests are welcome!   \nFeel free to suggest improvements, report bugs, or add new features.   \nPlease keep in mind the main goal of this project: a single header and simplicity.\n\n### Assets\n`assets/drink.wav` and font in `core.h` under CC0 license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fztry8%2Ftermlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fztry8%2Ftermlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fztry8%2Ftermlib/lists"}