Sign in to follow this  
Malazar

create text function in directx

Recommended Posts

Malazar    152
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'

Share this post


Link to post
Share on other sites
DesignerX    174
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.

Share this post


Link to post
Share on other sites
Malazar    152
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]

Share this post


Link to post
Share on other sites
Malazar    152
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?

Share this post


Link to post
Share on other sites
Evil Steve    2017
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?

Share this post


Link to post
Share on other sites
Malazar    152
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]

Share this post


Link to post
Share on other sites
Sc4Freak    643
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
);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this