Game UI Design (1.2) - TEXTURES & SPRITE package

xiaoxiao2021-03-06  63

1.2 Textures & Sprite Package CXTexture & CxSprite

[http://blog.9cbs.net/mythma]

1, what is Textures

Textures is a flat graphic displayed on the screen that provides more graphics processing than Surface - moving, scaling, rotating, and as a texture skin attached to a 3D model. In Direct3D, its packaged interface is iDirect3dtexture9.

2, what is Sprite

IDirect3dTexture9 can read texture data from the file, but because Textures cannot copy directly to the Back Buffer, you need another interface-ID3dxsprite (wizard) before drawing Textures on the screen. ID3DXSPRITE can copy several TeXTures to the Back Buffer, so an instance of Id3DxSprite can draw all the textures.

Therefore, idirect3dtexture9 is used to store the textures required for the program, but it itself cannot draw textures and needs to use interface ID3dxSprite.

3, the use of IDirect3dtexture9 and id3dxsprite

Definition: ~

Create: d3dxcreatetextureFromfile

D3DXCREATESPRITE

Create a transformation matrix: D3DXMAMATRIXTRANSFORMATION2D

Transform: SetTransform

Drawing image: draw

Release memory: ~

code show as below:

D3DXCREATEXTUREFROMFILE (g_pd3ddevice, "c: //image.bmp", & g_texture);

D3DXCREATESPRITE (G_PD3DDEvice, & g_sprite);

/ / -------------------------------------------------------------------------------------------- ----------------------------

D3DXVECTOR2 Translation;

Translation.x = 500;

Translation.y = 500;

D3DXVECTOR2 Scaling;

Scaling.x = 1.0; f

Scaling.y = 1.0F;

D3DXMAMATRIX MAT;

D3DXMatrixTransformation2D (& Mat, Null, 0, & Scaling, Null, 0, &) & scaling, NULL, 0, &

Translation;

g_sprite-> begin (0);

g_sprite-> settransform (&)

g_sprite-> draw (g_texture,

g_sprite-> end ();

4, how to package

From the above basic procedure, it can be seen that CXTexture needs to be completed: provide interfaces with LPDirect3DDevice9, associated with the texture file file, processes textures (zoom, rotate ...).

Class CXTexture

{

protected:

LPDIRECT3DTEXTURE9 M_TEXTURE;

LPDIRECT3DDEVICE9 M_PDEVICE;

D3DXVECTOR2 M_ROTATIONCENTER;

D3DXVECTOR2 M_TRANSLATION;

D3DXVECTOR2 M_SCALING;

Float M_Rotation;

Rect m_srcRect; public:

CXTexture (LPDIRECT3DDEVICE9 PDEVICE);

~ Cxtexture ();

LPDIRECT3DTEXTURE9 getTexture () const {return m_texture;}

Void SetTexture (LPDIRECT3DTEXTURE9 TEXTURE) Const {m_texture = texture;}

LPDIRECT3DDEVICE9 getDevice () const {return m_pdevice;}

Void setDevice (lpdirect3ddevice9 pdevice) const {m_pdevice = pdevice;

D3DXVECTOR2 GEROTATIONCENTER () Const {Return M_Rotationcenter;

Void Strotationcenter (D3DxVector2 RotationCenter) {m_rotationcenter =

Rotationcenter;

D3DXVECTOR2 GETTRANSLATION () const {return m_translation;}

Void SetTranslation (D3DXVector2 Translation) const {m_translation =

TRANSLATION;

D3DXVECTOR2 getscaling () const {return m_scaling;

Void setscaling (d3dxvector2 scaling) const {m_scaling = scale;}

Float getrotation () const {return m_Rotation;}

Void Strotation (Float Rotation) const {m_rotation = rotation;

Rect getRect () const {return m_srcRect;

Void setRect (Rect srcRect) const {m_srcrect = srcRect;}

HRESULT LOADFROMFILE (CHAR * PATH);

}

The main function of CxSprite is to display CXTexture on the screen, so there is a function of connecting to the LPDirect3DDevice9 interface and CXTexture.

Class CxSprite

{

protected:

LPD3DXSPRITE M_SPRITE;

LPDIRECT3DDEVICE9 M_PDEVICE;

PUBLIC:

CXSPRITE (LPDirect3DDevice9 PDEvice);

~ Cxsprite ();

LPD3DXSPRITE GETSPRITE () Const {Return M_Sprite;}

Void setsprite (lpd3dxsprite sprite) const {m_sprite = sprite;}

LPDIRECT3DDEVICE9 getDevice () const {return m_pdevice;}

Void setDevice (lpdirect3ddevice9 pdevice) const {m_pdevice = pdevice;

HRESULT DRAWTEXTURE (CXTexture * Texture);

}

转载请注明原文地址:https://www.9cbs.com/read-110929.html

New Post(0)