Sign in to follow this  

Using ID3DXSprite to set z order for ID3DXFont

This topic is 3570 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 all, I'm trying to get sprites and some text to draw in a correct z order. I've found two posts in the archives, here and here, suggesting using SetTransform on the ID3DXSprite to set the z, then passing it to ID3DXFont. I can't get this to work. Here's the code. mSprite and mFont are the ID3DXSprite and ID3DXFont pointers. Top level rendering function
void HumanGameView::render()
{
	// Clear the back and depth buffers, and send the start signals.
	gDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 0, 255), 1.0f, 0);
	gDevice->BeginScene();
	mSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT);
	gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true);

	// The DevConsole, because of its backdoor nature, is always drawn.
	mDevConsole->draw();

	// End the scene.
	gDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);
	mSprite->End();
	gDevice->EndScene();

	// Present the back buffer.
	gDevice->Present(0, 0, 0, 0);
}

Then, in the dev console, this code draws a texture, at a z-order of 0.5:
void Animation::draw(D3DXVECTOR3 position, int xOffset, int yOffset)
{
	position.x += xOffset; // This is plus-equals, doesn't show up on forum
	position.y += yOffset;

	mFrameCenter.z = position.z;

	mSprite->Draw(mTex, &mFrameRect, &mFrameCenter, &position, mColor);

	mLastPosition = position;
}

And here's where the text is drawn:
void Label::drawText()
{
	D3DXMATRIX original;
	mSprite->GetTransform(&original);

	D3DXMATRIX translation;

	// What Z should go here?
	D3DXMatrixTranslation(&translation, 0.0f, 0.0f, 0.0f);

	mSprite->SetTransform(&translation);

	// Draw the text.
	mFont->DrawText(mSprite, mContent.c_str(), -1, &mArea, DT_VCENTER | DT_LEFT | DT_NOCLIP, mColor);

	mSprite->SetTransform(&original);
}

In drawText(), am I using the D3DXMatrixTranslation() method correctly? What should I put in its z parameter so that the text draws above the sprite at 0.5? No matter what I put there, the text either draws behind the transparent sprite, or is completely blocked by it (the portion of the text not covered by the sprite appears, but the part under even a transparent sprite is not drawn at all).

Share this post


Link to post
Share on other sites

This topic is 3570 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this