Jump to content
  • Advertisement
Sign in to follow this  
MalmodirMurin

[DX] 3DText (D3DXCreateTextW) works only sometimes

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

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!