unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Programming > Direct3D

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 12-24-2006, 07:26 AM
zero_tolerance zero_tolerance is offline
Senior Member
 
Join Date: Dec 2006
Posts: 289
Default [D3D] Black Bordered Text

By Darkcode

You will need to have this in the top of your file:

Code:
#include "D3DFontEngine.h"

extern CFontEngine  *pFont;
Here is the main D3DFontEngine.cpp:

Code:
//
// D3DFontEngine.cpp


#include "D3DFontEngine.h"
#include "D3D9Dev.h"
#include "main.h"


HRESULT CFontEngine::Initialize( D3DXFONT_DESC dDesc, D3DCOLOR FontColor )
{
	if( m_pFont )
	{
		SAFE_RELEASE( m_pFont )
	}

	D3DXCreateFontIndirect( m_D3Ddev, &dDesc, &m_pFont );
	
	m_FontColor = FontColor;
	
	m_bInitialized = TRUE;

	return S_OK;
}

HRESULT CFontEngine::DrawText( char *pString, int x, int y )
{
	if( !m_bInitialized )
		return E_FAIL;

	HRESULT hRetVal;

	RECT FontRect = { x, y, 0, 0 };

	m_pFont->DrawTextA( NULL, pString, -1, &FontRect, DT_CALCRECT, 0 );
	hRetVal = m_pFont->DrawTextA( NULL, pString, -1, &FontRect, m_Align, m_FontColor );

	return hRetVal;
}
HRESULT CFontEngine::CleanUpFontStuff( )
{
	SAFE_RELEASE( m_pFont )
	m_bInitialized = FALSE;

	return S_OK;
}
void CFontEngine::InitDesc()
{
	pDesc.Height			= 16;
	pDesc.Width				= 0;
	pDesc.Weight			= FW_BOLD;
	pDesc.MipLevels			= 1;
	pDesc.Italic			= TRUE;
	pDesc.CharSet			= DEFAULT_CHARSET;
	pDesc.OutputPrecision	= OUT_DEFAULT_PRECIS;
	pDesc.Quality			= ANTIALIASED_QUALITY;
	pDesc.PitchAndFamily	= DEFAULT_PITCH | FF_DONTCARE;
	strcpy( pDesc.FaceName, "Arial" );
	Initialize( pDesc, D3DCOLOR_XRGB( 255, 255, 255 ) );
}
And when you look inside D3DFontEngine.h there is this (just incase you don't got it):

Code:
//
// D3DFontEngine.h

#ifndef _D3DFONTENGINE_H
#define _D3DFONTENGINE_H

#include "main.h"
#include "d3d9.h"



class CFontEngine 
{
public:
	CFontEngine(IDirect3DDevice9 *pIDirect3DDevice9)
	{
		m_pFont			= 0;
		m_FontColor		= D3DCOLOR_XRGB( 255, 255, 255 );
		m_bInitialized	= FALSE;
		m_Align			= DT_LEFT | DT_WORDBREAK;
		m_D3Ddev		= pIDirect3DDevice9;
	};
	~CFontEngine( )
	{
		if( m_pFont )
		{
			SAFE_RELEASE( m_pFont )
		}
	};

	HRESULT Initialize( D3DXFONT_DESC dDesc, D3DCOLOR FontColor );
	HRESULT DrawText( char *pString, int x, int y );
	HRESULT CleanUpFontStuff();
	void	InitDesc(void);
	
	D3DXFONT_DESC	pDesc;
	D3DCOLOR		m_FontColor;
	int				m_Align;
	LPD3DXFONT		m_pFont;
	RECT			m_FontRect;
	BOOL			m_bInitialized;

private:
	IDirect3DDevice9 *m_D3Ddev;
};

#endif //_D3DFONTENGINE_H
And you can tell these 2 things from it for drawing text...

Color:

Code:
pFont->m_FontColor = D3DCOLOR_XRGB( int r, int b, int g);
And then drawing text:

Code:
pFont->DrawText(char *pString, int x, int y);
So once you got that in mind, lets make our black bordered text:

Code:
void MyDrawText ( int x, int y, char Text, int r, int b, int g)
{
	pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
	pFont->DrawText(char Text, x, y - 1);
	pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
	pFont->DrawText(char Text, x, y + 1);
	pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
	pFont->DrawText(char Text, x - 1, y);
	pFont->m_FontColor = D3DCOLOR_XRGB( 0, 0, 0 );
	pFont->DrawText(char Text, x + 1, y);
	pFont->m_FontColor = D3DCOLOR_XRGB( r, g, b );
	pFont->DrawText(char Text, x, y);
}
And to call upon it, heres an example:

Code:
MyDrawText( 10, 65, D3D Tutorial, 255, 255, 255);
Which would yield white text with a black border, and placed at 10, 65.

Enjoy
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
black, bordered, d3d, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 06:43 AM.