💬 Texture Mapping [DrawTexBox()]
TEXTURE MAPPING
Credit:
- Topblast
- mmbob
- Topblast
- mmbob
Well i am posting this because most of you do not know what sprites are and how to use them. Texture mapping is Fitting a texture around a Primitive like a rectangle , triangle and so on. Also an other reason is am doing this because most of you are having problems with sprites and fitting it to your menu like if you want it to be 100 wide and 200 long. You cant do that as well.

this is acid burn's color picker as u can see i can edit the size of it in any way as well in the next image.

This is a menu i made Paint .
Credit:
- Topblast
- mmbob
- Topblast
- mmbob
Code:
void DrawTexBox( __in LPDIRECT3DDEVICE9 pDevice, __in LPDIRECT3DTEXTURE9 pTexture, __in int x, __in int y, __in int w, __in int h); Parameters pDevice [in] LPDIRECT3DDEVICE9 Pointer to an IDirect3DDevice9 interface, the device to be associated with the drawing of the object. pTexture [in] LPDIRECT3DTEXTURE9 Pointer to an LPDIRECT3DTEXTURE9 interface, the texture that will be mapped around the primitive. X [in] INT Specifies the x-coordinate of the rectangle''s upper-left corner. Y [in] INT Specifies the y-coordinate of the rectangle''s upper-left corner. W (Weight) [in] INT The width of the Square in logical units. H (Height) [in] INT The height of the Square in logical units.
Credit:
- Topblast
- mmbob
- Topblast
- mmbob
Code:
void DrawTexBox(LPDIRECT3DDEVICE9 pDevice,
LPDIRECT3DTEXTURE9 pTexture,
int x,
int y,
int w,
int h)
{
struct tVertex
{
float X, Y, Z, RHW;
float IU, IV;
enum FVF
{
FVF_Flags = (D3DFVF_XYZRHW | D3DFVF_TEX1)
};
};
tVertex Veri[4] =
{
{(float)x ,(float)y , 0.0f, 1.0f, 0.0f, 0.0f },
{(float)(x+w) ,(float)y , 0.0f, 1.0f, 1.0f, 0.0f },
{(float)x ,(float)(y+h) , 0.0f, 1.0f, 0.0f, 1.0f },
{(float)(x+w) ,(float)(y+h) , 0.0f, 1.0f, 1.0f, 1.0f },
};
pDevice->SetTexture( 0, pTexture );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
////////////////////////////////////
pDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
pDevice->SetRenderState( D3DRS_FOGENABLE, false );
pDevice->SetFVF( tVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof(tVertex));
}


