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 02-09-2009, 04:52 AM
Alkatraz Alkatraz is offline
Administrator
 
Join Date: Jan 2007
Posts: 72
Default [Coding] - My render class

Credits Monster64
Discussion thread
http://www.uc-forum.com/forum/showthread.php?t=55081


As per request, here is my render class again.

PHP Code:
#ifndef RENDERER_H
#define RENDERER_H
#pragma once

#include "stdafx.h"

#define COL_FRIEND_A(x)      D3DCOLOR_ARGB(x, 61,  141, 227)
#define COL_ENEMY_A(x)       D3DCOLOR_ARGB(x, 255, 0,   0)

#define COL_BLACK                D3DCOLOR_ARGB(255, 0,    0,    0)
#define COL_WHITE               D3DCOLOR_ARGB(255, 255,    255, 255)

#define COL_FRIEND              COL_FRIEND_A(255)
#define COL_ENEMY              COL_ENEMY_A(255)

typedef D3DXMATRIX* (WINAPID3DXMatrixMultiply_t) (
        
D3DXMATRIX*                          pOut,
        CONST 
D3DXMATRIX*              pM1,
        CONST 
D3DXMATRIX*              pM2);

typedef D3DXMATRIX* (WINAPID3DXMatrixTransformation2D_t) (
        
D3DXMATRIX*                          pOut,
        CONST 
D3DXVECTOR2*           pScalingCenter,
        
FLOAT                                      ScalingRotation,
        CONST 
D3DXVECTOR2*           pScaling,
        CONST 
D3DXVECTOR2*           pRotationCenter,
        
FLOAT                                      Rotation,
        CONST 
D3DXVECTOR2*           pTranslation);

class 
CRenderer
{
public:
     
CRenderer();
    ~
CRenderer();

    
void    OnLostDevice();
    
void    OnResetDevice();
    
void    BeginRender();
    
void    EndRender();

    
bool    InitRendering(LPDIRECT3DDEVICE9 pDevice);
    
void    FillRectD3D(int xint yint iWidthint iHeightDWORD dwColor);
    
void    DrawTextD3D(int xint yDWORD dwColorcharszTextDWORD formatbool bEspFont false);
    
void    DrawTextWrapped(int xint yDWORD dwColorcharszTextint iMaxWidth);

    
void    DrawNormalLineD3D(int iStartXint iStartYint iEndXint iEndYDWORD dwColor);
    
void    DrawPolarLineD3D(int iStartXint iStartYfloat flLengthfloat flAngleDWORD dwColor);

    static 
HRESULT    GenerateTexture(IDirect3DDevice9 *pD3DdevIDirect3DTexture9 **ppD3DtexDWORD colour32);
    static 
bool        GetD3DXFunctions();
    static 
HMODULE    FindD3DXModule();

private:
    
LPD3DXFONT                m_pFont;
    
LPD3DXFONT                m_pEspFont;
    
LPD3DXSPRITE             m_pSprite;
    
LPDIRECT3DTEXTURE9 m_pTexWhite;
    
LPDIRECT3DDEVICE9   m_pDevice;
};

#endif 
PHP Code:
#include "stdafx.h"
#include "CRenderer.h"

#pragma warning(disable: 4244)

typedef HRESULT (WINAPID3DXCreateFont_t) (
        
LPDIRECT3DDEVICE9       pDevice,  
        
INT                     Height,
        
UINT                    Width,
        
UINT                    Weight,
        
UINT                    MipLevels,
        
BOOL                    Italic,
        
DWORD                   CharSet,
        
DWORD                   OutputPrecision,
        
DWORD                   Quality,
        
DWORD                   PitchAndFamily,
        
LPCSTR                  pFaceName,
        
LPD3DXFONT*             ppFont);

typedef HRESULT (WINAPID3DXCreateSprite_t) (
        
LPDIRECT3DDEVICE9       pDevice,
        
LPD3DXSPRITE*           ppSprite);

D3DXMatrixMultiply_t            pD3DXMatrixMultiply;
D3DXCreateFont_t                pD3DXCreateFont;
D3DXCreateSprite_t        pD3DXCreateSprite;
D3DXMatrixTransformation2D_t    pD3DXMatrixTransformation2D;

CRenderer::CRenderer()
{
    
m_pFont 0;
    
m_pEspFont 0;
    
m_pSprite 0;
    
m_pTexWhite  0;
}

CRenderer::~CRenderer()
{
    
m_pSprite->Release();
    
m_pFont->Release();
    
m_pEspFont->Release();
}


HRESULT CRenderer::GenerateTexture(IDirect3DDevice9 *pD3DdevIDirect3DTexture9 **ppD3DtexDWORD colour32)
{
    if( 
FAILED(pD3Ddev->CreateTexture(8810D3DFMT_A4R4G4B4D3DPOOL_MANAGEDppD3DtexNULL)) )
        return 
E_FAIL;
    
    
WORD colour16 =    ((WORD)((colour32>>28)&0xF)<<12)
            |(
WORD)(((colour32>>20)&0xF)<<8)
            |(
WORD)(((colour32>>12)&0xF)<<4)
            |(
WORD)(((colour32>>4)&0xF)<<0);

    
D3DLOCKED_RECT d3dlr;    
    (*
ppD3Dtex)->LockRect(0, &d3dlr00);
    
WORD *pDst16 = (WORD*)d3dlr.pBits;

    for(
int xy=0xy 8*8xy++)
        *
pDst16++ = colour16;

    (*
ppD3Dtex)->UnlockRect(0);

    return 
S_OK;
}

