Rendering silently failing with ID3DXSprite and ID3DXFont

Started by
-1 comments, last by DeadMG 13 years, 3 months ago
I'm having some problems with ID3DXSprite and ID3DXFont where text will silently fail to render.

When two fonts are created, even when they are identical, rendering from the second font will silently fail. I'm running with Direct3D in full debug mode and it doesn't report any errors or warnings and I'm using a macro to check the return values of all Direct3D functions. The first font still works correctly (at least, notwithstanding the second issue). If the first font's creation is commented out, the second font will work correctly. I have fully re-entrant code, no global variables.
When I render more than one texture to the sprite, rendering will silently fail. This is most obvious because I have some animated buttons where the texture will change when moused over. Both textures are created beforehand. When mousing over, the texture changes and the text disappears. When the mouse leaves the button, the previous texture and the text re-appear. This is also completely silent from the Direct3D runtime.

I initially thought that it must be a problem with my use of ID3DXFont but when the second problem manifested, I'm looking more at ID3DXSprite. This is my main rendering code (the parts that relate to ID3DXSprite).

D3DCALL(D3DSprite->Begin(
D3DXSPRITE_ALPHABLEND |
D3DXSPRITE_DO_NOT_ADDREF_TEXTURE |
D3DXSPRITE_SORT_DEPTH_BACKTOFRONT |
D3DXSPRITE_SORT_TEXTURE
));
decltype(GetPtrs<D3D9Sprite>()) sprites = GetPtrs<D3D9Sprite>();
std::for_each(sprites.begin(), sprites.end(), [&, this](D3D9Sprite* sprite) {
//D3DXVECTOR3 spritepos = sprite->position + sprite->center;
if (!sprite->Visible())
return;
D3DCALL(D3DSprite->Draw(
sprite->owner->D3DTexture.get(),
nullptr,
&sprite->center,
&sprite->position,
0xFFFFFFFF
));
});
decltype(GetPtrs<D3D9Text>()) texts = GetPtrs<D3D9Text>();
std::for_each(texts.begin(), texts.end(), [&, this](D3D9Text* ptr) {
if (!ptr->Visible())
return;
RECT textbox = {0};
unsigned int format = 0;
textbox.top = ptr->PositionY();
textbox.left = ptr->PositionX();
textbox.bottom = textbox.top + ptr->SizeY();
textbox.right = textbox.left + ptr->SizeX();
D3DCALL(ptr->owner->D3DXFont->DrawTextW(
D3DSprite.get(),
ptr->Text().c_str(),
ptr->Text().size(),
&textbox,
format,
ptr->Colour()
));
});
decltype(GetPtrs<D3D9Button>()) buttons = GetPtrs<D3D9Button>();
std::for_each(buttons.begin(), buttons.end(), [&, this](D3D9Button* button) {
if (!button->Visible())
return;
D3DCALL(D3DSprite->Draw(
button->owner->D3DTexture.get(),
nullptr,
&button->center,
&button->position,
0xFFFFFFFF
));
RECT textbox = {0};
unsigned int format = DT_CENTER | DT_VCENTER;
textbox.top = button->PositionY() - (button->Texture()->SizeY() / 2);
textbox.left = button->PositionX() - (button->Texture()->SizeX() / 2);
textbox.bottom = button->PositionY() + (button->Texture()->SizeY() / 2);
textbox.right = button->PositionX() + (button->Texture()->SizeX() / 2);
D3DCALL(button->font->D3DXFont->DrawTextW(
D3DSprite.get(),
button->Text().c_str(),
button->Text().size(),
&textbox,
format,
button->Colour()
));
});
D3DCALL(D3DSprite->End());



Just a note- I'm using a C++0x compiler so there may be some unfamiliar constructs in here like decltype and lambda functions. If any clarification is needed just ask.

This topic is closed to new replies.

Advertisement