Jump to content
  • Advertisement
Sign in to follow this  
Programmer16

Font engine and FPS relation ?s

This topic is 5464 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on my font engine and I just added the ability for coloring words (like highlighting single words). Example: Color array = { white, // base red, // 1 green, // 2 blue, // 3 // 1 through 9 can be filled. 0 is the default color to use } The string is "Hi there \\2adventurer\\0, my name is \\1Programmer16\\0. This will highlight adventurer in green and Programmer16 in red. I tested it before this and I was getting between 52-54 FPS and after I was getting 48 (pretty much constantly). This is only a 4-6 drop in frame rate for a really useful feature. Currently in my loop I loop through each character of the string. If the current character is the backslash character and is followed by a number between 0 and 9, it opens/closes highlighting and increases the current character to indices. Then it renders it. The only addition between the two tests is a couple of if statements, and a couple of variables (one to tell if I'm coloring or not, and one to hold the current color). After thinking about it, I just went back to my code and I was using std::string overloaded operator [] three times in code, so I added another char variable for storing the next character, and it went back up to between 50-52. I guess my question is pretty much a dumb one now, but I'll ask it anyway. Does anybody think that this is a unreasonable drop in FPS? Ok, to make this post worth it, are there any features that anybody thinks I should implement? I'm thinking of changing the colors to <#> instead of \\#, but there isn't really any point since this works and there is the same amount of characters :D Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I would have personally used a HTML parser and some tags :D. You'd be able to do more with it in less work, but that's just my opinion :X

Share this post


Link to post
Share on other sites
I never really thought of that. I'll look into it, but the only thing I was really planning on supporting was the highlighted text. Do you know of any that are worth looking at?

As a side note, I'm going to have to change it to <#>. I was trying to color my FPS last night:
\\1%.0f\\0, which was formated to something like
\\164\\0, and 164 isn't one of the colors. But, with the <#> format, I can allow for more than 0-9 color values.

Thanks!

Share this post


Link to post
Share on other sites
Personally, I think HTML parsing is a little more than you actually need for an FPS. I'm assuming it's just for on-screen text and the like, and not some mini-browser.

Losing 4-6 frames for colors seems like a bit much. But it depends what type of game it's for. RPGs and games that aren't as fast paced are probably fine with a small drop in frame. FPS games (first-person shooter, not frames-per-second) I wouldn't like any type of drop I could prevent.

Share this post


Link to post
Share on other sites
It would be nice if you could calculate the colors of the characters only once, save it, and only parse the input again if it got updated.

Share this post


Link to post
Share on other sites
You might want to try rendering your text to a surface or texture, then reuse that each frame until it is no longer needed.

Probably not of use though unless your screen is very text heavy :)

Share this post


Link to post
Share on other sites
Quote:
Original post by overflowed_
Personally, I think HTML parsing is a little more than you actually need for an FPS. I'm assuming it's just for on-screen text and the like, and not some mini-browser.

Losing 4-6 frames for colors seems like a bit much. But it depends what type of game it's for. RPGs and games that aren't as fast paced are probably fine with a small drop in frame. FPS games (first-person shooter, not frames-per-second) I wouldn't like any type of drop I could prevent.


He never said it was a first person shooter :D. From the text example he gave, it looks like an RPG of sorts. Since RPGs are heavily text based as it is, the HTML parsing thing was just a suggestion since you'll be manipulating text regularly (to emphasize a character's personality, such as the big ugly ogre having large size text).

Might want to look at libwww, especially the parsing examples on the Sample Application page.

Actually, this sounds like a pretty neat article I could write. :D

Share this post


Link to post
Share on other sites
Ok, I changed it so that not only can you use the <#> format to color it, but it allows for any amount of colors and it doesn't drop my frame rate any more than 2 (When I tested my regular DrawText() that just takes a single color against this DrawText() function that takes an array of colors).

Here's an example:

DWORD g_dwFontColors[] =
{
0xffffffff, // default color, white
0xffff0000, // red
0xff00ff00, // green
0xff0000ff, // blue
0xff000000, // black
0xffff0000, // red
0xffff0000, // red
0xffff0000, // red
0xffff0000, // red
0xffff0000, // red
0xffff0000, // red
0xffff00ff, // pink
};

//Font(Filename, LetterWidth, LetterHeight, BitmapSize)
Eg3D::FontEngine::Font g_Font("Assets\\gui_font.png", 10.0f, 17.0f, 256.0f);

g_Font.DrawText(0, 0, g_dwFontColors, "The sky maybe <3>blue<0> and the grass maybe <2>green<0>, but fire is always <1>red<0>.\n<11>This text is %s :P<0>", "pink");



The font engine is actually part of my 3D game engine that I will use mostly for 3D RPGs (but it'll probably get used for other genres too, depends).

Thanks for responding, I'll check out libwww.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!