diff options
| -rw-r--r-- | example/.gitignore | 3 | ||||
| -rw-r--r-- | example/CMakeLists.txt | 39 | ||||
| -rw-r--r-- | example/empty_example.c | 74 | ||||
| -rw-r--r-- | example/line.c | 7 | ||||
| -rw-r--r-- | example/raw_mode.c | 21 | ||||
| -rw-r--r-- | example/rectangle.c | 102 | ||||
| -rw-r--r-- | example/red.c | 13 |
7 files changed, 134 insertions, 125 deletions
diff --git a/example/.gitignore b/example/.gitignore index 07ac165..4b44f82 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,2 +1 @@ -build/ -core.* +build / core.* diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 411945a..837e6e8 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,24 +1,31 @@ cmake_minimum_required(VERSION 3.21) -project(fbglExamples C) + project(fbglExamples C) -include(../cmake/folders.cmake) + include(../ cmake / folders.cmake) -if(PROJECT_IS_TOP_LEVEL) - find_package(fbgl REQUIRED) -endif() + if (PROJECT_IS_TOP_LEVEL) find_package( + fbgl REQUIRED) endif() -add_custom_target(run-examples) + 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() + 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_example( + empty_example) -add_folders(Example) + add_folders( + Example) diff --git a/example/empty_example.c b/example/empty_example.c index aee9232..cbb69c4 100644 --- a/example/empty_example.c +++ b/example/empty_example.c @@ -8,46 +8,46 @@ int main() { - printf("version %s\n", fbgl_version_info()); - printf("name %s\n", fbgl_name_info()); + 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; - } + 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_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; - } + FT_Library library = fbgl_freetype_init(); + if (!library) { + fbgl_destroy(&buffer); + return -1; + } - // Render text to framebuffer - fbgl_render_freetype_text(&buffer, library, face, "Hello, World!", 50, 50); + 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; + } - // 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); + // 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; + fbgl_destroy(&buffer); + return 0; } diff --git a/example/line.c b/example/line.c index 9d937cd..f20ec7e 100644 --- a/example/line.c +++ b/example/line.c @@ -11,11 +11,12 @@ int main(int argc, char *argv[]) fbgl_set_bg(&buffer, 0xFF0000); fbgl_point_t start = { 0, 0 }; - fbgl_point_t end = { 1020, 1020}; - for(int i = 0; i < 1890; i++) { + 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++){} + for (int j = 0; j < 10000000; j++) { + } } fbgl_draw_line(start, end, 0x000000, &buffer); diff --git a/example/raw_mode.c b/example/raw_mode.c index 12127af..449a824 100644 --- a/example/raw_mode.c +++ b/example/raw_mode.c @@ -4,18 +4,17 @@ int main(int argc, char *argv[]) { - fbgl_t fb; - fbgl_init("/dev/fb0", &fb); + fbgl_t fb; + fbgl_init("/dev/fb0", &fb); - fbgl_set_bg(&fb, 0xFFFFFF); + fbgl_set_bg(&fb, 0xFFFFFF); - while(1) { - if(fbgl_check_esc_key()) { - printf("pressed"); - fbgl_set_bg(&fb, 0x000000); + while (1) { + if (fbgl_check_esc_key()) { + printf("pressed"); + fbgl_set_bg(&fb, 0x000000); + } } - } - - return 0; -} + return 0; +} diff --git a/example/rectangle.c b/example/rectangle.c index 73f9c4b..ecc1afd 100644 --- a/example/rectangle.c +++ b/example/rectangle.c @@ -3,57 +3,59 @@ 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; + fbgl_t buffer; + if (fbgl_init("/dev/fb0", &buffer) == -1) { + fprintf(stdout, "Error: could not open framebuffer device\n"); + return -1; } - usleep(50000); // Delay to make the animation visible (adjust as needed) - } + 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; + fbgl_destroy(&buffer); + return 0; } diff --git a/example/red.c b/example/red.c index 274bc31..7f64dbd 100644 --- a/example/red.c +++ b/example/red.c @@ -4,10 +4,11 @@ int main(int argc, char *argv[]) { - fbgl_t fb; - fbgl_init("/dev/fb0", &fb); - fbgl_set_bg(&fb, 0xFF0000); - while(1){} - - return 0; + fbgl_t fb; + fbgl_init("/dev/fb0", &fb); + fbgl_set_bg(&fb, 0xFF0000); + while (1) { + } + + return 0; } |
