Skip to main content
GameDev.net gamedev.net
🔒 Locked

Animating texture

Started by streamer Jan 30, 2006 at 5:44 PM 1 replies 1k views
Original Post
streamer
streamer
Hello Well I have a liitle problem with DX9 in dx8 i do this stuff to animate a texture:

static float offset = 0.0f;
	offset+=0.0001f;
	if(offset >1.0f) offset = 0.0f;

	D3DXMATRIX mat;
	D3DXMatrixIdentity(&mat);

	m_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);

	mat._31=offset;
	mat._32=offset;

	m_pd3dDevice->SetTransform( D3DTS_TEXTURE0, &mat );
	BlitRect(m_pd3dDevice,mytexture , 0x2fffffff);



in dx9 I tried this but this doesn't work:

static float offset = 0.0f;
	offset+=0.0001f;
	if(offset >1.0f) offset = 0.0f;

	D3DXMATRIX mat;
	D3DXMatrixIdentity(&mat);

	g_pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
	//g_pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
	//g_pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);

	g_pd3dDevice->SetRenderState(D3DRS_WRAP1, D3DWRAPCOORD_0);
	g_pd3dDevice->SetRenderState(D3DRS_WRAP1, D3DWRAPCOORD_1);


	mat._31=offset;
	mat._32=offset;

	g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, &mat );
	BlitRect(g_pd3dDevice,mytexture, 0x2fffffff);



what is the problem? and BlitRect procedure is:

typedef struct _D3DTLVERTEX {
    float sx; /* Screen coordinates */
    float sy;
    float sz;
    
    D3DCOLOR color; /* Vertex color */
    float tu; /* Texture coordinates */
    float tv;
    _D3DTLVERTEX() { }
    _D3DTLVERTEX(const D3DVECTOR& v, 
                 D3DCOLOR _color, 
                 float _tu, float _tv)
    { sx = v.x; sy = v.y; sz = v.z; 
      color = _color; 
      tu = _tu; tv = _tv;
    }
} D3DTLVERTEX, *LPD3DTLVERTEX;
 
#define D3DFVF_TLVERTEX D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1
void BlitRect(LPDIRECT3DDEVICE9 lpDevice,
			  LPDIRECT3DTEXTURE9 lpSrc,
              D3DCOLOR col)
{
    float z = 1.0f;

    // set up rectangle

    D3DTLVERTEX verts[4];

    verts[0]=D3DTLVERTEX(D3DXVECTOR3(0,0,  z),col,0.0f,0.0f); 
    verts[2]=D3DTLVERTEX(D3DXVECTOR3(800,600,  z),col,1.0f,1.0f); 
    verts[1]=D3DTLVERTEX(D3DXVECTOR3(800,0, z),col,1.0f,0.0f);
    verts[3]=D3DTLVERTEX(D3DXVECTOR3(0,600, z),col,0.0f,1.0f);
    // set the texture
    lpDevice->SetTexture(0,lpSrc);

    // configure shader for vertex type
	lpDevice->SetFVF(D3DFVF_TLVERTEX);

    // draw the rectangle
    lpDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,2,verts,sizeof(D3DTLVERTEX));
}



Thanx in advance,
Promit
Promit
Quote:
Original post by streamer
what is the problem?
Well, you tell us. When "it doesn't work", what exactly happens?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
streamer
streamer
Quote:
Original post by Promit
Quote:
Original post by streamer
what is the problem?
Well, you tell us. When "it doesn't work", what exactly happens?


[smile] I'm sorry. The original code from DirectX8 slowly animates texture coordinates inside a 2D rectangle. But when I ported the code to DirectX9 nothing happens. Texture is there, but it wont animate.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.