Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

bitmap font performance issue (SDL and C++ )

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ASnogarD   Members   


Posted 20 June 2012 - 05:13 AM


I am developing a small framework that I can use when starting a new game project, the framework provides the basics I need each project ... like initialising , putting text on the screen, loading images, feedback from the code.
It was all going fine until I added the FPS meter, then I notice the FPS take a dive when the console was displaying messages... a HUGE dive, from max of 500 FPS ( no message from console) to 293 with only 23 messages being displayed.

To display text on the screen I use a basic bitmap font system, taken from Lazy Foo's tutorial and mixed with sdltutorials code.
In brief it :

Loads the bitmap font image onto a SDL_Surface, converting the image using SDL_DisplayFormat .
Stores the clipping data for each character in an static array of SDL_Rect objects
Uses ASCII values of each character to reference the relevant SDL_Rect object to provide clipping data to the draw function
Draw function is the typical blit from source ( the surface holding the font image) to destination ( main display).

video is set using SDL_HWSURFACE | SDL_DOUBLEBUF flags.

I realise it is a lot of looping and work to put up an image for each character in a string of text, but losing 200+ FPS for loosely spaced text on a screen normal ?

Question: Is a huge loss of updates per second to be expected when dsplaying a lot of text on the screen using a bitmap font system ?
Is there anyway to avoid this loss in SDL / C++ ?

Edited by ASnogarD, 20 June 2012 - 05:14 AM.

#2 RulerOfNothing   Members   


Posted 20 June 2012 - 05:19 AM

A drop in FPS from 500 to 293 is only an extra 1.4 milliseconds per frame, but I think that the main problem is that you are redrawing the text every frame. What happens to your FPS if you only draw the message once?

#3 ASnogarD   Members   


Posted 20 June 2012 - 05:33 AM

I do clear the screen each loop using a function which does :

SDL_Rect clearBox = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
SDL_FillRect(SDL_GetVideoSurface(), &clearBox , 0);

... you have given me some partial ideas though ( conditional screen clearing, partial screen clearing , small window for new messages and a large window to view all messages while the game loop gets paused when viewing the large console window )

So the drop is to be expected if I am redrawing the entire screen each update then ?

Thank you for the reply.

#4 sednihp   Members   


Posted 21 June 2012 - 12:00 PM

For all my text in SDL I use SDL_ttf and ttf fonts (fontspace.com is a great website for these). Load the font (TTF_OpenFont), then load the text to a SDL_Surface (I use TTF_RenderText_Blended for quality, there are others that are quicker with lower quality), then blit the surface to screen. All of this is done in my ImageCache class, which is probably similar to what you're trying to achieve.

This doesn't give me any noticeable slowdown at all and I redraw the entire screen every frame (same as you), but then all of my games are capped at 60fps.

Edited by sednihp, 21 June 2012 - 12:01 PM.

#5 antiHUMANDesigns   Members   


Posted 23 June 2012 - 07:09 PM

I also used SDL_ttf. One nice thing with that is that if you write the code well you only need to re-create the texture if the text changes, which most text doesn't do very often, so it's extremely fast. As fast as drawing one textured quad per text line.

Hmmm, yes, I did this together with openGL... I've never used SDL without openGL, though. :/ Maybe what I'm saying is irrelevant.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.