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 / Need your opinion on today's fastest way to render bitmap font!

Author
Message
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 11th Jan 2014 19:31
Hi guys. In short, I need your opinion on today's fastest way to render bitmap font in DBP. Font size ~14, resolution is full HD.

Ways: sprites, pasted images, 3d planes...or more?

Speed is everything, but font must be bitmap.

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Jan 2014 22:10
Use your source images (for the characters / symbols) and write them directly to memory to a larger image that acts as a label. You'll then recreate this image only if the text for the label changes, otherwise you keep the same image. The result is a slightly larger operation whenever the text changes, then you'll have very fast execution when you're just displaying your single (or if you have a few) label(s).
Much more efficient on the whole than pasting or creating sprites for each character in each frame.
You can hook up to the ?SetImageData@@YAXHKKKPADK@Z function from DBProImageDebug.dll to bypass the additional step of having to recreate the image from a memblock.


"Why do programmers get Halloween and Christmas mixed up?"
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 11th Jan 2014 22:55
Depend on what your doing with the font, hlsl point sprites is another way to render characters (of a atlas) or even whole pre-rendered text.

"Get in the Van!" - Van B
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Jan 2014 01:04
@Rudolpho
Quote: "write them directly to memory to a larger image that acts as a label"

Paste image? Not sure that I understand you...

@Sasuke
3D credits (lots of text over 3D scene) and cursor tooltips (from small to large).
Point sprites you say? How fast are they for atlas?

Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 12th Jan 2014 07:52
I have not tried a lot of ways to render bitmap font, nor have I tested them side by side to find the fastest. I use Svens bitmap font kit plugin for utilizing bitmap font.

http://forum.thegamecreators.com/?m=forum_view&t=179885&b=8

It does the trick nicely.

Ok, Jokes over, No more eye burn.
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jan 2014 10:55
Quote: "Paste image? Not sure that I understand you..."

No, either you can use a memblock and then get memblock ptr or make memory or alloc, if you're using M1U.


"Why do programmers get Halloween and Christmas mixed up?"
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Jan 2014 19:29
Quote: "bitmap font kit"

For credits it is slow as paste image (per letter). Plus, 127 characters support only. Double

Rudolpho, so copying one memblock (font atlas) to other memblock is fast enough to write a lot of text (i.e. pixels)? I'll try that, though I need to learn memblocks.

And about point sprites - are they fast? Are they safe to use for text?

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Jan 2014 22:18 Edited at: 12th Jan 2014 22:21
Point sprites tend to use just 1 single image, so the pipeline data is cut down to just X and Y coordinates.

I think that just using sprite letters is the safest bet. You'll be changing them a lot, so using a memblock is not ideal, it can be slow to update the image. There is ImageKit, and the Matrix plugins, they make it easier to paste images directly onto other images - that might be an option - have the bitmap font as images that you paste onto a foreground sprite and image. I use ImageKit quite a lot, nice and fast. But, if you are updating text every frame, sprites are the safest bet, I'm sure they have the least overhead in the long run... Plus, sprites are the only easy way to have coloured text. With sprites, you can just use white text and change the sprite colour to whatever you need. Doing that with a memblock is slow, ImageKit likewise.

I would make a bitmap font on a 16x16 basis, on a 16x16 grid - 256 frames that translate directly to ascii - so setting the sprite frame to the ascii value of the letter is all that is required. The less code you use in this part, the better... it's easier to just have a full 256 character set. If you like, you can use up the extra letters as GUI components, mouse cursors, icons, anything you can fit into the 16x16 frame.

I am the one who knocks...
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 12th Jan 2014 23:37 Edited at: 12th Jan 2014 23:39
Thanks Kezzla and Rudolpho for your ideas. I have run some tests but the sprite atlas seems to be the winner (versus memblocks and BFK). Memblocks are good to work with small images, like minimap. BFK is not very fast and have limitations, but for some cases it could be convenient.

Van B, speaking as we doing 16x16 atlas as you said...

Quote: "Point sprites tend to use just 1 single image, so the pipeline data is cut down to just X and Y coordinates."

How about setting the X and Y of atlas letter as vertex UV coords?

Sprites vs Paste sprites.
Sprite itself is no doubt faster than paste sprite. But there is a problem - how to organise sprites on screen?.. They are just bunch of images from 1 to eternity, and every time some text changes we need to clone additional sprites or delete unused, some sprites remaining unchanged... Can you give an idea how to manage them every loop?

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 13th Jan 2014 00:45
The Absolute fastest is pasting them to a render target and manipulating the render target when you need to. You could have tons of scrolling bitmap font on screen with hardly any performance hit.

"Get in the Van!" - Van B
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 13th Jan 2014 01:50 Edited at: 13th Jan 2014 01:51
Quote: "With sprites, you can just use white text and change the sprite colour to whatever you need. Doing that with a memblock is slow, ImageKit likewise."

Not much slower than just copying the pixels from the font sheet anyway; you can simply bitwise AND the source and overlay colours together (assuming your base image is white / grayscale on the parts you want coloured).


"Why do programmers get Halloween and Christmas mixed up?"
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 13th Jan 2014 01:54
Quote: "The Absolute fastest is pasting them to a render target and manipulating the render target when you need to. You could have tons of scrolling bitmap font on screen with hardly any performance hit."

Hmm, filling screen by pasting sprites over 3D test scene gave me 25 FPS when "live" sprites of same amount gave me 35 FPS.

Also I'd like to hear more of
Quote: "pasting them to a render target and manipulating the render target"

Render targer is "camera to image"?

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 13th Jan 2014 03:10 Edited at: 13th Jan 2014 03:27
Quote: "Render target is "camera to image"?"


Not exactly:
Quote: "MSDN ¬
A render target is a buffer where the video card draws pixels for a scene that is being rendered by an Effect Class.
The default render target is called the back buffer - this is the part of video memory that contains the next frame to be drawn. You can create other render targets with the RenderTarget2D class - in effect, reserving new regions of video memory for drawing. Most games render a lot of content to other render targets besides the back buffer ("offscreen"), then assemble the different graphical elements in stages, combining them to create the final product in the back buffer."


The idea is to render all the text or 2d to a render target texture as if it was like a text sheet/ 2d layer that would sit on top the of the 3d scene. I believe the camera render target is the default back buffer or frame buffer and this is what 'set camera to image' captures.

You'll need Ian M's matirx plugin (only this for my snippet below) and or Imagekit for further manipulation to make and edit render targets. Here's an example of a ton of text i've pre-rendered to a render target and at runtime I only update a bit of text when I need to, in this case it's the fps value on the image. This is done by clearing the text value in it's position then re-writing the new value.



"Get in the Van!" - Van B
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 14th Jan 2014 09:34 Edited at: 14th Jan 2014 09:36
Hmm. Interesting. Looks like it is not bitmap font, and if use bitmap font will it be slower? Also that code will fail if under erased text was part of another text, so all text somehow should be updated.

---
Van B, still asking could you give an idea of sprite based text handling?

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jan 2014 10:54
Quote: "Looks like it is not bitmap font"


I think you misunderstand. Bitmap font is just the name given to a 2d image which just happens to have reader-able characters on it. But it's no different than how you'd treat any other arrangement of pixels if your just taking the parts you want to rendering them to screen. Using text is no different than if I saved it in an image, cut it up into parts and rendered it = bitmap font.

Depending on the size of the image your pasting to the screen will affect how slow the method it.

Quote: "Also that code will fail if under erased text was part of another text, so all text somehow should be updated."


No method will be able to handle every situation, but nothing else is faster at displaying any amount of characters or pixels on screen. One idea is to combine or use both methods when you need to. Non-over lapping text to a render target and sprite based text for more complex set ups.

Though there is a way to handle overlapping on a render target. You work out want needs to be redrawn in that area you've erased and redraw it + the new data.

"Get in the Van!" - Van B
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 14th Jan 2014 12:13
Quote: "Using text is no different"

Almost. If you have problems with desired font in your system, text will render wrong symbols or as other (default) font. "Bitmap font" is just fail-safe technique (with effects as additional bonus).

Quote: "Non-over lapping text to a render target and sprite based text for more complex set ups."

So you the second after Van B who said about sprites as text. I like that idea but I can't imagine how to handle those sprites. Can you give an idea how to?

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Jan 2014 13:11
It depends on what the text has to do. I mean, for a score display, I'd use a set range of sprites, say sprite 10 to 16, then just change the frame number on those to suit the score when the score changes.

For screen text, like a help dialogue box for example, I'd use an incrementing global for the sprite number and step through a string, creating a sprite for each letter, then positioning it and setting it's frame to suit the letter.
Along with that, I'd have a function to clear the text, maybe just hiding the sprites, but going through each one and getting it ready for the next text display.

So it's best to split things up, use a set range of sprites when the sprites are displayed during the game, like for score displays - and any in-game text can use the incrementing global and be a bit more dynamic that way. Usually I'd load in a single image for a bitmap font, then with a memblock, work out the character widths and store them in an array... then when positioning the sprites, you can use a virtual printhead/cursor - incrementing on X by the character width.

Working out multi-line text can be tricky, usually I get the text string that I need to display, then adjust the text length in characters until it is below the size limit and not inside a word. Really, it would probably be easier to just split the text lines manually, like layout the sprites in single lines. It's fiddly, but doing it 'live' can be really slow and the code can be a bit tricky - it's probably overkill to work out multi-lines with code, unless you have dozens of lines of text to read in. I like to just make a function like BitText(x,y,t$), and have that do the grunt work... kinda like replacing the internal Text x,y,t$

I will see if I have a decent example to show tonight.

I am the one who knocks...
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 14th Jan 2014 14:00
To create my bitmap text, I use the d3d boxtext function to print text to a bitmap, get the image and paste it as a sprite. I then handle it exactly like agk text. Only redrawing the text when it's changed speeds it up.

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jan 2014 14:38 Edited at: 14th Jan 2014 14:38
Or just look at Mages example (Sprite Based): Pro Tip: Using Bitmap Fonts + Working Demo

"Get in the Van!" - Van B
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 14th Jan 2014 21:08
Yeah, looks pretty comprehensive, that would just bolt right in with minimal work.

I am the one who knocks...
mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Jan 2014 06:35 Edited at: 15th Jan 2014 06:37
Yeah it is a very good starting point! Thanks!

edit: still it is slow for lots of text, but as you say I'll add "layers" for still text and dynamic text.

mr Handy
17
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Jan 2014 09:29 Edited at: 15th Jan 2014 09:32
It seems to be unavailable to make layers for some overlapping cases without additional masks (i.e. performance impact). Okay

Also this is strange: today's test showed same FPS (the high one from previous test) for both SPRITE and PASTE SPRITE. That's odd and very good at the same time. Also, I do not altered my video card settings. But... I have upgraded from Kaspersky 2013 to Kaspersky 2014.

Login to post a reply

Server time is: 2025-05-16 01:40:46
Your offset time is: 2025-05-16 01:40:46