Jump to content
  • Advertisement
Sign in to follow this  
Sol Blue

Using ID3DXSprite to set z order for ID3DXFont

This topic is 3936 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->SetRenderState(D3DRS_ALPHATESTENABLE, true);

	// The DevConsole, because of its backdoor nature, is always drawn.

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

	// 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;

	D3DXMATRIX translation;

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


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


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!