Pages: 1
  Print  
Author Topic: Font Fractional Metrics  (Read 10774 times)
Offline (Male) Goombert
Posted on: May 19, 2014, 06:43:23 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
Well, after rigorous testing I have learned a lot of things about half-pixel alignment between Direct3D and OpenGL.

* You can not half-pixel align in the view or the bottom and right edges will be empty on the screen, or do similar for surfaces.
* You must add not subtract the pixel alignment in the projection function, if you subtract you'll get a similar issue to views.
* 0.25 appears to work the best in all cases, 0.5 may be driver/graphics card dependent
* OpenGL can not do a full half-pixel alignment (0.5) or games with repeating/scrolling backgrounds will skip and have a 1px gap sometimes between them.
* OpenGL and Direct3D pixel align differently, for instance, 0.25 is used in both systems, but when rendering text, you'll notice OpenGL has a space between lowercase 'r' and 't' whereas Direct3D does not, and Direct3D has a space between uppercase 'T' and 'Y' where OpenGL does not. One solution to this is to round up the glyph sizes in the font struct initialization.

NOTE: I used GM8 not 8.1, regardless of what the caption says, which did not have anti-aliasing options and by default used interpolation to render the font. And in ENIGMA I had the anti-aliasing disabled.



You can see GM8.0 renders the same as our Direct3D 9 system except it has interpolation because there were no aliasing options and it is turned off in ENIGMA. I used this code to test.
Code: (EDL) [Select]
draw_set_font(font0);
draw_set_color(c_black);
draw_text(0,0,"01234567890!@#$%^&*()_+-={}[]:;|\?/>.<,
QWERTYUIOPASDFGHJKLZXCVBNM
qwertyuiopasdfghjklzxcvbnm");

However, we still have the issue of the last bullet there. Because of font characters having fractional dimensions, they can still very easily become malaligned. The only solution I have thought of is to round up their dimensions, or else we need to find a way to truly fix half-pixel alignment.

Upon investigating the plugin I discovered that IsmAvatar has disabed fractional font metrics, which means subpixel accuracy. Or in other words the metrics should already be integer spaced.
http://docs.oracle.com/javase/7/docs/api/java/awt/RenderingHints.html#KEY_FRACTIONALMETRICS
https://github.com/enigma-dev/lgmplugin/blob/master/org/enigma/EnigmaWriter.java#L687
« Last Edit: May 20, 2014, 02:22:49 pm by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #1 Posted on: May 19, 2014, 07:25:32 pm
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
hmm looks minor to me, still way better than it was before.  When using fonts and tweaking size/bold/aliasing, it can be compensated and rendered nicely.  I experimented with it and worked fine.

Still noticed some issues in DX9 when using arial, size 20 bold aliasing off, there is a vertical line between the T and y, when using aliasing 1, it is gone.

I'm off to try this in YoYoLand. :D

Logged
Offline (Unknown gender) Darkstar2
Reply #2 Posted on: May 19, 2014, 07:41:25 pm
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
Ok, interesting.  default text rendering in GMS is a complete pile of dung...blurry as fuck, too much spacing between letters, and wrong v positioning !  When setting fonts things are correctly displayed, I could not reproduce the anomaly I saw in ENIGMA with the | after the T as explained above.

Anyhow so far it seems OGL rendering of fonts produces best results.  Ran with your code above using different fonts and it looks great, it's all a matter of tweaking size and aliasing and it's perfect.  Spacing differences to me is a minor issue in a game, we are talking about 1 pixel offsets, probably most people won't even notice lol!

Logged
Offline (Male) Goombert
Reply #3 Posted on: May 19, 2014, 10:02:58 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
On a funny side note, the latest version of Studio 1.3.1344 just released also has buggy pixel alignment.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #4 Posted on: May 19, 2014, 10:41:48 pm
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
It's been like that for previous versions too.
Tested under 1.2 same.  However, this happens with non assigned fonts.
Assigned fonts display ok.

However unassigned fonts under studio have more spacing between letters ! Do you notice also how the letters are also not properly vertically aligned.... in ENIGMA they are perfectly V aligned.  Again, these obviously visible issues are with unassigned fonts.

Logged
Offline (Male) Goombert
Reply #5 Posted on: May 20, 2014, 01:46:11 am

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
What? No I think you are not understanding, the top "Hello, world!" was drawn at a half-pixel and is visibly blurry, the bottom one is not.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #6 Posted on: May 20, 2014, 01:55:17 am
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
Right.....people have made complaints about font issues for years to YYG about blurry text, alignment issues, etc.

You DID know that GM's font rendering was buggy already and for a long time right ??? Why I think it is a something that can be easily forgiven is simple.....assign the bloody fonts ! :P The spacing issues is pretty tame compared to some of the more serious issues that could impact some game elements ! :D


« Last Edit: May 20, 2014, 01:57:03 am by Darkstar2 » Logged
Offline (Male) Goombert
Reply #7 Posted on: May 20, 2014, 02:19:38 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
No you're still not listening, it happens with assigned fonts as well, that picture from Studio is with an assigned font. Sprites will do the same in Studio as well. After my changes yesterday you should not have this problem in ENIGMA

Make a blank font and leave the default settings then add this draw code to a new object, place it in a room, and run it.
Code: (GML) [Select]
draw_set_font(font0);
draw_text(0, 0, "Hello, world!");
draw_text(1.5,20.5, "Hello, world!");

In Studio you get the image above, in ENIGMA, everything is good.


See? Because we half pixel aligned the projections like vector graphics should be, you will not ever have this issue with ENIGMA as of the changes yesterday.
« Last Edit: May 20, 2014, 02:27:47 pm by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #8 Posted on: May 20, 2014, 03:47:50 pm
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
Ohh right, I guess I didn't see much changes perhaps tiredness or optical illusion but when looking at the image above sideway I see the more obvious difference.

Strange because when I tested in GMS yesterday, I found unassigned fonts were far more blurrier, regardless of their position.
and when I used assigned fonts they were crisp.

Well it's good to know we don't have this issue in ENIGMA. Nice find.  Thanks for the fix.

Goes to show you that you will never get flawless, there's probably always will be issues in ENIGMA that are not present in GMS and issues in GMS that are not present in ENIGMA.

I think pixel offset / spacing issues with fonts is far more forgiving than blurriness of fonts.

BTW, as I recall GM always used DX9, right ?  Does GMS still use DX9 ?

The changes you made, I'm assuming is not just for text rendering but anything rendered on screen right ? and these flaws are more visible with text..... Will these changes impact on anything else such as particles ? sprites ?

As far as sprites having the same problem I guess I did not notice that in GMS.  The thing is most people probably won't notice these flaws especially when they are moving on screen as opposed to being still.

Logged
Offline (Male) Goombert
Reply #9 Posted on: May 20, 2014, 06:23:21 pm

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 2993

View Profile
Quote from: Darkstar2
Well it's good to know we don't have this issue in ENIGMA. Nice find.  Thanks for the fix.
You mean, we don't have them anymore. I would also appreciate if you could download the Portable ZIP and double check there is no font blurriness for you in both OpenGL 1 and Direct3D 9.
http://enigma-dev.org/docs/Wiki/Install:Windows

And yes this does affect sprites/backgrounds and everything else drawn orthographically, it means there should not be any half-pixel alignment issues, you should never get blurriness from drawing a sprite or text or anything at fractional pixels, for instance x=1.5670 and or y = 2.3568

Quote from: Darkstar2
BTW, as I recall GM always used DX9, right ?  Does GMS still use DX9 ?
GM does not use just DirectX anymore, it uses Googles' Almost Native Graphics Layer Engine, also known as ANGLE. Which is also used by the Qt Framework, Firefox, and Chrome.
https://code.google.com/p/angleproject/

That's how they allow HLSL shaders in games on Linux, theoretically of course, I have not proven it. We decided to just stick with basic Direct3D and OpenGL since it is both lighter weight and well, nobody really gives a fuck about Direct3D because it is not cross-platform.
« Last Edit: May 20, 2014, 06:26:11 pm by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #10 Posted on: May 20, 2014, 11:33:19 pm
Member
Joined: Jan 2014
Posts: 1238

View Profile Email
Ok there are 2 things, 1 is good 1 is shitty :D
I'll start with the good :D

1)  Tested with your hello world code, yep looks good I didn't see any blurring.  There is going to some bias however, if your screen resolution is smaller than game room resolution, the blurring you will see is the effect of the upscaling - this is the side effect of LCD monitors.  in window mode no blur.  To test full screen I had to set my monitor to its native resolution (1920x1080) no blurring.

2) is off topic, but whilst testing this I accidentally found a way to reproduce crashing ENIGMA and I was shocked how easy it was.

 
Logged
Pages: 1
  Print