Jump to content

SetFont Speed


Alistair
 Share

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

Intel Core 2 Duo E7500 @ 2.93GHz 2.13GHz, 4GB RAM, GeForce GTX 260 1GB PCI-E, Windows 7 Professional 32bit

Link to comment
Share on other sites

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).

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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.

Intel Core 2 Duo E7500 @ 2.93GHz 2.13GHz, 4GB RAM, GeForce GTX 260 1GB PCI-E, Windows 7 Professional 32bit

Link to comment
Share on other sites

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?

Intel Core 2 Duo E7500 @ 2.93GHz 2.13GHz, 4GB RAM, GeForce GTX 260 1GB PCI-E, Windows 7 Professional 32bit

Link to comment
Share on other sites

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

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

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.

Intel Core 2 Duo E7500 @ 2.93GHz 2.13GHz, 4GB RAM, GeForce GTX 260 1GB PCI-E, Windows 7 Professional 32bit

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

 Share

×
×
  • Create New...