D3DXSprite and DirectX 8

D3DXSprite and DirectX 8

Post by core » Wed, 20 Mar 2002 10:16:46



I am using D3DXSprite's to draw textures to the screen. I am also
using D3DXMESH to draw mesh's to the screen. The problem is I can not
get the Sprites to be drawn as a background for the mesh.
If I do this

sprite.render();
mesh.render();

The entire 50 pixel by 50 pixel sprite is drawn to the screen, even
over the mesh.
if I do this

mesh.render();
sprite.render();

The 50 pixel by 50 pixel sprite is correctly drawn (but with alpha
blending enabled) to the screen over the mesh.

How can I draw the sprites behind the 3D Objects?

Thanks...

//Code sample for sprite render
D3DXCreateSprite(m_pd3dDevice, &testSprite);
testSprite->Begin();
for (int i=128; i<300; i+=5){
testSprite->Draw( m_pTexture, &rectangle, &m_Scaling, &m_RotCenter,
                  m_Rotation, &trans, m_ModulateColor );
testSprite->End();

//Code sample for mesh render
for( int i = 0 ; i < m_NumMats ; i++ )
{
// Set this material as active
pMaterials[i].Update();
// Set this texture as active
Direct3dDevice->SetTexture( 0, pTextures[i] );
// Render this subset of the mesh
testMesh->DrawSubset(i);
// Reset the vertex shader
Direct3dDevice->SetVertexShader( VERTEX_TYPE );

Quote:}

 
 
 

D3DXSprite and DirectX 8

Post by Rich [Microsoft Direct3D MV » Wed, 20 Mar 2002 11:15:51


[Please do not mail me a copy of your followup]



Quote:>I am using D3DXSprite's to draw textures to the screen. I am also
>using D3DXMESH to draw mesh's to the screen. The problem is I can not
>get the Sprites to be drawn as a background for the mesh.

Things to investigate:
- debug runtime installed?
- linked with debug D3DX?
- all HRESULTs checked?
- debug level turned up?
- no interesting messages in the debug output?
- do you have a Z buffer? (D3DPRESENT_PARAMETERS)
- are you clearing the Z buffer? (D3DCLEAR_ZBUFFER)
- what are the Z buffer render states?
    (RS Z Enable, RS Z Write Enable, RS Z Func)
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book http://www.xmission.com/~legalize/book/
    izfree: Open source tools for Windows Installer
            http://izfree.sourceforge.net

 
 
 

D3DXSprite and DirectX 8

Post by core » Thu, 21 Mar 2002 06:29:08


I figured out that it has something to do with the ZBUFFER because
when I disable it with
g_pDevice->SetRenderState( D3DRS_ZENABLE, FALSE);
I get the correct behavior.

But I don't think this is the correct solution to the problem.

 
 
 

D3DXSprite and DirectX 8

Post by Eyal Tele » Tue, 26 Mar 2002 19:46:24


Quote:> I figured out that it has something to do with the ZBUFFER because
> when I disable it with
> g_pDevice->SetRenderState( D3DRS_ZENABLE, FALSE);
> I get the correct behavior.

> But I don't think this is the correct solution to the problem.

Actually, it sounds right. While I haven't worked with the sprite
class yet (tried to, but decided not to spend time right now replacing
already working code), it makes sense that it'd draw things in the
foreground. I don't see any way to set the depth in the draw call. So
I think that you should disable Z writing (using the
D3DRS_ZWRI*ABLE render state) when drawing the sprite, which should
make the draw order determine what you see of it.

        Eyal

 
 
 

1. Colorkey in D3DXSprite

Is there a way to display an image using a colorkey with
the ID3DXSprite interface? I know about the
D3DXLoadTextureFromFile. I mean, is there a function to
make the pixels with specific colors of a texture or
surface transparent?

Thank you,
Marek Dzikiewicz

2. Bad Graphics

3. D3DXSprite - fixed yet?

4. Splitting TIFF Images

5. D3DXSprite

6. JIF image file???

7. Question about D3DXSPRITE interface

8. questions about lightwave 3d

9. D3DXSPRITE and viewport again,...

10. Clipping Rotated Sprites with D3DXSprite

11. Pixel Ploting with D3DXSprite

12. D3DXSPRITE Is one good enough?

13. D3DXSPRITE size problem