diff options
| author | Levent Kaya <42411502+lvntky@users.noreply.github.com> | 2024-11-24 15:52:47 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-24 15:52:47 +0300 |
| commit | bd57db823e34d6522e33adb37692f988a4e606ef (patch) | |
| tree | e5485cccfab864d90f327bb2e5a911c08fcfa224 | |
| parent | 5813f6a1c2b83d1c2a115d87ca684c5d1e11e299 (diff) | |
| parent | f1cde5cdc57e18a455859582ee2fd56b6e61c714 (diff) | |
Merge pull request #5 from dario-loi/master
[docs] Fixed example code in README.md
| -rw-r--r-- | README.md | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -25,9 +25,11 @@ ### Installation -No installation is required! Simply copy the `fbgl.h` file into your project directory and include it in your source files. +No installation is required! Simply copy the `fbgl.h` file into your project directory and include it in your source files, +while also defining the `FBGL_IMPLEMENTATION` macro in one of your source files. ```c +#define FBGL_IMPLEMENTATION #include "fbgl.h" ``` @@ -40,31 +42,36 @@ No installation is required! Simply copy the `fbgl.h` file into your project dir Here’s a simple program that initializes the framebuffer, clears it to a blue color, and draws a red diagonal line. ```c -#include <stdio.h> #include "fbgl.h" +#define FBGL_IMPLEMENTATION +#include <stdio.h> + +int main() +{ + + fbgl_t buffer; -int main() { // Initialize the framebuffer - if (fbgl_init("/dev/fb0") != 0) { + if (fbgl_init("/dev/fb0", &buffer) != 0) { fprintf(stderr, "Failed to initialize framebuffer\n"); return 1; } - printf("Framebuffer size: %dx%d\n", fbgl_get_width(), fbgl_get_height()); + printf("Framebuffer size: %dx%d\n", fb_get_width(), fb_get_height()); // Clear framebuffer to blue fbgl_clear(0x0000FFFF); // Blue color // Draw a red diagonal line - for (int i = 0; i < fbgl_get_width() && i < fbgl_get_height(); i++) { - fbgl_put_pixel(i, i, 0xFFFF0000); // Red + for (int i = 0; i < fb_get_width() && i < fb_get_height(); i++) { + fbgl_put_pixel(i, i, 0xFFFF0000, &buffer); // Red } // Wait for user input before exiting getchar(); // Clean up - fbgl_destroy(); + fbgl_destroy(&buffer); return 0; } ``` |
