Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

[DX] 3DText (D3DXCreateTextW) works only sometimes

Started by MalmodirMurin May 3, 2011 at 11:41 PM 1 replies 1.2k views
Original Post
MalmodirMurin
MalmodirMurin
Hi there,
I have a problem concerning the creation of a 3D-Text. Somehow the text renders only sometimes (~ every second appliation start).

The mysterious thing is, I set up several checkings and did break points on them to check the function results of CreateFontA, CreateCompatibleDC, SelectObject and D3DXCreateTextW but no one will trigger. They seem to work properly.

Here is my wrapper-class:

VOID Text3D::init(LPDIRECT3DDEVICE9 device, LPCWSTR text, LPCSTR font, DWORD color)
{
p_dev = device;

// Font creation
HFONT hFont = CreateFontA(25, 12, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");

if (hFont == NULL)
{
int a = 0; // BREAKPOINT
}

// Object selection
HDC hdc = CreateCompatibleDC(NULL);

if (hdc == NULL)
{
int a = 0; // BREAKPOINT
}

HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);

if (hFontOld == 0)
{
int a = 0; // BREAKPOINT
}

// Mesh creation
HRESULT hr = D3DXCreateTextW(p_dev, hdc, text, 0.01f, 2.4f, &p_text, NULL, NULL);

if (FAILED(hr))
{
int a = 0; // BREAKPOINT
}

// Object restoration
SelectObject(hdc, hFontOld);
DeleteObject(hFont);
DeleteDC(hdc);
}

VOID Text3D::renderName(D3DXVECTOR3 *position)
{
p_dev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, FALSE);
p_dev->SetRenderState(D3DRS_AMBIENT, 0xffffffff);
p_dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

D3DXMATRIX world, matscale, matmove;
D3DMATERIAL9 mat;
D3DCOLORVALUE clr;

// transform
D3DXMatrixIdentity(&world);
D3DXMatrixScaling(&matscale, 100, 100, 1);
D3DXMatrixTranslation(&matmove, position->x, position->y, position->z);
world *= matscale * matmove;
p_dev->SetTransform(D3DTS_WORLD, &world);

// inner is red
clr.a = 255;
clr.g = clr.b = 0;
clr.r = 255;

// draw
mat.Ambient = mat.Diffuse = mat.Specular = mat.Emissive = clr;
mat.Power = 1;
p_dev->SetMaterial(&mat);
p_text->DrawSubset(0);

// restoration
D3DXMatrixIdentity(&world);
p_dev->SetTransform(D3DTS_WORLD, &world);
p_dev->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS, TRUE);
}


Since there are no variables which dynamically change through the different runs, I assume they remain the same every time...

Any help appreciated. Thank you.
MalmodirMurin
MalmodirMurin
I also encounter some strange behaviour when applying a color to the mesh.
One game start it is bright as expected, another one it is rather dark.
programci_84
programci_84
Don't forget to add lighting state:

p_dev->SetRenderState (D3DRS_LIGHTING, TRUE);

Also, don't forget to zeroe your material before use:
::RtlZeroMemory (&mat, sizeof (D3DMATERIAL9));

hth.
-R
There's no "hard", and "the impossible" takes just a little time.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.