Direct2D interface and blurry text issue
Asked Answered
L

2

7

My new application will feature a rich interface which should be resizable on-the-fly uses transparent icons/images etc. For this application I'm trying to decide on using the new Direct2D API against the good old GDI. One of the downsides is of course it does not run on XP, although I've found a bit nastier issues to decide upon:

  1. I noticed that outputting text in a Direct2D environment seems a bit blurry (although marketed as a feature). Just look at the text in Firefox 4 with hardware acceleration enabled (or IE9). It seems to be due to the fact that in Direct2D text does not adhere to the (pixel) grid like GDI does. Is there a way to force Direct2D to make it adhere to the pixel grid and thus fixing this issue?

  2. Is there really such an improvement in speed? I tried to understand this article and what I make from it is that in Windows 7 and XP (not Vista?) the GDI is already hardware accelerated where it can. E.g. in my application I use a lot of memory DC's which are just BitBlted into place and drawing transparent images/anti-aliased lines etc are being drawn using AlphaBlend. And that last one is definitely hardware accelerated since I measured speed while testing my routines.

So where would you put your money? Is Direct2D worth the hassle or would you just stick to the good old GDI? Or would you suggest something else?

Note: I'm programming in C++ btw, no use of MFC.

Lording answered 21/9, 2011 at 10:56 Comment(3)
Ah, so Microsoft is finally taking the Apple route when it comes to fonts.Conservancy
I would say, using Direct2D would be a bad idea if your application involves displaying a lot of text (like a browser). Obviously, some people disagree with me.Volsci
Technically asking for opinions on SO is a no-no (see the "not constructive" category in the FAQ). But I like the question, and I haven't found a better good forum for discussions like this, so I'm not voting to close.Anticlimax
V
6

The fix to your problem is very simple. Direct2D is highly configurable, and that includes text rendering and hinting. If you want to make it render text to match GDI's rendering (that is, very tight pixel alignment) just:

Since the other answer went out of its way to be most unhelpful and bash the rendering in Direct2D, let me provide another overview of Direct2D's text rendering. It is very, very good. Unlike on the Mac, where they basically do not hint fonts and the text actually comes out as blurry, Direct2D by default strongly hints in the Y direction only. This makes sense since your monitor probably has about 96 dpi vertically, but with sub-pixel anti-aliasing the horizontal resolution is beyond the range of reasonable human perception. It is also a lot more subtle in its ClearType usage and hinting than GDI was. The edges of GDI text tend to be very colorful compared to Direct2D. I find GDI text very harsh-looking nowadays and much prefer the Direct2D text in Firefox and IE for long reading sessions.

Therefore, there are several reasons that the default mode probably appears "blurry" to you.

  1. First of all, take the time to run the ClearType tuner program in the control panel. You will be amazed at the difference in Direct2D programs.
  2. No matter how good it is, it will always appear strange when you place it next to GDI-spaced text in your application. Try making everything in the UI one or the other, or clearly distinguish the content area from the other areas. If you decide to make everything GDI-spaced, just use the method I described above to set Direct2D to GDI-spaced text mode.
  3. You haven't installed all available updates from Windows Update. There have been several for DirectWrite and IE. Make sure you install them all and restart to see the improvements.
  4. You just haven't gotten used to it yet.
  5. It's in your head. Really. Once you start thinking about text rendering a lot, you'll probably find yourself noticing "problems" that aren't there. The other answer to this question is the perfect example. He states that he thinks the text in Visual Studio 2010 is blurrier than 2008, but they are actually pixel perfect copies. Don't believe me? The VS developers actually provided some comparisons yourself. I bet you can't tell the difference. http://blogs.msdn.com/b/text/archive/2010/03/05/additional-wpf-text-clarity-improvements.aspx
Volcanism answered 30/1, 2012 at 8:26 Comment(2)
Thanks finally some useful information on the subject. By now I have already written the application using the GDI, but I will definitely try this. And what you said in the other 5 points makes sense too, especially 4: I didn't like ClearType at first either...Lording
"[T]he other answer went out of its way to be most unhelpful and bash the rendering in Direct2D" Ouch! I don't think it's fair to label what I wrote as unhelpful, nor do I bash Direct2D. I'm pointing out that the two systems optimize for different things: readability given real-world constraints of most displays versus full generality for transforms. In regards to VS displays, it has gotten better, but the Direct2D versions are still notably blurrier than the GDI ones when using a higher logical DPI setting. The text also shifts a fraction of a pixel as the syntax highlighter catches up.Anticlimax
A
1

Just as much software relies on the inevitable march of Moore's law to offer more and more horsepower, GDI+ and Direct2D seem predicated on the fact that screen resolutions (pixel density) would continue to improve. But the fact is that pixel density has not increased significantly and, in face, has reached a plateau.

GDI text was designed with the assumption that resolutions suck. Pixel alignment, hinting, and later sub-pixel rendering (such as ClearType) are all well-engineered compromises that weighed the real-life constraint of readability at 75-100 pixels per inch against the generality of arbitrary transforms like scaling and rotation.

If our screens had pixel densities closer to what modern printers can produce, I'd be happy to surrender these compromises in favor of generality. But we're not there. We're not even close. Personally, I find the editor in VS 2010 far less readable than the one in VS 2008 for exactly these reasons.

Things to consider: Do you have to worry about devices other than the screen? Printers? Does Direct2D handle printers or do you have to implement a GDI solution anyway? How important is Windows XP? How future proof do you want to be? Direct2D is clearly the direction Microsoft is trying to move everyone.

Things not to consider: Speed. I've yet to see any modern application limited by the speed of rendering text to the screen, regardless of the technology. It's a highly optimized path. The actual layout is probably much more of a bottleneck than setting pixels values on the screen. If you're animating a zoom of a full screen, then maybe you need Direct2D--not for speed, but for the general transforms and smooth scaling.

Anticlimax answered 21/9, 2011 at 16:53 Comment(4)
Yes indeed, it's scaling/sizing/animation etc what seems to be the bottle neck, not the text rendering. Thanks for your write-up, I'm very much feeling the 'Direct2D text rendering is correct on high DPI panels' point as well, but doesn't do well with on a low DPI. So may I conclude you're actually saying Direct2D is a technique to be employed in the future, not just yet?Lording
What you say would be true, except apple.com/macbook-pro/features has a 220dpi display. It won't be long before there are Windows machines with similar displays either.Gerstein
Oh, and while we’re about it, plenty of applications are (stupidly) limited by the speed of rendering text to the screen. Typically they do things like e.g. copying files and displaying every single filename, which is really dumb. (The right way is to use a timer to update the display every so often, FWIW).Gerstein
@alastair: Yes, the "retina" displays that have arrived since I wrote this answer represent a huge leap in resolution for displays, which generally hadn't significantly increased in resolution for a very long time. But it will be a very long time before all displays are super high-res. For the foreseeable future, I'll still be using GDI for readability. (Using GDI on a super-high res screen isn't much of a cost.)Anticlimax

© 2022 - 2024 — McMap. All rights reserved.