{"id":23096815,"url":"https://github.com/lvntky/fbgl","last_synced_at":"2025-08-16T12:31:54.488Z","repository":{"id":263977326,"uuid":"890565455","full_name":"lvntky/fbgl","owner":"lvntky","description":"Lightweight 2D Framebuffer Library for Linux","archived":false,"fork":false,"pushed_at":"2024-11-28T21:41:47.000Z","size":15412,"stargazers_count":32,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-28T22:26:39.552Z","etag":null,"topics":["2d","2d-graphics","embedded","fbdev","framebuffer","graphics","graphics-library","graphics-rendering","library","lightweight","unix"],"latest_commit_sha":null,"homepage":"https://lvntky.github.io/fbgl/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lvntky.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}},"created_at":"2024-11-18T19:45:00.000Z","updated_at":"2024-11-28T21:41:25.000Z","dependencies_parsed_at":"2024-11-21T13:01:49.785Z","dependency_job_id":null,"html_url":"https://github.com/lvntky/fbgl","commit_stats":null,"previous_names":["lvntky/fbgl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvntky%2Ffbgl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvntky%2Ffbgl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvntky%2Ffbgl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lvntky%2Ffbgl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lvntky","download_url":"https://codeload.github.com/lvntky/fbgl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230037811,"owners_count":18163195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["2d","2d-graphics","embedded","fbdev","framebuffer","graphics","graphics-library","graphics-rendering","library","lightweight","unix"],"created_at":"2024-12-16T22:48:32.790Z","updated_at":"2025-08-16T12:31:54.462Z","avatar_url":"https://github.com/lvntky.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\t\n# fbgl: Lightweight 2D Framebuffer Library for Linux\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/e9071bbf1ec345fab63a8020e7867337)](https://app.codacy.com/gh/lvntky/fbgl/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\n\n`fbgl` (Framebuffer Graphics Library) is a minimalistic, **header-only** 2D framebuffer library written in C. Designed for simplicity and performance, `fbgl` provides an intuitive API for directly manipulating the Linux framebuffer device (`/dev/fb0`). Whether you're experimenting with low-level graphics or building lightweight graphical applications, `fbgl` offers the foundation you need.\n\n---\n\n## Features\n\n- **Header-only design**: Include `fbgl.h` and start coding.\n- **Direct framebuffer rendering**: Writes directly to `/dev/fb0` for high performance.\n- **Simple API**: Easy-to-use functions for initializing, clearing, and drawing.\n- **Lightweight**: Minimal dependencies, using only standard Linux libraries.\n- **Custom rendering**: Draw pixels, lines, and shapes directly to the framebuffer.\n\n---\n\n## Getting Started\n\n### Prerequisites\n\n- A Linux-based system with framebuffer support.\n- Development tools like GCC.\n- Access to `/dev/fb0` (requires elevated permissions or proper user configuration).\n\n### Installation\n\nNo installation is required! Simply copy the `fbgl.h` file into your project directory and include it in your source files,\nwhile also defining the `FBGL_IMPLEMENTATION` macro in one of your source files.\n\n```c\n#define FBGL_IMPLEMENTATION\n#include \"fbgl.h\"\n```\n\n---\n\n## Usage\n\n### Example Program\n\nHere’s a simple program that initializes the framebuffer, clears it to a blue color, and draws a red diagonal line.\n\n```c\n#define FBGL_IMPLEMENTATION\n#include \"fbgl.h\"\n#include \u003cstdio.h\u003e\n\nint main()\n{\n\n    fbgl_t buffer;\n\n    // Initialize the framebuffer\n    if (fbgl_init(\"/dev/fb0\", \u0026buffer) != 0) {\n        fprintf(stderr, \"Failed to initialize framebuffer\\n\");\n        return 1;\n    }\n\n    printf(\"Framebuffer size: %dx%d\\n\", fb_get_width(), fb_get_height());\n\n    // Clear framebuffer to blue\n    fbgl_clear(0x0000FFFF); // Blue color\n\n    // Draw a red diagonal line\n    for (int i = 0; i \u003c fb_get_width() \u0026\u0026 i \u003c fb_get_height(); i++) {\n        fbgl_put_pixel(i, i, 0xFFFF0000, \u0026buffer); // Red\n    }\n\n    // Wait for user input before exiting\n    getchar();\n\n    // Clean up\n    fbgl_destroy(\u0026buffer);\n    return 0;\n}\n```\n\nCompile the program:\n\n```bash\ngcc -o example main.c\n```\n\nRun the program with elevated permissions to access `/dev/fb0`:\n\n```bash\nsudo ./example\n```\n\n---\n\n## API Reference\n\n### Initialization and Cleanup\n\n#### `int fbgl_init(const char *device);`\nInitializes the framebuffer.\n\n- **Parameters**:  \n  `device`: Path to the framebuffer device (e.g., `/dev/fb0`).\n\n- **Returns**:  \n  `0` on success, `-1` on failure.\n\n#### `void fbgl_destroy(void);`\nDestroys the framebuffer and releases resources.\n\n---\n\n### Drawing Functions\n\n#### `void fbgl_clear(uint32_t color);`\nFills the entire framebuffer with a specified color.\n\n- **Parameters**:  \n  `color`: 32-bit ARGB color (e.g., `0xFFFF0000` for red).\n\n#### `void fbgl_put_pixel(int x, int y, uint32_t color);`\nSets a pixel at the specified position to the given color.\n\n- **Parameters**:  \n  `x, y`: Pixel coordinates.  \n  `color`: 32-bit ARGB color.\n\n---\n\n### Utility Functions\n\n#### `int fbgl_get_width(void);`\nReturns the width of the framebuffer in pixels.\n\n#### `int fbgl_get_height(void);`\nReturns the height of the framebuffer in pixels.\n\n---\n\n## How It Works\n\n1. **Framebuffer Device**: `fbgl` uses the Linux framebuffer device (`/dev/fb0`) to directly access the screen memory.\n2. **Memory Mapping**: The framebuffer is mapped into user-space memory using `mmap`, allowing for direct pixel manipulation.\n3. **Direct Rendering**: Pixels are written directly to the framebuffer, bypassing higher-level graphics APIs.\n\n---\n\n## Limitations\n\n- **Platform-specific**: Works only on Linux systems with framebuffer support.\n- **Root permissions**: Access to `/dev/fb0` often requires `sudo`.\n- **No hardware acceleration**: Rendering is done in software, so performance depends on CPU speed.\n\n---\n\n## Roadmap\n\nFuture improvements for `fbgl` may include:\n- Support for double buffering.\n- More advanced drawing primitives (e.g., circles, filled polygons).\n- Cross-platform abstraction for non-Linux systems.\n- Text rendering using bitmap fonts.\n- Performance optimizations for large resolutions.\n\n---\n\n## Contributing\n\nContributions are welcome! If you’d like to improve `fbgl`, add features, or fix bugs:\n1. Fork the repository.\n2. Create a new branch for your changes.\n3. Submit a pull request with a clear description of your updates.\n\n---\n\n## License\n\n`fbgl` is licensed under the MIT License. See the `LICENSE` file for details.\n\n---\n\n## Acknowledgments\n\n- Inspired by the simplicity of low-level graphics programming.\n- Thanks to the Linux community for making framebuffer programming accessible!\n- See the [acknowledgements](./acknowledgements.md) for more details.\n\n---\n\n## Showcase\n\nFirst Texture Rendering\n\n![fist texture render](./docs/texture.gif)\n\nPSF Text in fbgl\n\n![text](./docs/text.png)\n\nSimple ray casting demo\n\n![ray](./docs/ray_demo.gif)\n\n---\n\n## Testing on virtual framebuffer\nIf you want to test your programs that made with FBGL without accelerate you user privilages on Linux, fallow these streps:\n\n```sh\nchmod +x fbgl_test_virtual_fb.sh\n./fbgl_test_virtual_fb.sh\n```\nThen, open a VNC viewer (like TigerVNC), connect to:\n```sh\nlocalhost:5900\n```\n\n## Contact\n\nIf you have questions or suggestions, feel free to reach out via GitHub or email.\n\nHappy coding with `fbgl`! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvntky%2Ffbgl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flvntky%2Ffbgl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flvntky%2Ffbgl/lists"}