ID3DXFont really rubbish quality

Started by
22 comments, last by AshleysBrain 15 years ago
Hmm I found this thread while googling around:

http://forums.devx.com/archive/index.php/t-153589.html

'Actually I use A8R8G8B8 as a render target and it works fine. All you need is to fill the background with ARGB = 0,255,255,255 then you render the text with fully white color (255,255,255,255) in your A8R8G8B8 render target. Then in your ID3DXSprite Draw function you set the last param to the color you want the text to be displayed with (in your case black).'

My guess is whats happened is when he drew the text onto the render target it used these render states:

SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

Now the red green blue channels would have remained 255,255,255, but the alpha channel would have been multiplied by itself:
alpha = srcalpha * srcalpha + destalpha * (1-srcalpha)
alpha = srcalpha * srcalpha + 0 * (1-srcalpha)
alpha = srcalpha * srcalpha

Anyway heres an image with three lines of text.
The first is the normal 'blocky' writing
The second is the normal 'blocky' writing after its alpha has been multiplied by itself
The third is MS paint text



Although this improves the quality of the antialising it still looks thicker than the MS Paint one :/
Advertisement
I think Codeka was right on the ball with this one!

Have a look at this:



I did this all in MS Paint. I inverted the white text on a black background so it became black text on a white background...and low and behold it looks like s***! And looks exactly like the blocky text!
Well I had a go at modifying it:

HDC dc = gfont->GetDC();
SetBkColor(dc, RGB(255,255,255));
SetTextColor(dc, RGB(0,0,0));

But when you call the drawtext function, the letters are inverted...like instead of it drawing the letters, it draws the background. Heres a screenie:



The first window is how it rendered. The second two are modified in paintbrush...but this is how text should look on a white background..

So I think DirectX creates the font using a black background and white text...then creates the texture using the black to white values as the alpha channel (black being transparent, white being opaque)
So what's it doing wrong? If it creates just an alpha channel, why's it mess up so bad with black text on a white background? Why does the invert trick work? Are there some renderstates that could do that without using shaders?
Construct (Free open-source game creator)

This topic is closed to new replies.

Advertisement