Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


hyspanux

Member Since 25 Jun 2012
Offline Last Active Jun 25 2012 09:23 AM

Topics I've Started

D3DXSprite render order doesn´t work

25 June 2012 - 02:44 AM

Hi all

I need your help. I´m writting a graphics engine and now I want to use Font system with ID3XFont.
This engine don´t have z-order and all objects are drawn at render order.
All works fine but now when I use ID3DXfont, text are drawn on top of all objects and I cant understand why.

All Objects has a matworld and are render as

void Object::RenderChild(D3DXMATRIX matWorld)
{
for(std::list<Object*>::iterator it = vctChild.begin(); it != vctChild.end(); it++)
{
Object *tmp = *it;
tmp->matWorld = matWorld;
tmp->Draw();
}
}

And calculate world transform with

void Object::gfPushMatrix()
{
vectEsc.x = Scale.X; vectEsc.y = Scale.Y; vectEsc.z = Scale.Z;
vectPos.x = (float)((int)Position.X); vectPos.y = (float)((int)Position.Y);
vectPos.z = 0;

vectRotCent.x = rotCenterPoint.X; vectRotCent.y = rotCenterPoint.Y; vectRotCent.z = rotCenterPoint.Z;
D3DXMATRIX mtxTmp;
D3DXMatrixRotationX(&Rx,D3DXToRadian(Rotation.X));
D3DXMatrixRotationY(&Ry,D3DXToRadian(Rotation.Y));
D3DXMatrixRotationZ(&Rz,D3DXToRadian(Rotation.Z));

mtxRot = Rx * Ry * Rz;
quatRot = D3DXQUATERNION();
D3DXQuaternionRotationMatrix(&quatRot, &mtxRot);
D3DXMatrixTransformation(&mtxTmp, NULL, NULL, &vectEsc, &vectRotCent, &quatRot, &vectPos);
matWorld = mtxTmp*matWorld;
GraphicsDevice_->SetTransform( D3DTS_WORLD, &matWorld); // GraphicsDevice is LPDIRECT3DDEVICE9
}

Any object do Draw as

void AnyObject::Draw()
{
gfPushMatrix();
[ Calculate position, alpha, texture clip, ...
and draw texture with LPDIRECT3DDEVICE9->DrawPrimitiveUP(...) ]
}

And my TextObject draw text in a D3DXSprite with a D3DXFont as
void TextTTF::Draw()
{
gfPushMatrix();
pTextSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE);
pTextSprite->SetTransform(&matWorld);
font->drawText(pTextSprite, text, 0,0,Color, Alignment);
pTextSprite->End();
}

I draw a background, then a text object and the many other objects which should be over the text
but the result is that text are drawn over all objects.

Any idea?
Thanks in advance

PARTNERS