HMODULE CRenderer::FindD3DXModule()
{
    
HANDLE hSnap;
    
MODULEENTRY32 xModule;
    
hSnap CreateToolhelp32Snapshot(TH32CS_SNAPMODULEGetCurrentProcessId());
    
xModule.dwSize sizeof(MODULEENTRY32);
    if(
Module32First(hSnap, &xModule))
    {
        while(
Module32Next(hSnap, &xModule))
        {
            if(
strstr(xModule.szModule"d3dx9_"))
            {
                
CloseHandle(hSnap);
                return 
xModule.hModule;
            }
        }
    }
    
CloseHandle(hSnap);
    return 
NULL;
}

bool CRenderer::GetD3DXFunctions()
{
    
HMODULE hMod FindD3DXModule();

    if(!
hMod)
        
hMod LoadLibrary("d3dx9_25.dll");

    
pD3DXCreateFont                = (D3DXCreateFont_t)                GetProcAddress(hMod"D3DXCreateFontA");
    
pD3DXCreateSprite            = (D3DXCreateSprite_t)                GetProcAddress(hMod"D3DXCreateSprite");
    
pD3DXMatrixMultiply            = (D3DXMatrixMultiply_t)            GetProcAddress(hMod"D3DXMatrixMultiply");
    
pD3DXMatrixTransformation2D    = (D3DXMatrixTransformation2D_t)    GetProcAddress(hMod"D3DXMatrixTransformation2D");

    return (
pD3DXCreateFont != 0);
}

bool CRenderer::InitRendering(LPDIRECT3DDEVICE9 pDevice)
{
    
D3DVIEWPORT9 viewPort;

    
m_pDevice pDevice;

    if(
CRenderer::GetD3DXFunctions())
    {
        
CRenderer::GenerateTexture(pDevice, &m_pTexWhiteCOL_WHITE);

        
pD3DXCreateSprite(pDevice, &m_pSprite);
        
pD3DXCreateFont(pDevice1404000FALSEDEFAULT_CHARSETOUT_DEFAULT_PRECISDEFAULT_QUALITYDEFAULT_PITCH FF_DONTCARETEXT("Verdana"), &m_pFont);
        
pD3DXCreateFont(pDevice1204000FALSEDEFAULT_CHARSETOUT_DEFAULT_PRECISDEFAULT_QUALITYDEFAULT_PITCH FF_DONTCARETEXT("Verdana"), &m_pEspFont);

        
pDevice->GetViewport(&viewPort);
        
pGlobals->sScreen.width     viewPort.Width;
        
pGlobals->sScreen.height viewPort.Height;

        return 
true;
    }

    return 
false;
}

void CRenderer::OnLostDevice()
{
    
m_pSprite->OnLostDevice();
    
m_pFont->OnLostDevice();
    
m_pEspFont->OnLostDevice();
}

void CRenderer::OnResetDevice()
{
    
m_pSprite->OnResetDevice();
    
m_pFont->OnResetDevice();
    
m_pEspFont->OnResetDevice();
}

void CRenderer::BeginRender()
{
    
m_pSprite->Begin(D3DXSPRITE_ALPHABLEND);
}

void CRenderer::EndRender()
{
    
m_pSprite->End();
}

void CRenderer::FillRectD3D(int xint yint iWidthint iHeightDWORD dwColor)
{    
    
RECT rct;
    
rct.left    0;
    
rct.top        0;
    
rct.right    iWidth;
    
rct.bottom    iHeight;

    
D3DXVECTOR3 pos;
    
pos.x;
    
pos.y;
    
pos.0;

    
m_pSprite->Draw(m_pTexWhite, &rctNULL, &posdwColor);    
}

void CRenderer::DrawNormalLineD3D(int iStartXint iStartYint iEndXint iEndYDWORD dwColor)
{    
    
float flLength    DistBetweenTwoPoints(iStartXiStartYiEndXiEndY);
    
float flAngle    atan((float)(iEndY iStartY) / (iEndX iStartX));

    
DrawPolarLineD3D(iStartXiStartYflLengthflAngledwColor);
}

void CRenderer::DrawPolarLineD3D(int iStartXint iStartYfloat flLengthfloat flAngleDWORD dwColor)
{    
    
D3DXMATRIX        d3dMatrixd3dOldMatrix;
    
RECT            rct;

    
D3DXVECTOR2        vCenter(iStartXiStartY);
    
D3DXVECTOR3        vPos(iStartXiStartY0);

    
rct.left    0;
    
rct.top        0;
    
rct.right    flLength;
    
rct.bottom    1;

    
pD3DXMatrixTransformation2D(&d3dMatrixNULLNULLNULL, &vCenterflAngleNULL);

    
m_pSprite->GetTransform(&d3dOldMatrix);

    
m_pSprite->SetTransform(&d3dMatrix);
    
m_pSprite->Draw(m_pTexWhite, &rctNULL, &vPosdwColor);

    
m_pSprite->SetTransform(&d3dOldMatrix);
}

void CRenderer::DrawTextD3D(int xint yDWORD dwColorcharszTextDWORD dwFormatbool bEspFont)
{
    
LPD3DXFONT pFont 0;    

    
RECT rct;  
    
rct.left    1;  
    
rct.right    1;  
    
rct.top        ;  
    
rct.bottom    1;
    
dwFormat    |= DT_NOCLIP;

    
pFont bEspFont m_pEspFont m_pFont;

    
pFont->DrawText(m_pSpriteszText, -1, &rctdwFormatdwColor);
}

void CRenderer::DrawTextWrapped(int xint yDWORD dwColorcharszTextint iMaxWidth)
{
    
LPD3DXFONT pFont 0;    

    
RECT rct;  
    
rct.left    1;  
    
rct.right    iMaxWidth;  
    
rct.top        ;  
    
rct.bottom    300;

    
m_pFont->DrawText(m_pSpriteszText, -1, &rctDT_WORDBREAKdwColor);

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
class, coding, render

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:20 AM.