diff options
| author | dario-loi <loi.1940849@studenti.uniroma1.it> | 2024-11-24 20:21:45 +0100 |
|---|---|---|
| committer | dario-loi <loi.1940849@studenti.uniroma1.it> | 2024-11-24 20:21:45 +0100 |
| commit | a3bfd065071e2dd4e772fae9da7908ce523148c6 (patch) | |
| tree | 68b062d79a1b5e59c2bcba2ca8df1cef9852f656 | |
| parent | 274cacc5fadb3c3a220b833f027eee47cbda824c (diff) | |
| parent | cd0a47245a54c249eca7ef1c0d86bc4aa3489e9b (diff) | |
Merge branch 'master' into bugfixes
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | asset/bmp/FLAG_B24.BMP | bin | 46182 -> 0 bytes | |||
| -rw-r--r-- | asset/font.psf | bin | 29728 -> 0 bytes | |||
| -rw-r--r-- | asset/font_2.ttf | bin | 120240 -> 0 bytes | |||
| -rw-r--r-- | asset/tga_textures/doom.tga | bin | 0 -> 1440018 bytes | |||
| -rw-r--r-- | asset/tr.tga | bin | 4367378 -> 0 bytes | |||
| -rw-r--r-- | example/.gitignore | 1 | ||||
| -rw-r--r-- | example/empty_example.c | 53 | ||||
| -rw-r--r-- | example/raw_mode.c | 20 | ||||
| -rw-r--r-- | example/rectangle.c | 61 | ||||
| -rw-r--r-- | example/red.c | 14 | ||||
| -rw-r--r-- | examples/texture.c | 4 | ||||
| -rw-r--r-- | fbgl.h | 10 |
13 files changed, 157 insertions, 9 deletions
@@ -1,2 +1,3 @@ build -.vscode
\ No newline at end of file +.vscode +fbgl-test-env/ diff --git a/asset/bmp/FLAG_B24.BMP b/asset/bmp/FLAG_B24.BMP Binary files differdeleted file mode 100644 index b61d368..0000000 --- a/asset/bmp/FLAG_B24.BMP +++ /dev/null diff --git a/asset/font.psf b/asset/font.psf Binary files differdeleted file mode 100644 index 071330e..0000000 --- a/asset/font.psf +++ /dev/null diff --git a/asset/font_2.ttf b/asset/font_2.ttf Binary files differdeleted file mode 100644 index af3f57c..0000000 --- a/asset/font_2.ttf +++ /dev/null diff --git a/asset/tga_textures/doom.tga b/asset/tga_textures/doom.tga Binary files differnew file mode 100644 index 0000000..4f7a447 --- /dev/null +++ b/asset/tga_textures/doom.tga diff --git a/asset/tr.tga b/asset/tr.tga Binary files differdeleted file mode 100644 index 86f10ae..0000000 --- a/asset/tr.tga +++ /dev/null diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/example/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/example/empty_example.c b/example/empty_example.c new file mode 100644 index 0000000..8c7d32d --- /dev/null +++ b/example/empty_example.c @@ -0,0 +1,53 @@ +#define FBGL_IMPLEMENTATION +// #define FBGL_HIDE_CURSOR +#define FBGL_USE_FREETYPE +#include "../fbgl.h" + +#include <stddef.h> +#include <stdio.h> + +int main() +{ + printf("version %s\n", fbgl_version_info()); + printf("name %s\n", fbgl_name_info()); + + fbgl_t buffer; + if (fbgl_init("/dev/fb0", &buffer) == -1) { + fprintf(stdout, "Error: could not open framebuffer device\n"); + return -1; + } + int color = 0x00000000; + + FT_Library library = fbgl_freetype_init(); + if (!library) { + fbgl_destroy(&buffer); + return -1; + } + + FT_Face face = fbgl_load_font(library, "../asset/font_2.ttf", + 24); // Adjust path and size + if (!face) { + fbgl_freetype_cleanup(library); + fbgl_destroy(&buffer); + return -1; + } + + // Render text to framebuffer + fbgl_render_freetype_text(&buffer, library, face, "Hello, World!", 50, + 50); + + // Main loop checking for ESC key + int l = 0; + while (1) { + if (fbgl_check_esc_key()) { + fprintf(stdout, "ESC pressed\n"); + break; + } + // fbgl_set_bg(&buffer, i++); // Set background color to + for (int i = 0x000000; i <= 0xFFFFFF; i++) { + fbgl_set_bg(&buffer, i); + } + } + fbgl_destroy(&buffer); + return 0; +} diff --git a/example/raw_mode.c b/example/raw_mode.c new file mode 100644 index 0000000..449a824 --- /dev/null +++ b/example/raw_mode.c @@ -0,0 +1,20 @@ +#define FBGL_IMPLEMENTATION +#include "../fbgl.h" +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + fbgl_t fb; + fbgl_init("/dev/fb0", &fb); + + fbgl_set_bg(&fb, 0xFFFFFF); + + while (1) { + if (fbgl_check_esc_key()) { + printf("pressed"); + fbgl_set_bg(&fb, 0x000000); + } + } + + return 0; +} diff --git a/example/rectangle.c b/example/rectangle.c new file mode 100644 index 0000000..ecc1afd --- /dev/null +++ b/example/rectangle.c @@ -0,0 +1,61 @@ +#define FBGL_IMPLEMENTATION +#include "../fbgl.h" + +int main(int argc, char *argv[]) +{ + fbgl_t buffer; + if (fbgl_init("/dev/fb0", &buffer) == -1) { + fprintf(stdout, "Error: could not open framebuffer device\n"); + return -1; + } + + fbgl_set_bg(&buffer, 0xFFFFFF); // Set the background to white + + fbgl_point_t start = { 100, 100 }; + fbgl_point_t end = { 200, 200 }; + fbgl_draw_rectangle_outline(start, end, 0xFF0000, + &buffer); // Draw red rectangle outline + + fbgl_point_t start2 = { 600, 400 }; + fbgl_point_t end2 = { 800, 800 }; + uint32_t colors[] = { 0xFFC00, 0x00FF00, 0x0000FF, + 0xFF00FF }; // Yellow, Green, Blue, Magenta + size_t color_index = 0; + + // Initial position of the marquee rectangle + int dx = 15; // Horizontal speed + int dy = 8; // Vertical speed + + while (1) { + // Clear the framebuffer (set background) + fbgl_set_bg(&buffer, 0xFFFFFF); + + // Draw the moving filled rectangle + fbgl_draw_rectangle_filled(start2, end2, colors[color_index], + &buffer); + + // Move the filled rectangle by updating its position + start2.x += dx; + end2.x += dx; + start2.y += dy; + end2.y += dy; + + // Reverse direction if the rectangle hits the screen boundary + if (start2.x <= 0 || end2.x >= buffer.width) { + dx = -dx; + color_index++; + } + if (start2.y <= 0 || end2.y >= buffer.height) { + dy = -dy; + color_index++; + } + if (color_index >= 4) { + color_index = 0; + } + + usleep(50000); // Delay to make the animation visible (adjust as needed) + } + + fbgl_destroy(&buffer); + return 0; +} diff --git a/example/red.c b/example/red.c new file mode 100644 index 0000000..7f64dbd --- /dev/null +++ b/example/red.c @@ -0,0 +1,14 @@ +#define FBGL_IMPLEMENTATION +#include "../fbgl.h" +#include <stdio.h> + +int main(int argc, char *argv[]) +{ + fbgl_t fb; + fbgl_init("/dev/fb0", &fb); + fbgl_set_bg(&fb, 0xFF0000); + while (1) { + } + + return 0; +} diff --git a/examples/texture.c b/examples/texture.c index 03311ea..75a67d7 100644 --- a/examples/texture.c +++ b/examples/texture.c @@ -32,7 +32,8 @@ int main(int argc, char **argv) int dy = 3; // Vertical speed (adjust for desired marquee speed) // Main rendering loop - while (1) { + int framesize = 30 * 30; + while (framesize) { // Clear the framebuffer (set background) fbgl_set_bg(&framebuffer, 0x000000); @@ -56,6 +57,7 @@ int main(int argc, char **argv) } usleep(50000); // Delay to make the marquee effect visible (adjust as needed) + framesize--; } // Wait for the user to press the escape key before exiting @@ -161,10 +161,6 @@ void fbgl_clear(uint32_t color); void fbgl_put_pixel(int x, int y, uint32_t color, fbgl_t *fb); void fbgl_draw_line(fbgl_point_t x, fbgl_point_t y, uint32_t color, fbgl_t *fb); -/** - * Display methods - */ -void fbgl_display(void); /** * Access framebuffer data methods @@ -291,14 +287,14 @@ void fbgl_set_bg(fbgl_t *fb, uint32_t color) #endif // DEBUG // Fill the entire framebuffer with the specified color - for (uint32_t i = 0; i < fb->width * fb->height; i++) { + for (int32_t i = 0; i < fb->width * fb->height; i++) { fb->pixels[i] = color; } } void fbgl_put_pixel(int x, int y, uint32_t color, fbgl_t *fb) { -#ifdef DEBUG +#ifdef FBGL_VALIDATE_PUT_PIXEL if (!fb || !fb->pixels) { fprintf(stderr, "Error: framebuffer not initialized.\n"); return; @@ -307,7 +303,7 @@ void fbgl_put_pixel(int x, int y, uint32_t color, fbgl_t *fb) if (x < 0 || x >= fb->width || y < 0 || y >= fb->height) { return; // Ignore out-of-bound coordinates } -#endif // DEBUG +#endif // FBGL_VALIDATE_PUT_PIXEL const size_t index = y * fb->width + x; fb->pixels[index] = color; |
