create text function in directx

Started by
6 comments, last by Sc4Freak 16 years, 11 months ago
I've been working through a book (introduction to 3D game programming with directx 9.0 by Frank D. Luna) and have been trying to impliment a text render function as displayed in the book. my function looks like this: void CreateFont () { HRESULT D3DXCreateFontIndirect(LPDIRECT3DDEVICE9 pDevice, CONST LOGFONT*, LPD3DXFONT* ppFont); LOGFONT lf; ZeroMemory(&lf, sizeof (LOGFONT) ); lf.lfHeight =25; lf.lfWidth =12; lf.lfWeight =500; lf.lfItalic =false; lf.lfUnderline =false; lf.lfStrikeOut =false; lf.lfCharSet =DEFAULT_CHARSET; strcpy_s(lf.lfFaceName, "Times New Roman"); ID3DXFont* font = 0; D3DXCreateFontIndirect(pDevice,&lf,&font); } it currently generates an error, stating that the device named "pDevice" is an undeclaired identifier. any thoughts on this? it'd be especially handy if someone knows the book and has tried the code he used in this chapter before. cheers, Mal'
Advertisement
Why you have a function (D3DXCreateFontIndirect(...)) declared inside another funciton (CreateFont() ).

It should look something like this :

void CreateFont (LPDIRECT3DDEVICE9 pDevice){ZeroMemory(&lf, sizeof (LOGFONT) );lf.lfHeight =25;lf.lfWidth =12;lf.lfWeight =500;lf.lfItalic =false;lf.lfUnderline =false;lf.lfStrikeOut =false;lf.lfCharSet =DEFAULT_CHARSET;strcpy_s(lf.lfFaceName, "Times New Roman");ID3DXFont* font = 0;D3DXCreateFontIndirect(pDevice,&lf,&font);}


Where pDevice is a pointer to a direct3d device already created outside the function.
There is nothing that can't be solved. Just people that can't solve it. :)
i've separated the two, and things seem to be going a little better, though the function is now generating the following error instead:

LNK2019: unresolved external symbol "long __cdecl D3DXCreateFontIndirectA(struct IDirect3DDevice9 *,struct tagLOGFONTA const *,struct ID3DXFont * *)" (?D3DXCreateFontIndirectA@@YAJPAUIDirect3DDevice9@@PBUtagLOGFONTA@@PAPAUID3DXFont@@@Z) referenced in function "void __cdecl CreateFontA(struct IDirect3DDevice9 *)" (?CreateFontA@@YAXPAUIDirect3DDevice9@@@Z)

i don't know what external is being unresolved here :S

thanks for your help so far.

[Edited by - Malazar on May 3, 2007 7:51:38 PM]
You must add the d3dx9.lib library to your linker. Have you done that ?
There is nothing that can't be solved. Just people that can't solve it. :)
Quote:Original post by DesignerX
You must add the d3dx9.lib library to your linker. Have you done that ?


yeah, i already got that added. well i had d3dx9d.lib added, i tried just adding d3dx9.lib and having both added, and it came with the same result. is there any other library that might be causing it?
d3dx9d.lib should be used for debug builds, d3dx9.lib for release builds.

Are you sure that you have the DirectX SDK installed and set up correctly? What IDE are you using?
Quote:Original post by Evil Steve
d3dx9d.lib should be used for debug builds, d3dx9.lib for release builds.

Are you sure that you have the DirectX SDK installed and set up correctly? What IDE are you using?


i'm using visual studio 2005 (genuine, not express)

i'm also certain the directx sdk is installed and set up propperly, because this isn't the first directx project i've worked on, hence my confusion over this situation :S

EDIT:
I had a little shuffle round, to see if i could declair this in a different way, so now i have the following:

//global variables
LPDIRECT3DDEVICE9 pDevice;

//function prototypes
void CreateFont (LPDIRECT3DDEVICE9 pDevice);

HRESULT D3DXCreateFontIndirect(/*LPDIRECT3DDEVICE9*/ pDevice,
CONST LOGFONT*,
LPD3DXFONT* ppFont);

void CreateFont (LPDIRECT3DDEVICE9 pDevice)
{

LOGFONT lf;

ZeroMemory(&lf, sizeof (LOGFONT) );
lf.lfHeight =25;
lf.lfWidth =12;
lf.lfWeight =500;
lf.lfItalic =false;
lf.lfUnderline =false;
lf.lfStrikeOut =false;
lf.lfCharSet =DEFAULT_CHARSET;
strcpy_s(lf.lfFaceName, "Times New Roman");

ID3DXFont* font = 0;
D3DXCreateFontIndirect(pDevice,&lf,&font);
}

this comes up with the following errors instead:
error C2059: syntax error : 'const'
error C2664: 'D3DXCreateFontIndirectA' : cannot convert parameter 2 from 'LOGFONT *__w64 ' to 'const D3DXFONT_DESCA *'

can anyone tell me if i'm going in the right direction now? sorry to be such a pain in the behind.

[Edited by - Malazar on May 4, 2007 11:57:44 AM]
Why are you trying to forward declare D3DXCreateFontIndirect()? This function is included in D3DX, if you want to use it, all you have to do is include d3dx.h and its library.

Besides, your forward declaration isn't correct. From the DirectX SDK Documentation:

Quote:
HRESULT D3DXCreateFontIndirect(
LPDIRECT3DDEVICE9 pDevice,
CONST D3DXFONT_DESC * pDesc,
LPD3DXFONT * ppFont
);
NextWar: The Quest for Earth available now for Windows Phone 7.

This topic is closed to new replies.

Advertisement