DX9 Dynamic Texture problems

Started by
0 comments, last by S1CA 19 years, 6 months ago
Hello, I have a problem setting up a Dynamic texture using DX9. The following is the code related to this problem:

// Setup Dynamic texture m_pOverlayTx
if (!m_pD3DDevice) return false;
if (!m_pOverlayTx) m_pD3DDevice->CreateTexture(256, 256, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pOverlayTx, NULL);
if (!map) return false;

D3DLOCKED_RECT  r;
m_pOverlayTx->LockRect(0, &r, NULL, D3DLOCK_DISCARD | D3DLOCK_NO_DIRTY_UPDATE);

D3DCOLOR* otxbits = (D3DCOLOR*)r.pBits;
for (UINT y = 0; y < 256; y++) 
	for (UINT x = 0; x < 256; x++) 
		// both otxbits and map point to D3DCOLOR[256*256], memcpy would work if pitch/4 is 256
		otxbits[(x*r.pitch/4) + y)] = map[x*256 + y];
	
m_pOverlayTx->UnlockRect(0);

// Render the image.
// m_pVertexBuffer contains 4 vertices to draw a quad.
if (!m_pVertexBuffer || !m_pTerrainTx || !m_pD3DDevice) return false;

// Texture Stage States are already set by previous routines.
m_pD3DDevice->SetTexture( 0, m_pTerrainTx ));

if (m_pOverlayTx) {
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_BLENDTEXTUREALPHA );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	m_pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAARG2, D3DTA_CURRENT ));

	m_pD3DDevice->SetTexture( 1, m_pOverlayTx );
}
m_pD3DDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(HudVertex)));
m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,  0, 2);

m_pD3DDevice->SetTexture( 0, NULL );
m_pD3DDevice->SetTexture( 1, NULL );
m_pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );

When I execute this code I either do not get the intended output (only m_pTerrainTx renders, not a blend of m_pTerrainTx and m_pOverlayTx) or I get the blue screen of death. Any help would be greatly accepted. Thankyou
Advertisement
1) Does your graphics hardware actually support dynamic textures?
Check for D3DCAPS2_DYNAMICTEXTURES.

2) Does your graphics hardware support D3DFMT_A8R8G8B8 dynamic textures with your current display mode and settings ?
Check with IDirect3D9::CheckDeviceFormat().

3) What does the DEBUG Direct3D runtime say with the debug output level set to high ?

4) If the DEBUG Direct3D runtime isn't saying anything, did you use D3DCREATE_PUREDEVICE ?. If so try removing it and see if the runtime does have anything to say.

5) Blue Screen Of Death can indicate broken display driver (try using a WHQL certified one) and/or hideous abuse of the API.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement