diff options
Diffstat (limited to 'example')
| -rw-r--r-- | example/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | example/line.c | 27 | ||||
| -rw-r--r-- | example/texture.c | 74 |
3 files changed, 0 insertions, 125 deletions
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt deleted file mode 100644 index 411945a..0000000 --- a/example/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -cmake_minimum_required(VERSION 3.21) - -project(fbglExamples C) - -include(../cmake/folders.cmake) - -if(PROJECT_IS_TOP_LEVEL) - find_package(fbgl REQUIRED) -endif() - -add_custom_target(run-examples) - -function(add_example NAME) - add_executable("${NAME}" "${NAME}.c") - target_link_libraries("${NAME}" PRIVATE fbgl::fbgl) - target_compile_features("${NAME}" PRIVATE c_std_99) - add_custom_target("run_${NAME}" COMMAND "${NAME}" VERBATIM) - add_dependencies("run_${NAME}" "${NAME}") - add_dependencies(run-examples "run_${NAME}") -endfunction() - -add_example(empty_example) - -add_folders(Example) diff --git a/example/line.c b/example/line.c deleted file mode 100644 index f20ec7e..0000000 --- a/example/line.c +++ /dev/null @@ -1,27 +0,0 @@ -#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, 0xFF0000); - fbgl_point_t start = { 0, 0 }; - fbgl_point_t end = { 1020, 1020 }; - for (int i = 0; i < 1890; i++) { - start.x = i; - fbgl_draw_line(start, end, 0xFFFFFF, &buffer); - for (int j = 0; j < 10000000; j++) { - } - } - fbgl_draw_line(start, end, 0x000000, &buffer); - - while (1) { - } - - return 0; -} diff --git a/example/texture.c b/example/texture.c deleted file mode 100644 index d1c25bd..0000000 --- a/example/texture.c +++ /dev/null @@ -1,74 +0,0 @@ -#define FBGL_IMPLEMENTATION -#include "../fbgl.h" -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> // for usleep - -int main(int argc, char **argv) -{ - // Initialize framebuffer - fbgl_t framebuffer; - if (fbgl_init(NULL, &framebuffer) != 0) { - fprintf(stderr, "Failed to initialize framebuffer.\n"); - return EXIT_FAILURE; - } - - // Load a TGA texture - const char *texture_path = argv[1]; - fbgl_tga_texture_t *texture = fbgl_load_tga_texture(texture_path); - if (!texture) { - fprintf(stderr, "Failed to load texture.\n"); - fbgl_destroy(&framebuffer); - return EXIT_FAILURE; - } - - // Set a background color (e.g., black) - fbgl_set_bg(&framebuffer, 0x000000); // Clear the framebuffer to black - - // Texture movement parameters - int texture_x = 0; // Initial horizontal position of the texture - int texture_y = 100; // Initial vertical position of the texture - int dx = 5; // Horizontal speed (adjust for desired marquee speed) - int dy = 3; // Vertical speed (adjust for desired marquee speed) - - // Main rendering loop - int framesize = 30 * 30; - while (framesize) { - // Clear the framebuffer (set background) - fbgl_set_bg(&framebuffer, 0x000000); - - // Draw the texture at the current position - fbgl_draw_texture(&framebuffer, texture, texture_x, texture_y); - - // Move the texture by updating its position - texture_x += dx; - texture_y += dy; - - // Reverse direction if the texture hits the screen boundary (X-axis) - if (texture_x <= 0 || - texture_x + texture->width >= framebuffer.width) { - dx = -dx; // Reverse horizontal direction when hitting the left or right edge - } - - // Reverse direction if the texture hits the screen boundary (Y-axis) - if (texture_y <= 0 || - texture_y + texture->height >= framebuffer.height) { - dy = -dy; // Reverse vertical direction when hitting the top or bottom edge - } - - usleep(50000); // Delay to make the marquee effect visible (adjust as needed) - framesize--; - } - - // Wait for the user to press the escape key before exiting - printf("Press ESC to exit...\n"); - while (!fbgl_check_esc_key()) { - // You can add additional rendering logic here if needed - } - - // Clean up - fbgl_destroy_texture(texture); - fbgl_destroy(&framebuffer); - - return EXIT_SUCCESS; -} |
