wip: work on font rendering in window rendered by shared object
This commit is contained in:
@@ -56,10 +56,17 @@ LIBSRC := src/libhello.cpp
|
||||
|
||||
all: $(OUTDIR)/$(LIBNAME).lib $(OUTDIR)/$(LIBNAME).lib.sym
|
||||
|
||||
$(OUTDIR)/$(LIBNAME).lib: $(LIBSRC)
|
||||
@mkdir -p $(OUTDIR)
|
||||
$(CXX) $(CXXFLAGS) -c src/libhello.cpp -o src/libhello.o
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) src/libhello.o -o $@
|
||||
$(OUTDIR):
|
||||
mkdir -p $@
|
||||
|
||||
src/libhello.o: src/libhello.cpp Makefile | $(OUTDIR)
|
||||
$(CXX) $(CXXFLAGS) -c src/libhello.cpp -o $@
|
||||
|
||||
src/stb_truetype_impl.o: src/stb_truetype_impl.cpp Makefile | $(OUTDIR)
|
||||
$(CXX) $(CXXFLAGS) -c src/stb_truetype_impl.cpp -o $@
|
||||
|
||||
$(OUTDIR)/$(LIBNAME).lib: src/libhello.o src/stb_truetype_impl.o
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) src/libhello.o src/stb_truetype_impl.o -o $@
|
||||
|
||||
# Generate symbol file from nm output
|
||||
# Format: "symbol_name,offset_in_hex"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user