• Advertisement
Sign in to follow this  

image file as background

This topic is 3037 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I use DirectX 9. My problem is: I've got an image file with extension "*.tga" and I want to displaied this image as background of the application. Obviously, the virtual object has to be displaied in front of the background and this is my problem. The image file is loaded as Texture ("D3DXCreateTextureFromFile") and I'm using the Sprite to draw the texture on the screen as background.
        D3DDev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xAABBCCEE, 1.0f, 0);

	// // // set index buffer and vertex declaration: // // //
	hRes = D3DDev->SetIndices(D3DIB);
	if (FAILED(hRes)) return hRes;

	hRes = D3DDev->SetVertexDeclaration(D3DVD);
	if (FAILED(hRes)) return hRes;

	// // // visual rendering: // // //
	hRes = D3DDev->BeginScene();

        // sprite:
	D3DSprite->Begin(NULL);
		D3DSprite->Draw(D3DT9TextureBackground, NULL, NULL, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
	D3DSprite->End();

        // 3D object:
	unsigned int Passes;
	D3DEffect->Begin(&Passes, 0);
	for (unsigned int i = 0; i < Passes; i++)
	{
   	        D3DEffect->BeginPass(i);
		hRes = D3DMesh->DrawSubset(0);
		D3DEffect->EndPass();
	} // for (unsigned int i = 0; i < Passes; i++)
	D3DEffect->End();

	D3DDev->EndScene();
        D3DDev->Present(NULL, NULL, NULL, NULL);


where: - D3DDev is the D3D device - D3DEffect is the effect - D3DSprite is the sprite The problem could be the transparency ? that is just supported by the format file ("*.tga").

Share this post


Link to post
Share on other sites
Advertisement
A sprite is always on top of 3D geometry.

You could disable Z-writes, that should work. Add this line after the D3DSprite->Begin(NULL); line:
D3DDev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
A sprite is always on top of 3D geometry.

You could disable Z-writes, that should work. Add this line after the D3DSprite->Begin(NULL); line:
D3DDev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);


And then I re-set as "true" the value of "D3DRS_ZWRITEENABLE" (because i use "D3DRS_ZWRITEENABLE" in my code as "true"):



D3DSprite->Begin(NULL);
D3DDev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
D3DSprite->Draw(D3DT9TextureBackground, NULL, NULL, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
D3DSprite->End();

D3DDev->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
// here is the cycle of the 3D object for the visual rendering



Is right in this way ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Claudio
Quote:
Original post by Evil Steve
A sprite is always on top of 3D geometry.

You could disable Z-writes, that should work. Add this line after the D3DSprite->Begin(NULL); line:
D3DDev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);


And then I re-set as "true" the value of "D3DRS_ZWRITEENABLE" (because i use "D3DRS_ZWRITEENABLE" in my code as "true"):

*** Source Snippet Removed ***

Is right in this way ?
Yes. I don't think you need to set the value back to TRUE, since D3DSprite->End() will do that (Although I'm not 100% sure about that).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement