gl.LoadFont() tempry freezes game when loading widget ingame

gl.LoadFont() tempry freezes game when loading widget ingame

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

gl.LoadFont() tempry freezes game when loading widget ingame

Post by Pithikos »

I am done with a widget but I just noticed that if I disable it ingame and then enable it, the screem will freeze for 3-5 secs. After a lot if trial and error I came to the conclusion that this is due to loading four different fonts:

Code: Select all

local gl, GL            = gl, GL
local header1FontSize      = 20
local header1Font        = gl.LoadFont("fonts/texgyreheros-bold.otf", header1FontSize, 45, 25)
local header2FontSize      = 20
local header2Font      = gl.LoadFont("fonts/texgyreheros-bold.otf", header2FontSize)
local header3FontSize      = 20
local header3Font        = gl.LoadFont("fonts/UnDotum.ttf", header3FontSize)
local toolTipFontSize      = 12
local toolTipFont          = gl.LoadFont("fonts/UnDotum.ttf", toolTipFontSize, 12)
Is this to be expected? Some way to fix this?
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: gl.LoadFont() tempry freezes game when loading widget ingame

Post by Pithikos »

Ok so the problem seems to depend on the extra parameters given to LoadFont(). Taking off the outline parameters fixes this. For small outline numbers it lags less. The higher the number, the longer the game stays frozen.

Thus this will load instantly without any lag:

Code: Select all

local gl, GL            = gl, GL
local header1FontSize      = 20
local header1Font        = gl.LoadFont("fonts/texgyreheros-bold.otf", header1FontSize)
local header2FontSize      = 20
local header2Font      = gl.LoadFont("fonts/texgyreheros-bold.otf", header2FontSize)
local header3FontSize      = 20
local header3Font        = gl.LoadFont("fonts/UnDotum.ttf", header3FontSize)
local toolTipFontSize      = 12
local toolTipFont          = gl.LoadFont("fonts/UnDotum.ttf", toolTipFontSize)
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: gl.LoadFont() tempry freezes game when loading widget ingame

Post by Beherith »

I believe loadfont renders the whole font to a static buffer, so it doesnt have to render fonts later. Rendering with large outlines can take a while.
User avatar
Pithikos
Posts: 146
Joined: 26 Dec 2008, 14:26

Re: gl.LoadFont() tempry freezes game when loading widget ingame

Post by Pithikos »

Well one weird thing is that I don't see any optical difference with the parameters applied or not. The text always looks the same no matter if I give an outline of 50 or 2.
Post Reply

Return to “Lua Scripts”