Skip to main content
gamedev.net
🔒 Locked

CD3DFont

Started by Todd Casey 4 replies 1k views
Original Post
Todd Casey
Todd Casey
I am trying to use the CD3DFont class that came with the DirectX 8 SDK. I currently have a triangle displayed on the screen to make sure that my D3D8 initialization code wasn''t failing but it works fine. I have the CD3DFont class declared as: CD3DFont *pFont = NULL; Then I try to initialize the class: pFont = new CD3DFont(_T("Arial"), 12, D3DFONT_BOLD); // I call this after I have initialized the pd3dDevice successfully pFont->InitDeviceObjects(pd3dDevice); Then between my D3DDevice BeginScene and EndScene calls I''m trying to draw text: pFont->DrawText(2, 40, 0xffffffff, _T("2D Text")); It crashes in the DrawText member function on this line: m_pd3dDevice->ApplyStateBlock( m_dwDrawTextStateBlock ); I am probably missing something small but I can''t seem to find it! Thanks for any help or ideas. Todd
SikCiv
SikCiv
I had the same problem. I ended up using the D3DX font interface. Its much easier to use, all u have to do is create a standard HFont object, then create the D3DX font object using D3DXCreateFont and specify the HFont u created. drawing it is simple, just call ->DrawText.


Heres my code...


// CREATION

// Create a font.
HFONT Font[10];

Font[0] = CreateFont(14,0,0,0,0,0,0,0,0,0,0,PROOF_QUALITY,0, "Courier New");
if(Font[0] == NULL)
{
DebugOutput("Font[0] Failed to create HFont.");
}
else
{
// Create a 3D Font.
hr = D3DXCreateFont(lpD3DDevice, Font[0], &lpD3DXFont[0]);
if(FAILED(hr))
{
DebugOutput("Font[0] Failed to create 3D Font.");
}
}




// DRAWING...

RECT rcTemp =
MakeRc(0,(GfxSys.nVSize-65)+i*13,640,480);
hr = lpD3DXFont[0]->DrawText(szTemp, -1, &rcTemp, DT_LEFT, D3DCOLOR_ARGB(155, 155, Debug.StringColor+50, 255));

if(FAILED(hr)) DebugOutput("Failed 3D Font text blit");



Its a bit messy due to the lack of horz space..but its usable and it works fine.

  Downloads:  ZeroOne Realm
Todd Casey
Todd Casey
Thanks for the info!

Todd
headache
headache
This is gonna sound weird but call the RestoreObjects function after you init it and that should fix it.
Todd Casey
Todd Casey
I tried that but with no luck. Did you get it working for yourself? Thanks.

Todd
DmGoober
DmGoober
I haven't looked to carefully at your code and problems, but i know for a fact that the pick example that comes with the sdk prints framerate information to the d3ddevice. Have you tried looking at that?

It uses the following:

m_pFont = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );

CD3DFont is defined in a file probably named d3dfont.cpp/.h

Be careful -- everytime the device changes (for example switching from full screen to windowed) the CD3DFont needs to be invalidated, inited, restored, etc.

HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();

I'm obviously talking out of my butt since i haven't really looked at the font stuff too carefully, but i strongly suggest you look at pick.cpp (and look at d3dapp.cpp for more info.)

Hope that helps.

DmGoober

Edited by - DmGoober on November 24, 2000 11:22:59 AM
Alexander "DmGoober" Jhinalexjh@online.microsoft.com[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.