Thread View: borland.public.cppbuilder.multimedia
1 messages
1 total messages
Started by Jonathan Benedicto
Thu, 31 Mar 2005 02:42
D3DXCreateFont
Author: Jonathan Benedicto
Date: Thu, 31 Mar 2005 02:42
Date: Thu, 31 Mar 2005 02:42
60 lines
2539 bytes
2539 bytes
I'm using dx 9 to build a 3d app.
I've been trying to use D3DXCreateFont to create a D3DDXFont so that I
can draw some info to the back buffer.
I create the D3DDXFont in a method like this :
HRESULT __fastcall TMForm::CreateD3DXFont(LPD3DXFONT* ppd3dxFont,
AnsiString pstrFont, DWORD dwSize)
{
HRESULT hr;
LPD3DXFONT pd3dxFontNew = NULL;
HDC hDC;
INT nHeight;
HFONT hFont;
hDC = GetDC( NULL );
nHeight = -MulDiv(dwSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
ReleaseDC(NULL, hDC);
hFont = CreateFont(nHeight, 0, 0, 0, FW_DONTCARE, false,
false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
pstrFont.c_str());
if(hFont == NULL)
return E_FAIL;
try{
hr = D3DXCreateFont(g_pd3dDevice, hFont,
&pd3dxFontNew);
}catch(Exception& E){
hr = E_FAIL;
Log->Add("Exception thrown while creating font.");
}catch(...){
hr = E_FAIL;
Log->Add("Exception thrown while creating font.");
}
DeleteObject(hFont);
if(SUCCEEDED(hr))
*ppd3dxFont = pd3dxFontNew;
return hr;
}
And call the method like this :
// Create a font for statistics and help output
hr = CreateD3DXFont(&g_pd3dxFont, "Arial", 14);
if(FAILED(hr)){
Log->Add("Can't create font.");
throw Exception("Can't create font.");
}
However, the call to D3DXCreateFont always throws a EAccessViolation.
Please can someone help me to find out what I've done wrong.
--
Jonathan
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads