diff options
| author | dario-loi <loi.1940849@studenti.uniroma1.it> | 2024-11-26 22:38:38 +0100 |
|---|---|---|
| committer | dario-loi <loi.1940849@studenti.uniroma1.it> | 2024-11-26 22:38:38 +0100 |
| commit | 7016d298ed1a5faf274ea5d300d7aea9dbc68b56 (patch) | |
| tree | 3f35ff268ba62d5d801f6287d1ee9f040bcb7e1e /examples | |
| parent | 51b1a6304a7bc832ac2998e2e123c63894cb9ac4 (diff) | |
Outline and filled circles, suppressed warnings
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/circle.c | 32 | ||||
| -rw-r--r-- | examples/text.c | 44 |
2 files changed, 54 insertions, 22 deletions
diff --git a/examples/circle.c b/examples/circle.c new file mode 100644 index 0000000..40ad800 --- /dev/null +++ b/examples/circle.c @@ -0,0 +1,32 @@ +#define FBGL_IMPLEMENTATION +#include "fbgl.h" + +int main(void) +{ + fbgl_t buffer; + if (fbgl_init("/dev/fb0", &buffer) == -1) { + fprintf(stdout, "Error: could not open framebuffer device\n"); + return -1; + } + + fbgl_point_t circ_center = { 960, 540 }; + + fbgl_set_bg(&buffer, 0x00FF0000); + uint32_t i = 0; + while (true) { + circ_center.x = 960 + 200 * cos(i * M_PI / 180); + circ_center.y = 540 + 200 * sin(i * M_PI / 180); + + fbgl_draw_circle_outline(circ_center.x - 240, + circ_center.y - 240, 40, 0xFFFFFF, + &buffer); + i = (i + 1) % 360; + fbgl_draw_circle_filled(480, 540, 40, 0xFFFFFF, &buffer); + usleep(10000); + } + + while (1) { + } + + return 0; +} diff --git a/examples/text.c b/examples/text.c index 7cbf3ff..9003e3c 100644 --- a/examples/text.c +++ b/examples/text.c @@ -16,35 +16,35 @@ int save_framebuffer_as_ppm(fbgl_t *fb, const char *filename) } // Write PPM header (P6 format - binary RGB) - fprintf(fp, "P6\n%zu %zu\n255\n", fb->width, fb->height); + fprintf(fp, "P6\n%u %u\n255\n", fb->width, fb->height); - // Allocate buffer for pixel data - uint8_t *pixel_buffer = malloc(fb->width * fb->height * 3); - if (!pixel_buffer) { + // Allocate buffer for pixel data + uint8_t* pixel_buffer = malloc(fb->width * fb->height * 3); + if (!pixel_buffer) { perror("Memory allocation error"); fclose(fp); return -1; } // Convert framebuffer to RGB - for (size_t y = 0; y < fb->height; y++) { - for (size_t x = 0; x < fb->width; x++) { - uint32_t pixel = fb->pixels[y * fb->width + x]; - - // Extract RGB components (assuming 32-bit ARGB or RGB) - uint8_t r = (pixel >> 16) & 0xFF; - uint8_t g = (pixel >> 8) & 0xFF; - uint8_t b = pixel & 0xFF; - - // Store in buffer for PPM - pixel_buffer[(y * fb->width + x) * 3] = r; - pixel_buffer[(y * fb->width + x) * 3 + 1] = g; - pixel_buffer[(y * fb->width + x) * 3 + 2] = b; - } - } - - // Write pixel data - fwrite(pixel_buffer, 1, fb->width * fb->height * 3, fp); + for (int32_t y = 0; y < fb->height; y++) { + for (int32_t x = 0; x < fb->width; x++) { + uint32_t pixel = fb->pixels[y * fb->width + x]; + + // Extract RGB components (assuming 32-bit ARGB or RGB) + uint8_t r = (pixel >> 16) & 0xFF; + uint8_t g = (pixel >> 8) & 0xFF; + uint8_t b = pixel & 0xFF; + + // Store in buffer for PPM + pixel_buffer[(y * fb->width + x) * 3] = r; + pixel_buffer[(y * fb->width + x) * 3 + 1] = g; + pixel_buffer[(y * fb->width + x) * 3 + 2] = b; + } + } + + // Write pixel data + fwrite(pixel_buffer, 1, fb->width * fb->height * 3, fp); // Cleanup free(pixel_buffer); |
