add ttf font
This commit is contained in:
parent
cc1d7ab2d4
commit
28ab4be2d6
Binary file not shown.
|
@ -26,7 +26,7 @@ $(NVBOARD_ARCHIVE): $(NVBOARD_OBJS)
|
|||
-include $(NVBOARD_OBJS:.o=.d)
|
||||
|
||||
# Link flags for examples
|
||||
LDFLAGS += $(shell sdl2-config --libs) -lSDL2_image
|
||||
LDFLAGS += $(shell sdl2-config --libs) -lSDL2_image -lSDL2_ttf
|
||||
|
||||
.PHONY: nvboard-archive nvboard-clean
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
#include <nvboard.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
static TTF_Font *font = NULL;
|
||||
|
||||
void init_font() {
|
||||
int ret = TTF_Init();
|
||||
assert(ret != -1);
|
||||
std::string nvboard_home = getenv("NVBOARD_HOME");
|
||||
font = TTF_OpenFont((nvboard_home + "/resources/font/" + "FreeMono.ttf").c_str(), 28);
|
||||
assert(font != NULL);
|
||||
}
|
||||
|
||||
void test_font(SDL_Renderer *renderer) {
|
||||
SDL_Color c = {.r = 0xff, .g = 0xff, .b = 0xff };
|
||||
SDL_Surface *s = TTF_RenderText_Solid_Wrapped(font, "abc", c, 0);
|
||||
SDL_Texture *t = SDL_CreateTextureFromSurface(renderer, s);
|
||||
SDL_Rect r = { 0, 0, s->w, s->h };
|
||||
SDL_RenderCopy(renderer, t, NULL, &r);
|
||||
SDL_FreeSurface(s);
|
||||
SDL_DestroyTexture(t);
|
||||
}
|
||||
|
||||
void close_font() {
|
||||
TTF_CloseFont(font);
|
||||
font = NULL;
|
||||
TTF_Quit();
|
||||
}
|
|
@ -82,6 +82,11 @@ void nvboard_init(int vga_clk_cycle) {
|
|||
init_components(main_renderer);
|
||||
init_gui(main_renderer);
|
||||
|
||||
void init_font();
|
||||
void test_font(SDL_Renderer *renderer);
|
||||
init_font();
|
||||
test_font(main_renderer);
|
||||
|
||||
for (int i = 0; i < NR_PINS; i ++) {
|
||||
if (pin_array[i].ptr == NULL) pin_array[i].ptr = &pin_array[i].data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue