[Patch] Single texture font

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

[Patch] Single texture font

#1 Post by Mitten.O »

This code changes Font such that instead of an arbitrary number of
256x256 textures, it stores all its glyphs in a single texture that is as large as it needs to be.

I don't think there is much fear of running on a device where
the glyphs won't fit on a MAX_TEXTURE_SIZE x MAX_TEXTURE_SIZE.
(At least as long as we don't have localization in chinese or something.
But I doubt our support for such a thing anyway.)

This change removes the need for switching textures while rendering text with a single font.
This is preparatory work for seeking a way to achieve the performance gains of the reckless adventure
(viewtopic.php?f=9&t=8965)
reliably and without doing anything reckless.

This is also theoretically good for performance,
but the gain is buried deep beneath various inefficiencies
without other changes.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Foocaux
Space Squid
Posts: 78
Joined: Sat Jul 26, 2014 7:14 am

Re: [Patch] Single texture font

#2 Post by Foocaux »

Hmm, at first sight this doesn't seem to work too well for me, at least as some text is concerned:
curses.png
curses.png (37.98 KiB) Viewed 2037 times
I was in windowed mode, and without thinking I moved the main() window around; amazingly, it helped!
Aaah.png
Aaah.png (24.8 KiB) Viewed 2037 times
The small print: Any code contribution I make to FreeOrion is made under GPL v2.0, any graphic contribution is under CC-by-SA 3.0

User avatar
em3
Vacuum Dragon
Posts: 630
Joined: Sun Sep 25, 2011 2:51 pm

Re: [Patch] Single texture font

#3 Post by em3 »

In the latter screenshot the slanted text still looks wonky.
https://github.com/mmoderau
[...] for Man has earned his right to hold this planet against all comers, by virtue of occasionally producing someone totally batshit insane. - Randall Munroe, title text to xkcd #556

User avatar
adrian_broher
Programmer
Posts: 1156
Joined: Fri Mar 01, 2013 9:52 am
Location: Germany

Re: [Patch] Single texture font

#4 Post by adrian_broher »

Foocaux wrote:I was in windowed mode, and without thinking I moved the main() window around; amazingly, it helped!
My guess its that the GL_UNPACK_ALIGNMENT isn't set properly when transferring the glyphs to the texture atlas.

http://www.opengl.org/wiki/Pixel_Transfer#Pixel_layout
em3 wrote:In the latter screenshot the slanted text still looks wonky.
This seems to be a general problem with our(?) font/rendering code. Almost every glyph I see has some artifacts on the edges.
Resident code gremlin
Attached patches are released under GPL 2.0 or later.
Git author: Marcel Metz

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Single texture font

#5 Post by Mitten.O »

My guess its that the GL_UNPACK_ALIGNMENT isn't set properly when transferring the glyphs to the texture atlas.
This seems unlikely. I didn't change the part of the code that sets these parameters and that code sets the alignment as 1, which should work, I think.
And if it didn't work, how could it work anywhere? And how could moving the window fix it?
I am not a master of alignment, so there could be answers to all these questions, but seems a bit unlikely.
This seems to be a general problem with our(?) font/rendering code. Almost every glyph I see has some artefacts on the edges.
I added one pixel margin between the glyphs in the atlas. Seems to remove the artefacts. This fix could of course be done also in the original scheme,
if we choose to stay with it.

Foocaux, does the issue arise consistently?
Does this change affect it?
Does it appear with larger font sizes (seeing the strange artefacts in more detail may help in guessing what is going on)?
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Foocaux
Space Squid
Posts: 78
Joined: Sat Jul 26, 2014 7:14 am

Re: [Patch] Single texture font

#6 Post by Foocaux »

The good news: no more font artifacts (used to be very visible in the research screen when at max magnification).

The bad news: my hyeroglyphs are still there.
At first I thought it was a random thing, but I've just found a way to reliably get squiggles as a window title: I close all but the fleet window, click twice on the research icon to go to research & back, tah-dah: the title is messed up. I move the fleet window about, tah-dah, english again!


I found the options for font sizes & resized the font successfully, but trying to change the value inside the 'window titles' box with the up arrow caused a crash to desktop for me.
To allow my below par laptop to compile FO, I had to disable all debug features, so I'm slightly stumped here... wish I could help more :(

Edit: weird, without using the up/down arrows I managed to change the window title font size: changing the title size doesn't seem to trigger a recalculation of the bitmap, so I get hyeroglyphs at 11, 10, 18; changing it to 12 'Options' - the title of the options menu itself - is readable again.
It looks like my computer doesn't like 13 as 'window titles'. Doing just that caused a CTD.
It also looks like it saved the setting as 13 just before crashing, since I now CTD every time I try to restart my compiled FO. Where are those settings kept? I've already tried Roaming\FreeOrion\config.xml, but that seems to affect only the downloaded test release...
The small print: Any code contribution I make to FreeOrion is made under GPL v2.0, any graphic contribution is under CC-by-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: [Patch] Single texture font

#7 Post by Dilvish »

Foocaux wrote:Where are those settings kept? I've already tried Roaming\FreeOrion\config.xml, but that seems to affect only the downloaded test release...
http://freeorion.org/index.php/Config.xml I think it should be the same location for all builds (certainly is for Linux)
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Single texture font

#8 Post by Mitten.O »

I had simply missed the fact that one of the three RenderText overrides is not just
a convenience for the largest one, but wholly independent,
thereby neglecting to make it bind its font texture.
It was using its own coordinates with the texture of a different font.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Foocaux
Space Squid
Posts: 78
Joined: Sat Jul 26, 2014 7:14 am

Re: [Patch] Single texture font

#9 Post by Foocaux »

Dilvish wrote: it should be the same location for all builds
Yep, so it is.
I had 2 instances of FreeOrion running at once, in order to compare the user interface behaviour. I guess that's not a particularly good idea! :)


Thanks Mitten.O, compiling this new patch right now, will let you know how it goes! :)
The small print: Any code contribution I make to FreeOrion is made under GPL v2.0, any graphic contribution is under CC-by-SA 3.0

User avatar
Foocaux
Space Squid
Posts: 78
Joined: Sat Jul 26, 2014 7:14 am

Re: [Patch] Single texture font

#10 Post by Foocaux »

That's more like it! :)
The hyeroglyphs are gone, and I couldn't figure out a way to get them back. Changing window title size works properly too. (well, with one teensy weensy exception)
My build, and that's really puzzling, still doesn't like window title 13. It crashes the second I enter that number in.

Setting <title-font-size>13</title-font-size> inside config.xml, then starting FreeOrion.exe results into a crash to desktop every time.
The last line inside freeorion.log always reads:

Code: Select all

DEBUG Client : HumanClientApp::Enter2DMode()
Mitten.O, does this happen to you, or is it just me?
The small print: Any code contribution I make to FreeOrion is made under GPL v2.0, any graphic contribution is under CC-by-SA 3.0

User avatar
Dilvish
AI Lead and Programmer Emeritus
Posts: 4768
Joined: Sat Sep 22, 2012 6:25 pm

Re: [Patch] Single texture font

#11 Post by Dilvish »

Foocaux wrote:Setting <title-font-size>13</title-font-size> inside config.xml, then starting FreeOrion.exe results into a crash to desktop every time.
just one more datapoint -- doesn't cause any trouble for me
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Single texture font

#12 Post by Mitten.O »

I couldn't replicate the problem by your exact procedure.
I needed to launch freeorion, open the load dialog, close it,
then open options and change the title font from 13 to 14.
But that did it.

It is a wonder there was no more trouble.
I had a zero indexing bug.
I did not take into account that the width you need to
fit coordinate x is in fact x + 1.
Such a rookie mistake.
Thanks for helping me pin it down.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

User avatar
Foocaux
Space Squid
Posts: 78
Joined: Sat Jul 26, 2014 7:14 am

Re: [Patch] Single texture font

#13 Post by Foocaux »

Yep, with the latest patch everything seems fine here!

Glad I could help, I've got a keen interest in FreeOrion.exe's optimisation. :)
The small print: Any code contribution I make to FreeOrion is made under GPL v2.0, any graphic contribution is under CC-by-SA 3.0

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [Patch] Single texture font

#14 Post by Geoff the Medio »

Builds and runs OK for me... Except for one quirk: If I set the Window Title font size to 13, I get a massive drop in FPS, while on the options screen from the main splash screen. 12, 11, or 14 render normal speed, but just on 13, it drops to 2 or 3 FPS. Regular text font size doesn't seem to have any similar effect.

Mitten.O
Programmer
Posts: 255
Joined: Sun Apr 06, 2014 4:15 pm

Re: [Patch] Single texture font

#15 Post by Mitten.O »

I wasn't taking the texture max size into account properly,
which forced the opengl driver to simulate wider textures than
the hardware supported for very specific font sizes.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Any code by me in this post is released under GPL 2.0 or later.

Post Reply