Directx Text Problem

Started by
5 comments, last by JaMeZwHiTe 14 years, 3 months ago
Hi all, I am trying to create a game for University Coursework and i am having some problems getting the text to work properly. I have created the text and have a render function which updates the text, my problem is it will not render properly. In other words, when the function is called, the text is rendered then disappears so quick you don't even see it. I tried calling the render function every loop round but then it only renders the text ignoring everything else and just the text is displayed but you can see the text "flashing" like its being rendered on top of itself thousands of times... I hope this makes some sort of sense? Here is my code: In the "Resources Function": l_hr=D3DX10CreateFont(g_pD3D,20,0,FW_BOLD,1,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,"Arial",&pFont); And here is the draw Function: void UpdateText() { RECT r = {400,300,0,0}; sprintf(t,"%d",Score); pFont->DrawText(NULL,t,-1,&r,DT_CALCRECT|DT_LEFT,D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)); pFont->DrawText(NULL,t,-1,&r,DT_LEFT,D3DXCOLOR(1.0f,1.0f,1.0f,1.0f)); } I call the UpdateText() every time the text needs updating and you don't see it, and if i call it every loop round i have the text flashing issue. Does anyone have any idea? Much help is appreciated :-) Jamie.
Advertisement
The code looks good. It appears likely it's where you have the update function in your loop, assuming your variable Score is valid each time through the loop, and t is a valid buffer.

FYI, you definitely have to call DrawText after you clear the buffer every render, between dev->BeginScene() and dev->EndScene(), and after you've drawn any 3D objects.

[Edited by - Buckeye on January 10, 2010 10:53:20 AM]

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thank you Buckeye for that info. The variable and buffer are valid, when i mentioned that the text renders over the top of each other, it's just '0'. Also the project is just a 2D sprite project :)
Okay, just ignore the "after 3D" stuff. [WINK] The rest is still valid. <-- I think. Just noticed you're using DX10, right? My comments are all DX9 stuff.

It would help if you posted your render loop code. You can/should use or [ source] tags (see the FAQ for how to do that.)<br><br>Meantime, ensure you've called otherSprites-&gt;End() or otherSprites-&gt;Flush() before you draw the text. Or comment out all the other sprite calls and see if the text renders properly within the BeginScene/EndScene calls.<br><br>You can also leave out the DT_CALCRECT call and, for the time being:<br><pre><br>dev-&gt;Clear(.. your buffers ..);<br>dev-&gt;BeginScene();<br>RECT r = {400,300,0,0};<br>pFont-&gt;DrawText(NULL,"test",-1,&r,DT_NOCLIP,D3DXCOLOR(1.0f,1.0f,1.0f,1.0f));<br>dev-&gt;EndScene();<br>dev-&gt;Present(NULL,NULL,NULL,NULL);<br></pre><br>or something similar (provided, of course, your window is larger than 400x300).

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I have been able to fix the problem with your help :)

One more thing though i need to ask is about it's render order... depsite it is first drawn after the resources (sprites declared and stuff) have been done, it appears underneath some of the sprites. In other words how do i push it all the way to the top ??

Also, why is it that even when i set a render order and each own Z axis, why do some of the sprites insist of rendering and overlapping in the wrong order ??

Jamie

[Edited by - JaMeZwHiTe on January 13, 2010 1:59:58 PM]
Quote:ensure you've called otherSprites->End() or otherSprites->Flush() before you draw the text.

Do you End() the other sprites before you call DrawText(NULL,..)?

If you do, post the rendering code.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
Quote:ensure you've called otherSprites->End() or otherSprites->Flush() before you draw the text.

Do you End() the other sprites before you call DrawText(NULL,..)?

If you do, post the rendering code.


Yes, ->End() and ->Flush() are called at the end of every Render loop.

Will grab the code a sec...

This topic is closed to new replies.

Advertisement