summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorlvntky <klevent1903@gmail.com>2024-11-26 01:46:12 +0300
committerlvntky <klevent1903@gmail.com>2024-11-26 01:46:12 +0300
commit31afd2a2540430139200e50fd9cf546dc93fbfa9 (patch)
treeb7bc83cae8b780a6b62bcfb4311a7beb8dc42cf7 /examples
parentd4611757ca2f710b3295847834a47217d19746ef (diff)
[feature] font rendering updated, but not works
Diffstat (limited to 'examples')
-rw-r--r--examples/empty_example.c53
-rw-r--r--examples/text.c28
2 files changed, 28 insertions, 53 deletions
diff --git a/examples/empty_example.c b/examples/empty_example.c
deleted file mode 100644
index 352824a..0000000
--- a/examples/empty_example.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#define FBGL_IMPLEMENTATION
-//#define FBGL_HIDE_CURSOR
-#define FBGL_USE_FREETYPE
-#include "fbgl.h"
-
-#include <stdio.h>
-#include <stddef.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/examples/text.c b/examples/text.c
new file mode 100644
index 0000000..0982a37
--- /dev/null
+++ b/examples/text.c
@@ -0,0 +1,28 @@
+#define FBGL_IMPLEMENTATION
+#include "fbgl.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h> // for usleep
+#include <stdint.h>
+
+int main(int argc, char *argv[])
+{
+ fbgl_t buf;
+ fbgl_init("/dev/fb0", &buf);
+
+ fbgl_set_bg(&buf, 0x000000);
+
+ fbgl_psf2_font_t *font = fbgl_load_psf2_font(argv[1]);
+
+ size_t framerate = 30 * 30;
+ fbgl_render_psf2_text(&buf, font, "hello fbgl", 100, 100, 0xFFFFFF);
+
+ for(size_t i = 0; i < framerate; i++) {
+ usleep(50000);
+ }
+
+ fbgl_destroy_psf2_font(font);
+ fbgl_destroy(&buf);
+
+ return 0;
+}