Dont know if this may be useful but I wrote a way to auto assign the ID's and create a class version, much like the .net wrapper.
You just do this in your h file..
D3DText text;
enum {
ALIGN_LEFT = 0,
ALIGN_CENTER,
ALIGN_RIGHT };
Make sure to do the include #include "D3DText.h" and that enum statement.
and this in the main..
text.SetFont("Arial", 12, 0, 0);
text.StartText();
text.AAText(100, 100, ALIGN_LEFT, "Hello World!");
text.AAText(10, 10, ALIGN_LEFT, "Hello World2!");
text.AAText(0, 10, ALIGN_LEFT, "Hello World3!");
text.EndText();
of course you could make a function for this is you like. so its more like.. text.font(100, 100, ALIGN_LEFT, Arial, 12, 0, 0, "Hello World!"); combining it all in. I like the start and end so I left it.
here is the D3DText.h
#ifndef _D3DTEXT_H_
#define _D3DTEXT_H_
#include "d3d9.h"
class D3DText
{
public:
D3DText( void );
virtual ~D3DText( void );
void SetFont(LPSTR pFont, int nFontSize, int nFontBold, int nFontItalic);
void StartText(void);
void EndText(void);
void AAText(int x, int y, int nAlign, LPSTR pString);
void SetTextCol(int r, int g, int b, int a);
int getID( void ) ;
void deleteDevice( void ) ;
private:
int g_nRed;
int g_nGreen;
int g_nBlue;
int g_nAlpha;
int g_nFontSize;
bool g_Bold;
bool g_Italic;
char g_strFont[LF_FACESIZE];
ID3DXFont* g_pFont[20];
ID3DXFont* g_pFont2;
ID3DXFont* g_pStatsFont;
IDirect3DDevice9* g_pd3dDevice;
ID3DXSprite* g_pTextSprite;
static D3DText *m_pInstance;
int m_iID;
};
#endif
and the D3DText.Cpp
//#######################################
// Fast Antialiased Text
// Use instead of normal dbText()
//
// Thanks to Cloggy from tgc forums for
// the original dll code.
//
// Converted from dbp dll to DarkSDK
// addon by Sephnroth
//#######################################
#include "DarkSDK.h"
#include "D3DFactory.h"
#include "D3Dtext.h"
D3DText::D3DText( void ) {
m_iID = D3DFactory::getInstance( )->getNextID( );
g_nRed=255;
g_nGreen=255;
g_nBlue=255;
g_nAlpha=255;
g_Bold = false;
g_Italic = false;
g_pFont2 = NULL;
g_pStatsFont = NULL;
g_pd3dDevice = NULL;
g_pTextSprite = NULL;
g_pd3dDevice = dbGetDirect3DDevice();
}
D3DText::~D3DText( void ) {
}
void D3DText::SetTextCol(int r, int g, int b, int a) {
g_nRed = r;
g_nGreen = g;
g_nBlue = b;
g_nAlpha = a;
}
void D3DText::SetFont(LPSTR pFont, int nFontSize, int nFontBold, int nFontItalic) {
HRESULT hr;
if (m_iID > 20) {
return;
}
HDC hDC = GetDC(NULL);
int nLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
ReleaseDC(NULL, hDC);
int g_nFontSize = -nFontSize * nLogPixelsY / 72;
if (m_iID == 1)
lstrcpy(g_strFont, pFont);
if (nFontBold == 1) {
g_Bold = true;
} else {
g_Bold = false;
}
if (nFontItalic == 1) {
g_Italic = true;
} else {
g_Italic = false;
}
hr = D3DXCreateFont( g_pd3dDevice, // D3D device
g_nFontSize, // Height
0, // Width
g_Bold ? FW_BOLD : FW_NORMAL, // Weight
1, // MipLevels, 0 = autogen mipmaps
g_Italic, // Italic
DEFAULT_CHARSET, // CharSet
OUT_DEFAULT_PRECIS, // OutputPrecision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_DONTCARE, // PitchAndFamily
pFont, // pFaceName
&g_pFont[m_iID]); // ppFont
g_pFont[m_iID]->PreloadGlyphs(32,180);
if (g_pTextSprite == NULL)
hr = D3DXCreateSprite( g_pd3dDevice, &g_pTextSprite );
}
void D3DText::StartText(void) {
g_pTextSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);
}
void D3DText::EndText(void) {
g_pTextSprite->End();
}
void D3DText::AAText(int x, int y, int nAlign, LPSTR pString) {
RECT rc;
if (m_iID > 20)
return;
SetRect(&rc, x, y, 0, 0 );
switch (nAlign) {
case 1:
{
g_pFont[m_iID]->DrawText( g_pTextSprite, pString, -1, &rc, DT_CALCRECT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ));
rc.left=x-((rc.right-x)/2);
rc.right=x+((rc.right-x)/2);
break;
}
case 2:
{
g_pFont[m_iID]->DrawText( g_pTextSprite, pString, -1, &rc, DT_CALCRECT, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ));
rc.left=x-(rc.right-x);
rc.right=x+(rc.right-x);
break;
}
}
g_pFont[m_iID]->DrawText( g_pTextSprite, pString, -1, &rc, DT_NOCLIP, D3DCOLOR_ARGB( g_nAlpha, g_nRed, g_nGreen, g_nBlue ));
}
int D3DText::getID( void ) {
return m_iID;
}
void D3DText::deleteDevice( void ) {
//dbDeleteDirect3DDevice( m_iID );
}
also a factory file..
D3DFactory.h
#ifndef _D3DFACTORY_H_
#define _D3DFACTORY_H_
class D3DFactory {
public:
D3DFactory( void );
virtual ~D3DFactory( void );
int getNextID( void );
int getCurrentID(void);
static D3DFactory *getInstance( void );
static void deleteInstance( void );
private:
int m_iNextID;
static D3DFactory *m_pInstance;
};
#endif
and D3DFactory.cpp
#include "ObjectFactory.h"
ObjectFactory *ObjectFactory::m_pInstance = 0;
ObjectFactory::ObjectFactory( void ) {
m_iNextID = 0;
}
ObjectFactory::~ObjectFactory( void ) {
}
int ObjectFactory::getNextID( void ) {
return ++m_iNextID;
}
int ObjectFactory::getCurrentID( void ) {
return m_iNextID;
}
ObjectFactory *ObjectFactory::getInstance( void ) {
if( !m_pInstance ) {
m_pInstance = new ObjectFactory( );
}
return m_pInstance;
}
void ObjectFactory::deleteInstance( void ) {
if( !m_pInstance ) {
return;
}
delete m_pInstance;
m_pInstance = 0;
}
The Factory holds the instance of the id, and you could add more IDs in there is you wanted other D3d Calls. Hope this is help full to some one.