Hey, it seems when I try to draw textures using the Z value in the D3DXVECTOR, it doesn't affect the drawing outcome. For example, I draw a red ball, then a blue ball on top of the red ball,
where the red ball has a depth value of 0.1f and
the blue ball has a depth value of 0.2f,
and still the blue ball appears on top of the red ball.

I should probably mention that I've managed to get this to work before, so I've seen it working before!

Now, I'll apply the code I'm using and hopefully someone will see the faulty programming.

Alright, first up is the Direct3D.cpp file
This takes care of the begin drawing and end drawing of the sprite.
Shouldn't affect the result...

void StartRender()
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    d3ddev->BeginScene();
	d3dspt->Begin(D3DXSPRITE_ALPHABLEND);
    return;
}

// Stop rendering
void EndRender()
{	
	d3dspt->End();
    d3ddev->EndScene();
    d3ddev->Present(NULL, NULL, NULL, NULL);
	
    return;
}

void LoadTexture(LPDIRECT3DTEXTURE9* texture, LPCTSTR filename)
{
	D3DXCreateTextureFromFileEx(d3ddev, filename,
								D3DX_DEFAULT,
								D3DX_DEFAULT,
								D3DX_DEFAULT,
								NULL,
								D3DFMT_A8R8G8B8,
								D3DPOOL_MANAGED,
								D3DX_DEFAULT,
								D3DX_DEFAULT,
								D3DCOLOR_XRGB(255,0,255),
								NULL,
								NULL,
								texture);
    return;
}

void DrawTexture(LPDIRECT3DTEXTURE9 texture, RECT drawingrect, D3DXVECTOR3 position, D3DCOLOR color)
{	
	 d3dspt->Draw(texture, &drawingrect, NULL, &position, color);
	return;
}

Next up is the Render.cpp file

LPDIRECT3DTEXTURE9 redball, blueball;

void LoadGraphics()
{
	LoadTexture(&redball, "whiteball.png");
	LoadTexture(&blueball, "whiteball.png");
	return;
}

void Render()
{
    StartRender();
	RECT rb, bb;
	SetRect(&rb, 0,0,128,128);
	SetRect(&bb, 0,0,128,128);
	D3DXVECTOR3 redballpos(0.0f, 0.0f, 0.1f), blueballpos(0.0f, 0.0f, 0.2f);
	DrawTexture(redball, rb, redballpos, D3DCOLOR_XRGB(255,0,0));
	DrawTexture(blueball, bb, blueballpos, D3DCOLOR_XRGB(0,0,255));
	EndRender();

    return;
}

As I explained in the beginning, the blue ball is still drawn on top of the red ball even though it has a greater depth than the red ball.

What am I missing?

I really want to solve this problem, 'cause otherwise I'd have to resort to manual draw sequencing, and I suspect that requires extra processing...

Just for craps and chuckles, have you tried using -0.2f? It's been a while since I've worked in 3D, so I'm not 100% on which coordinate system DX uses.

No it did not. However the ball with the negative z value disappeared...
Any other approach?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.