Jump to content
  • Advertisement
Sign in to follow this  
il_maestro

Obtaining a better quality with ID3DXFont

This topic is 4892 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

Hello, i'm writing a Quake-like console, it's almost finished but i have a problem with the raw quality of the font output. If i'll make this too, i'll pot here the Classes. The problem is that i obtain antialiased font that give out a "ghost" effect, very unpleasant. I tried to play turning off multisampling for the device, than changing the the flags of D3DXFONT_DESC but i did not obtain a decent result. Anyone have encountered that before or have a good advice? Many thanks.

Share this post


Link to post
Share on other sites
Advertisement
You mean a slight blur?

Try adding 0.5 to your text coordinates. There's a reason for this, but I cant be bothered going into it. :P

Share this post


Link to post
Share on other sites
Yes, that "slight blur".
But adding simply an offset is not an acceptable solution ;)
I can't see where is the point.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sounds like a "texels to pixels"-problem
Read about "Mapping Texels to Screen Space" in the DX documentation, or search this forum for some info about it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
"Directly Mapping Texels to Pixels" in the DX documentation is the correct article.

Share this post


Link to post
Share on other sites
Ok, i have read the article about textel and pixel. Many thanks, because now
i know one more thing. Sadly, it seems it does not apply to the case... Here
is some code.
This is where I create the font, and it's almost the same as Text3D sample
in the SDK.
HDC hDC = GetDC( NULL );
int nLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC( NULL, hDC );

int nHeight = -iLogicalFontHeight * nLogPixelsY / 72;

// Initialize and fill D3DXFONT_DESC structure ,that describes the font
ZeroMemory(&dxFontDescription, sizeof(D3DXFONT_DESC));
dxFontDescription.Height =nHeight; // in logical units
dxFontDescription.Width =0; // in logical units, if 0 is set using the height
dxFontDescription.Weight =FW_NORMAL; // boldness, range 0(light) - 1000(bold)
dxFontDescription.MipLevels =0; // A mipmap is a sequence of textures, use D3DX_DEFAULT to have a complete mipmap chain
//dxFontDescription.Italic =false; // Italic on a console? Nah....
dxFontDescription.CharSet =DEFAULT_CHARSET; // iso-8859-1 or kind of....
dxFontDescription.OutputPrecision =OUT_DEFAULT_PRECIS; // defines how closely the output must match the requested font height, width......
dxFontDescription.Quality =DEFAULT_QUALITY; // Writes with the default quality
dxFontDescription.PitchAndFamily =DEFAULT_PITCH|FF_DONTCARE; // Default pitch and kick to the family

strcpy(dxFontDescription.FaceName, sFontName); // font style

// Make sure we have a valid D3D Device
if(!dxDevice) {
return E_FAIL;
};

// Create an ID3DXFont based on dxFontDescription.
if(FAILED(hr=D3DXCreateFontIndirect(dxDevice, &dxFontDescription, &dxFont)))
{
::OutputDebugStr("Failed #D3DXCreateFontIndirect# call in #CTextOut::ResetFont#");
return hr;
}

Here I call the DrawText to render a string to the screen (i'm not drawing
on a texture).

// give the screen offset of given x, y
SetRect(&rect,x,y,0,0);

// the first call returns the height of the rectangle to draw in
if (FAILED(hr=dxFont->DrawText(
NULL, // LPD3DXSPRITE pSprite
sTextBufferTemp.c_str(), //LPCTSTR pString
-1, // int Count, size of string or -1 indicates null terminating string
&rect, // LPRECT pRect, rectangle text is to be formatted to in windows coords
DT_CALCRECT, // DWORD Format, draw in the left without clipping
dxFGColor))) // D3DCOLOR Color ,black text
{
::OutputDebugStr("Failed #dxDevice->BeginScene# call in #CTextOut::Lock#");
return hr;
}

// the second call put the text in the defined rectangle
if (FAILED(hr=dxFont->DrawText(
NULL, // LPD3DXSPRITE pSprite
sTextBufferTemp.c_str(), //LPCTSTR pString
-1, // int Count, size of string or -1 indicates null terminating string
&rect, // LPRECT pRect, rectangle text is to be formatted to in windows coords
DT_LEFT|DT_NOCLIP, // DWORD Format, draw in the left without clipping
dxFGColor))) // D3DCOLOR Color ,black text
{
::OutputDebugStr("Failed #dxDevice->BeginScene# call in #CTextOut::Lock#");
return hr;
}



So there isn't place to give a -0.5 offset. :-(

Share this post


Link to post
Share on other sites
From the docs:
DEFAULT_QUALITY - Appearance of the font does not matter.

Are you sure that's what you want?

I've always used ANTIALIASED_QUALITY, but you also might want to try NONANTIALIASED_QUALITY or PROOF_QUALITY to get the effect you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrunkenHyena
I've always used ANTIALIASED_QUALITY, but you also might want to try NONANTIALIASED_QUALITY or PROOF_QUALITY to get the effect you want.


I point out one more strange thing: even if i change to NONANTIALIASED_QUALITY, ANTIALIASED_QUALITY... the output look always exactly the same :-|

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!