Jump to content
Alistair

SetFont Speed

Recommended Posts

I am having issues setting the fonts with regards to framerate.

It seems that using SetFont even when the fonts are preloaded slows the system down to 1 or 2 framerates.

How else would I get around changing fonts when I need to draw text using different fonts in 1 pass through of the code?

 

Here is an example setting the font to the default each loop.

In my code I need to change font in various locations, but this simple sample shows the issue.

I get about 2 frames per second with this sample.

 

Not sure if just a lua issue or not.

 

require("Scripts/constants/keycodes")

RegisterAbstractPath("")

if Graphics(1360,768,0,60,0)==0 then
Notify("Failed to set graphics mode.", 1)
return
end

fw=CreateFramework() 
if fw==nil then 
       Notify("Failed to initialize engine.",1) 
       return 
end 

SetGlobalObject("framewerk",fw) 

font_arial9 = LoadFont("abstract::Arial9")

---------------------------------------------------------------------------------------------------------------------
while KeyHit(KEY_ESCAPE) == 0 do

fw:Update()
fw:Render()

SetBlend(1)
SetFont(font_arial9)
DrawText("test 1", 0, 40)
SetBlend(0)

Flip(0)

end

Share this post


Link to post

You don't need to use SetFont() in each frame, do it only once before the main loop (or once when switching the font inside the main loop).

Share this post


Link to post

You don't need to use SetFont() in each frame, do it only once before the main loop (or once when switching the font inside the main loop).

 

What if I draw text for the hud or text above an enemy in various fonts?

In this example it seems useless to set font each loop, but in my app I draw different text in different fonts in the same loop.

Share this post


Link to post

I think it's a bug in the Lua interface, since it works fast in C++.

 

Is this something Josh will look into or can I forget about using different fonts in lua?

Share this post


Link to post

I think it's a bug in the Lua interface, since it works fast in C++.

 

Is this something Josh will look into or can I forget about using different fonts in lua?

 

There is no bug. You are trying to load the standard LE font, Arial9, using the abstract path. If you looked at your console log, you will see its not being loaded. And since your code is constantly trying to set a font that is not there, its bogging down the whole process. You need to use the 'incbin::' call to grab LE's embedded font.

 

RegisterAbstractPath("")
Graphics(400,300)
fw=CreateFramework()
font1 = LoadFont("incbin::Arial9")
font2 = LoadFont("abstract::ComicSans_24_Bold_Italic_Shadow")
while AppTerminate()==0 do

fw:Update()
fw:Render()

SetBlend(1)
DrawText("Standard LE font",0,60)
SetFont(font2)
DrawText("Custom Font",0,100)
SetFont(font1)
SetBlend(0)
Flip(0)
end

 

ComicSans_24_Bold_Italic_Shadow.zip

 

post-14-067046800 1289280381_thumb.jpg

Share this post


Link to post

There is no bug. You are trying to load the standard LE font, Arial9, using the abstract path. If you looked at your console log, you will see its not being loaded. And since your code is constantly trying to set a font that is not there, its bogging down the whole process. You need to use the 'incbin::' call to grab LE's embedded font.

 

RegisterAbstractPath("")
Graphics(400,300)
fw=CreateFramework()
font1 = LoadFont("incbin::Arial9")
font2 = LoadFont("abstract::ComicSans_24_Bold_Italic_Shadow")
while AppTerminate()==0 do

fw:Update()
fw:Render()

SetBlend(1)
DrawText("Standard LE font",0,60)
SetFont(font2)
DrawText("Custom Font",0,100)
SetFont(font1)
SetBlend(0)
Flip(0)
end

 

ComicSans_24_Bold_Italic_Shadow.zip

 

post-14-067046800 1289280381_thumb.jpg

 

Ahh. lol. Stupid me.

 

Thanks.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...