wip: work on font rendering in window rendered by shared object
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <gui/truetype.hpp>
|
||||
|
||||
// Exported demo function - creates a window and renders until closed
|
||||
extern "C" int hello_run() {
|
||||
@@ -20,6 +21,18 @@ extern "C" int hello_run() {
|
||||
int width = 200;
|
||||
int height = 320;
|
||||
|
||||
gui::TrueTypeFont* font = (gui::TrueTypeFont*)montauk::malloc(sizeof(gui::TrueTypeFont));
|
||||
if (!font) {
|
||||
montauk::win_destroy(winId);
|
||||
return -1;
|
||||
}
|
||||
montauk::memset(font, 0, sizeof(gui::TrueTypeFont));
|
||||
if (!font->init("0:/fonts/Roboto-Medium.ttf")) {
|
||||
montauk::mfree(font);
|
||||
montauk::win_destroy(winId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Simple render - fill with a color pattern
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -28,6 +41,14 @@ extern "C" int hello_run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Render text using TrueType
|
||||
gui::Color text_color;
|
||||
text_color.r = 0xF5;
|
||||
text_color.g = 0xF5;
|
||||
text_color.b = 0xF5;
|
||||
text_color.a = 255;
|
||||
font->draw_to_buffer(pixels, width, height, 20, 20, "Hello from libhello!", text_color, 16);
|
||||
|
||||
// Present the initial frame
|
||||
montauk::win_present(winId);
|
||||
|
||||
@@ -58,10 +79,12 @@ extern "C" int hello_run() {
|
||||
pixels[y * width + x] = 0xFF1a1a2e;
|
||||
}
|
||||
}
|
||||
font->draw_to_buffer(pixels, width, height, 20, 20, "Hello from libhello!", text_color, 16);
|
||||
montauk::win_present(winId);
|
||||
}
|
||||
}
|
||||
|
||||
montauk::win_destroy(winId);
|
||||
montauk::mfree(font);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user