Jump to content
  • Advertisement
Sign in to follow this  
Jtomage69

ID3DXFont troubles in gamecore

This topic is 4251 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 thank you all for help with my last post however I have decide not to install the previous SDK well since I could get the code running even after uninstalling. So I have decided to try and update the code cuz well I m going have to learn the updated DirectX at some point so might as well be now. So I have been able to reduce the number of errors, and I hope all the changes will allow the code to run. But here is where I am currently stuck. It has to do with the ID3DXFont. and I have no idea why that strcpy isnt working either.
Quote:
c:\documents and settings\jyt\my documents\visual studio 2005\projects\ch6\ch6\core_graphics.cpp(981) : error C2664: 'strcpy' : cannot convert parameter 1 from 'WCHAR [32]' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\documents and settings\jyt\my documents\visual studio 2005\projects\ch6\ch6\core_graphics.cpp(989) : error C2664: 'D3DXCreateFontIndirectW' : cannot convert parameter 2 from 'LOGFONT *__w64 ' to 'const D3DXFONT_DESCW *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\documents and settings\jyt\my documents\visual studio 2005\projects\ch6\ch6\core_graphics.cpp(1004) : error C2039: 'Begin' : is not a member of 'ID3DXFont' c:\program files\microsoft directx sdk (october 2006)\include\d3dx9core.h(314) : see declaration of 'ID3DXFont' c:\documents and settings\jyt\my documents\visual studio 2005\projects\ch6\ch6\core_graphics.cpp(1013) : error C2039: 'End' : is not a member of 'ID3DXFont' c:\program files\microsoft directx sdk (october 2006)\include\d3dx9core.h(314) : see declaration of 'ID3DXFont' c:\documents and settings\jyt\my documents\visual studio 2005\projects\ch6\ch6\core_graphics.cpp(1034) : error C2660: 'ID3DXFont::DrawTextW' : function does not take 5 arguments
and here is the code that is causing the problem
[source lang = "cpp"]

cFont::cFont()
{
  m_Font = NULL;
}

cFont::~cFont()
{
  Free();
}

ID3DXFont *cFont::GetFontCOM()
{
  return m_Font;
}

BOOL cFont::Create(cGraphics *Graphics, char *Name, long Size, BOOL Bold, BOOL Italic, BOOL Underline, BOOL Strikeout)
{
  LOGFONT lf;

  if(Graphics == NULL || Name == NULL)
    return FALSE;
  if(Graphics->GetDeviceCOM() == NULL)
    return FALSE;

  // Clear out the font structure
  ZeroMemory(&lf, sizeof(LOGFONT));

  // Set the font name and height
  strcpy(lf.lfFaceName, Name);     //the strcpy problem
  lf.lfHeight = -Size;
  lf.lfWeight = (Bold == TRUE) ? 700 : 0;
  lf.lfItalic = Italic;
  lf.lfUnderline = Underline;
  lf.lfStrikeOut = Strikeout;

  // Create the font object
  if(FAILED(D3DXCreateFontIndirect(Graphics->GetDeviceCOM(), &lf, &m_Font)))  //D3DXCreateFontIndirect error
    return FALSE;
  return TRUE;
}

BOOL cFont::Free()
{
  ReleaseCOM(m_Font);
  return TRUE;
}

BOOL cFont::Begin()
{
  if(m_Font == NULL)
    return FALSE;
  if(FAILED(m_Font->Begin()))  //ID3DXFont error
    return FALSE;
  return TRUE;
}

BOOL cFont::End()
{
  if(m_Font == NULL)
    return FALSE;
  if(FAILED(m_Font->End()))
    return FALSE;
  return TRUE;
}

BOOL cFont::Print(char *Text, long XPos, long YPos, long Width, long Height, D3DCOLOR Color, DWORD Format)
{
  RECT Rect;

  if(m_Font == NULL)
    return FALSE;

  if(!Width)
    Width = 65535;
  if(!Height)
    Height = 65536;

  Rect.left   = XPos;
  Rect.top    = YPos;
  Rect.right  = Rect.left + Width;
  Rect.bottom = Rect.top + Height;
  if(FAILED(m_Font->DrawText(Text, -1, &Rect, Format, Color)))
    return FALSE;
  return TRUE;
}


Thank you all in advance.

Share this post


Link to post
Share on other sites
Advertisement
Hello!

Error 1, is caused by the compiler using Unicode (wide character) support. I assume you're using VC2005 since this is the default setting for a new project. With this setting enabled, many D3DX and MS functions/structures use the wide character versions of themselves e.g. D3DXCreateFontIndirect() is expanded to D3DXCreateFontIndirectW() (rather than D3DXCreateFontIndirectA() the ascii version). The simple way to remedy this is to right-click your project, go to properties -> configuration properties -> C/C++ -> Language and set "Treat WChar_t as built in type" to "No". The other way is to use the wchar versions of functions, so instead of strcpy(), use wcscpy() and use wchar rather than char.

Error 2 can be solved by using the D3DXFONT_DESC structure rather than LOGFONT (I think they're very similar so it's an easy change).

Errors 3, 4, and 5 are caused because the ID3DXFont interface has changed. Begin() and End() no longer exist and don't need to be called (DrawText() still needs to be called within IDirect3DDevice9::BeginScene() however). DrawText() now takes 6 parameters:

INT DrawText(
LPD3DXSPRITE pSprite,
LPCTSTR pString,
INT Count,
LPRECT pRect,
DWORD Format,
D3DCOLOR Color
);

At I home I use it like this:

mpFont->DrawText(NULL, // Use ID3DXFont's string sprite
pStr, // The text I want to print
-1, // Assume string is null terminated and use strlen to calc length
&rc, // Position
DT_NOCLIP, colour);


HTH,
stoo

Share this post


Link to post
Share on other sites
there is a faster way to draw text, in d3d then id3dxfont believe me, i can give u dll if u want, if u want it send a message on s5zone@mail.ru

Share this post


Link to post
Share on other sites
Thank you for your help but I am still having some problems.

The strcpy still doesnt work. I tried both ways and still doesnt work. Then thought it might if I change to D3DXFont_DESC but it still doesnt. I am getting an

Quote:

error C2664: 'strcpy' : cannot convert parameter 1 from 'WCHAR' to 'char *'


and I did change the properties. I get a
Quote:

error C2664: 'wcscpy' : cannot convert parameter 2 from 'char *' to 'const wchar_t *'


with the code


D3DXFONT_DESC des

ZeroMemory(&desc, sizeof(D3DXFONT_DESC));

wcscpy(desc.FaceName, Name); or strcpy(desc.FaceName, Name);



And Also...

just double checking. I can delete the Begin and end then?

Share this post


Link to post
Share on other sites
Yeah, you can get rid of Begin() and End(). :)

This code works when the project is set to not use wchar_t by default.

char *pName = "SomeFontName";

D3DXFONT_DESC desc;
ZeroMemory(&desc, sizeof(D3DXFONT_DESC));
strcpy(desc.FaceName, pName);

D3DXCreateFontIndirect(mpDevice, &desc, &pFont);


If you still have trouble and you want to use single byte characters (i.e. char), try using the ASCII version of the D3DXFONT_DESC structure: D3DXFONT_DESCA, in case there is some weird project stuff going on.

stoo

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!