Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Program ends after many usages of D3D_Font

Author
Message
MummyKillerSLO
17
Years of Service
User Offline
Joined: 5th Jul 2009
Location: Object Position Y(ObjChair)
Posted: 21st Jan 2013 22:24
Hello! I've started to make a simple game, where some text needs to be flashing (font needs to go from smaller to bigger size and vice-versa). So far, I've made an example of my idea, but the program ends after some seconds. I think, that command D3D_FONT can't be used in so many loops, so I am wondering, if there is any alternative command excluding native SET TEXT SIZE?

My program looks like this:
[CODE]
set display mode 1680,1050,32
sync on : sync rate 0
d3d_init

do
cls
a# = wrapvalue(a# + 0.5)
size = sin(a#) * 100

d3d_starttext
d3d_font 1,"courier new",size,0,0,0
d3d_text 1,5,100,0,"Screen FPS: " + str$(screen fps())
d3d_endtext
sync
loop
[/CODE]

Happy to having and using DarkBASIC Professional...
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 21st Jan 2013 23:48
I've taken a look at the code for Cloggy's D3D plugin as well as checking task manager whilst that code is running. There seems to be a memory leak where, if you redefine a font, it doesn't clean up the old one first so each time you set up a font under the same id it uses up more and more memory until it fails. It should be quite easy to fix but I'm afraid I don't have time at the moment to get an environment set up to build a new version of the DLL. The only other alternative I can think of is to take a look at the Advanced 2D plugin.


Previously TEH_CODERER.
zeroSlave
17
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 22nd Jan 2013 04:26 Edited at: 22nd Jan 2013 06:36
Woah! That snippet locked up my laptop!

I've not used the Advanced 2d plugin, so I'm not sure of its functions. If you can't find a solution using it, you may want to look into a different approach. Does the text need to be dynamic? If not, you may be able to make an image of the text (at the largest resolution used), then resize it accordingly.

If the text does need to change (like the updating screen fps in your snippet) you may want to look into making your own text system using a texture atlas. I personally use codeheads bitmap font generator to generate a texture atlas.

Here is an example of a font system:

And the text image is attached.

It doesn't show how to resize, but with a bit of math, it would definitely be possible!

Edit: You got the [co[/b]de] right at the top, but I think the forum is case sensitive. Use [co[b]de] & [/co[/b]de] instead of [CO[b]DE] & [/CO[b][/b]DE]

Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 22nd Jan 2013 14:48
Ok, I've had a chance to rebuild the DLL now. If you download the attached zip file and drop it over your DBPro installation directory it will replace the D3D DLL and keywords to add a new command: d3d_clearFont. If you call this before trying to reset the font then it will clean up the existing font first, preventing the memory leak. I've tested it and left it running for quite a while and the program continued to run without issue. Let me know if you have any problems with it.

As an example:



Previously TEH_CODERER.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Jan 2013 14:57
Just a side note: Depend on what your doing with the text stick to DBP cause it's a lot faster than D3D, actually nearly twice as fast. Avoid A2D at all costs for text, incredibly slow!
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 22nd Jan 2013 15:11 Edited at: 22nd Jan 2013 15:13
It probably depends on exactly what you are doing, but D3D definitely gives slightly better results in this quick test. I get about 0.38ms for native and 0.31ms for D3D.




Previously TEH_CODERER.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Jan 2013 15:28
It's the other way round for me plus timer() function isn't to accurate. I wonder what results you'll get with the test I did awhile back:

MummyKillerSLO
17
Years of Service
User Offline
Joined: 5th Jul 2009
Location: Object Position Y(ObjChair)
Posted: 22nd Jan 2013 15:44
It works like a charm now! Thank you guys! (also thanks to Andrew_Neale for rebuilding DLL for me )

Happy to having and using DarkBASIC Professional...
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 22nd Jan 2013 15:49 Edited at: 22nd Jan 2013 15:49
[Edit] Posted this before seeing the above post. No worries, glad to be of assistance! [/Edit]

With that test, after a few very minor changes for fairness, it does indeed favour the native commands quite considerably. Whether this then just shows that certain scenarios are better with one than the other or that my little test was a bit of an odd exception...

However, you lose out on other features, primarily the anti-aliasing which is probably the main cause for the difference in speed but also makes a vast difference to quality. I guess you just have to choose what is best for your situation. Even then, for a lot of text, I would choose to pre-render it where possible.

My very minor changes, in case you're interested:



I basically made sure that both methods explicitly set a colour instead of just the D3D one as in your code in case there was any slowness there. I also made it so that all the text is D3D or all the text is native rather than having a mix with the info text in native in case there was a slow down caused by the mixture. Probably mostly irrelevant but, hey, I was curious!


Previously TEH_CODERER.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 23rd Jan 2013 10:52 Edited at: 23rd Jan 2013 10:53
As the fixes/changes to this DLL will be useful to me as well, I've made a couple of other small changes and thought I'd add them here in case they're useful to anyone else. Using 'D3D_Font' will now not create a font if the font already exists so that you can't accidentally cause a memory leak. 'D3D_ClearFont' will still allow you delete an existing font. 'D3D_FontExist' will now allow you to check if a font has been setup yet or not.

As an example:


[Edit] Forgot to attach the file, doh! [/Edit]


Previously TEH_CODERER.
Zero G Scott
18
Years of Service
User Offline
Joined: 14th Dec 2007
Location: California, USA, Earth, Sol Sys
Posted: 24th Jan 2013 01:26 Edited at: 24th Jan 2013 01:27
How would you go about pre-rendering text? Since you're on the subject of text.
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 24th Jan 2013 04:00
@Andrew_Neale:

Any chance you could post the modified DLL source code as well? I'd like to utilize your changes above, but also keep some modifications I made earlier with viewports.
Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 24th Jan 2013 18:48
Sure, they're fairly minimal. I'm afraid I don't have the code with me at the moment but I'll try to upload it tomorrow.


Previously TEH_CODERER.

Login to post a reply

Server time is: 2026-07-08 21:14:16
Your offset time is: 2026-07-08 21:14:16