Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

Fonts in Direct3D 9?

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

I need a way to output text to a surface in a flip chain. This is for debugging purposes, so I can display small things like FPS, etc. I want it to be something simple, I tried IDirect3DSurface9::GetDC() so that I could use Win32's TextOut() function, but this doesn't work with Windowed mode I don't think. GetDC() keeps failing for me. I need a way that will be compatible with both fullscreen and windowed mode. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
If you create a font with D3DXCreateFont() (which i believe can take any windows true type font) you can then make a call to ID3DXFont::DrawText() which will draw formatted text to the screen. I don't recall the exact details, but that's why the MSDN was created, right! clicksies!

Share this post


Link to post
Share on other sites
this may help you


// font.h

class Font
{

protected:

LPD3DXFONT m_pFont;

public:

Font() { m_pFont = NULL; }
~Font() { destroy(); }

void create(LPDIRECT3DDEVICE9 pDevice, UINT height, LPCTSTR pFacename);
void destroy();

void draw(LPD3DXSPRITE pSprite, LPCTSTR pString, int x, int y, D3DCOLOR color);

};




// font.cpp

#include <d3dx9.h>
#include "font.h"

void Font::create(LPDIRECT3DDEVICE9 pDevice, UINT height, LPCTSTR pFacename)
{
D3DXCreateFont(
pDevice, // D3D Device
height, // Height
0, // Width
FW_NORMAL, // Weight
1, // Mip Levels
FALSE, // Italic
DEFAULT_CHARSET, // Char Set
OUT_DEFAULT_PRECIS, // Output Precision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH|FF_DONTCARE, // Pitch And Family
pFacename, // Face Name
&m_pFont // D3DX Font
);
}

void Font::destroy()
{
if( m_pFont )
{
m_pFont->Release();
m_pFont = NULL;
}
}

void Font::draw(LPD3DXSPRITE pSprite, LPCTSTR pString, int x, int y, D3DCOLOR color)
{
RECT Rect; SetRect(&Rect, x, y, 0, 0);

m_pFont->DrawText(
pSprite, // Sprite
pString, // String
-1, // Count
&Rect, // Rect
DT_LEFT|DT_NOCLIP, // Format
color // Color
);
}

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!