Navigation
Artikel
Stuff
RSS Feeds
|
Sourcecodes - DirectX Text mit ID3DXFONTSprachenübersicht/C / C++/ C#/Spieleprogrammierung/DirectX Keywords: ID3DXFONT, LPD3DXFONT, Schrift mit DirectX Der folgende Code beschreibt die benutzung von ID3DXFONT:
Code: #pragma once //Header #include <d3d9.h> //File for DirectXGraphics #include <d3dx9.h> //Filfe for DirectXGraphics #include <cstdio> //Standard I/O header //Defines #define DLLEXPORT __declspec(dllexport) //Font informations struct bn_FontInformations { //Width of the font int iWidth; //Weight of the font int iWeight; //Height of the font int iHeight; //Specifies the character set for example: TURKISH_CHARSET;DEFAULT_CHARSET int iCharSet; //Specifies the pitch and family of the font FF_DECORATIVE;FF_DONTCARE;FF_MODERN int iPitchAndFamily; //Tests if it's italic bool bItalic; //The name of the font char *pFontName; }; //Class for the font class bn_Font { public: //Initialise DirectXGraphics bn_Font(); //Desturktor clears the class ~bn_Font(); //Initialise DirectXGraphics void Initialise(LPDIRECT3DDEVICE9 lpD3DDevice,bn_FontInformations FontInfo); //Draws the Text void DrawText(char *pText,int iX,int iY,int iWidth = 0,int iHeight = 0,D3DCOLOR TextColor = D3DCOLOR_XRGB(0xFF,0xFF,0)); //If the device'll be reseted void OnLostDevice(); //If the device has been reseted void OnResetDevice(); protected: //The font LPD3DXFONT m_lpD3DFont; //If it's initialised bool m_bInitialise; };
Code: //******************************* FOR MORE SEE THE .h file ********************************// #include "font.h" //Copy src to dest for size chars inline void CopyPointingString(char *pTarget,char *pSource,int size) { for(int i=0; i<size; i++) { if (i == size-1) pTarget[i]='\0'; else pTarget[i]=pSource[i]; } } //Initialise DirectXGraphics bn_Font::bn_Font() { //Sets it 0 m_lpD3DFont = NULL; m_bInitialise = false; } //If the device'll be reseted void bn_Font::OnLostDevice() { m_lpD3DFont->OnLostDevice(); } //If the device has been reseted void bn_Font::OnResetDevice() { m_lpD3DFont->OnResetDevice(); } //Initialise DirectXGraphics void bn_Font::Initialise(LPDIRECT3DDEVICE9 lpD3DDevice,bn_FontInformations FontInfo) { D3DXFONT_DESC FontDesc; if (FontInfo.pFontName) CopyPointingString(FontDesc.FaceName,FontInfo.pFontName,sizeof(FontInfo.pFontName)); //Sets the informations FontDesc.Weight = FontInfo.iWeight; FontDesc.Width = FontInfo.iWidth; FontDesc.Height = FontInfo.iHeight; FontDesc.CharSet = FontInfo.iCharSet; FontDesc.PitchAndFamily = FontInfo.iPitchAndFamily; FontDesc.Italic = FontInfo.bItalic; FontDesc.MipLevels = 1; //Creates the font D3DXCreateFontIndirect(lpD3DDevice,&FontDesc,&m_lpD3DFont); m_bInitialise = true; } //Destructor clears the class bn_Font::~bn_Font() { //Clean if (NULL != m_lpD3DFont) { m_lpD3DFont->Release(); m_lpD3DFont = NULL; } } //Draws the Text void bn_Font::DrawText(char *pText,int iX,int iY,int iWidth,int iHeight,D3DCOLOR TextColor) { //Draws it if (m_bInitialise) { //Creates a buffer char strBuffer[255]; sprintf(strBuffer,"%s",pText); RECT r = {iX,iY,iWidth,iHeight}; //Sets the size if (iWidth == 0 || iHeight == 0) m_lpD3DFont->DrawText(NULL,strBuffer,-1,&r,DT_CALCRECT,TextColor); //Gives it out m_lpD3DFont->DrawText(NULL,strBuffer,-1,&r,DT_CENTER,TextColor); } } Gibt es noch irgendwelche Fragen, oder wollen Sie über den Artikel diskutieren? Sprachenübersicht/C / C++/ C#/Spieleprogrammierung/DirectX/DirectX Text mit ID3DXFONT |