diff --git a/src/api/l_graphics.c b/src/api/l_graphics.c index 80f7b298..7355f1dc 100644 --- a/src/api/l_graphics.c +++ b/src/api/l_graphics.c @@ -687,6 +687,12 @@ static int l_lovrGraphicsSetBackground(lua_State* L) { return 0; } +static int l_lovrGraphicsGetDefaultFont(lua_State* L) { + Font* font = lovrGraphicsGetDefaultFont(); + luax_pushtype(L, Font, font); + return 1; +} + static int l_lovrGraphicsGetBuffer(lua_State* L) { BufferInfo info = { 0 }; @@ -1266,6 +1272,7 @@ static const luaL_Reg lovrGraphics[] = { { "isFormatSupported", l_lovrGraphicsIsFormatSupported }, { "getBackground", l_lovrGraphicsGetBackground }, { "setBackground", l_lovrGraphicsSetBackground }, + { "getDefaultFont", l_lovrGraphicsGetDefaultFont }, { "getBuffer", l_lovrGraphicsGetBuffer }, { "newBuffer", l_lovrGraphicsNewBuffer }, { "newTexture", l_lovrGraphicsNewTexture }, diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index 2267dc23..4d6ea780 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -625,6 +625,18 @@ void lovrGraphicsSetBackground(float background[4]) { state.background[3] = background[3]; } +Font* lovrGraphicsGetDefaultFont() { + if (!state.defaultFont) { + state.defaultFont = lovrFontCreate(&(FontInfo) { + .rasterizer = lovrRasterizerCreate(NULL, 48), + .padding = 1, + .spread = 4. + }); + } + + return state.defaultFont; +} + void lovrGraphicsSubmit(Pass** passes, uint32_t count) { if (!state.active) { return; @@ -2818,15 +2830,7 @@ void lovrPassCircle(Pass* pass, float* transform, float angle1, float angle2, ui void lovrPassText(Pass* pass, Font* font, const char* text, uint32_t length, float* transform, float wrap, HorizontalAlign halign, VerticalAlign valign) { if (!font) { - if (!state.defaultFont) { - state.defaultFont = lovrFontCreate(&(FontInfo) { - .rasterizer = lovrRasterizerCreate(NULL, 48), - .padding = 1, - .spread = 4. - }); - } - - font = state.defaultFont; + font = lovrGraphicsGetDefaultFont(); } uint32_t originalGlyphsLength = font->glyphs.length; diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 5d79b8c9..5e9730c8 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -90,6 +90,7 @@ bool lovrGraphicsIsFormatSupported(uint32_t format, uint32_t features); void lovrGraphicsGetBackground(float background[4]); void lovrGraphicsSetBackground(float background[4]); +Font* lovrGraphicsGetDefaultFont(void); void lovrGraphicsSubmit(Pass** passes, uint32_t count); void lovrGraphicsWait(void);