Sign in to follow this  
cozzie

Text disappearing? (D3DXFONT)

Recommended Posts

Hi,

When I start my 3D engine and load scene etc., I output text on the Window to show progres.

- scene file loaded
- d3d device initialized
etc.

Before I enabled the debug version of D3D (instead of retail) version, everything worked fine. Now in debug, I get notes about 'present' cannot we between beginscene and endscene. I've read that this might have to do that my graphic card supports it (retail mode) but some others might not.
I figured, let's solve it so it works always.

Can anyone give me some pointers on what I might be doing wrong?
(by the way, my print function counts the line number in the object, goes one up after each call)

Here's the sample code:
[source lang="cpp"]_d3d.mD3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), NULL, 0);

// compiling those 4 lines and the 4 lines below, gives as result:
// green background color, first line of text not shown, 2nd line (code below) shown on black //background

_d3d.mD3ddev->BeginScene();
_d3d.mD3dFont.Print((char*)console_initdi);
_d3d.mD3ddev->EndScene();
_d3d.mD3ddev->Present(NULL, NULL, NULL, NULL);


// do other stuff


// only compiling these 4 lines of code, shows text correctly
_d3d.mD3ddev->BeginScene();
_d3d.mD3dFont.Print((char*)console_loadscn);
_d3d.mD3ddev->EndScene();
_d3d.mD3ddev->Present(NULL, NULL, NULL, NULL);
[/source] Edited by cozzie

Share this post


Link to post
Share on other sites
You don't have to (or better said - you shouldn't) call BeginScene, EndScene and Present for every single draw call, but only once per render target. If you render only to the default backbuffer, you just call BeginScene at the beginning, then do all drawing (including text), then at the end call EndScene followed by Present.

[source lang="cpp"]
_d3d.mD3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), NULL, 0);
_d3d.mD3ddev->BeginScene();
_d3d.mD3dFont.Print((char*)console_initdi);

// do other stuff

_d3d.mD3dFont.Print((char*)console_loadscn);
_d3d.mD3ddev->EndScene();
_d3d.mD3ddev->Present(NULL, NULL, NULL, NULL);

[/source]

Share this post


Link to post
Share on other sites
Hi, thanks for the reply.
I'll try that, but I wonder if it will solve my problem, because what I'm trying to do is give a progress update on things being loaded, meaning I want to 'present'/draw each line as soon as a stap has finished. In your example/ reply I believe all text is rendered in the end, when I exectute 'present'? (or am I overseeing something).

Share this post


Link to post
Share on other sites
As suggested, you should only call Present once per frame. I don't believe you will need to have "load progress" updates faster than once per frame, but if you do, I suggest piping them to OutputDebugStream, a log file or a special console window instead of to the screen.

Share this post


Link to post
Share on other sites
[quote name='cozzie' timestamp='1353916682' post='5004139']
In your example/ reply I believe all text is rendered in the end, when I exectute 'present'? (or am I overseeing something).
[/quote]
Yes, that's correct, when you call present, the content of backbuffer is swapped with frontbuffer and thus displayed on the screen.

The code you posted is executed in your main loop (every frame) or is it just "linear" code, something like:
- print something on the screen
- do something
- add some other text on the screen
- do something
- add some other text on the screen
- end

If the later, then I'm afraid it won't be so easy. In DirectX you normally do your drawing every frame (for example 60 times per second), even if nothing changed on the screen. If you want to display some text, like a console (dos window), you could add the text to some buffer (for example std::vector<string> where each entry is one line or one message) whenever you want to add a new line on the screen, and display this whole vector every frame. Edited by Tom KQT

Share this post


Link to post
Share on other sites
What I'm trying to do here is 'one time' execution, not for each frame.
The order is:
1. initialize direct3d
=> print a line of text in window/ fullscreen with LPD3DXFONT
(including making it visible)
2. initialize directinput
=> print a line of text in window/ fullscreen with LPD3DXFONT
(including making it visible)
3. load scene file
etc. etc.

So it's not something which I do for each frame (it's the initialisation phase, before rendering the scene frame by frame). With frame by frame rendering, I have no issues with printing text in each frame.

Share this post


Link to post
Share on other sites
Hi Tom,
It's the latter, inital startup of my engine, not during scene rendering frame by frame.

With the reactions I now think I would have two options.
One being:
1. clear buffers, begin scene, print text, end scene, present
2. don't clear buffers, begin scene, print text, end scene, present
3. etc..
that way I keep the 'normal frame rendering' in place, without clearing the frontbuffer.


Two being:
1 - clear buffers. begin scene
2 - print text to frontbuffer directly
3 - print text to frontbuffer directly
... etc.
x - end scene


One I didn't get working up till now, two I don't know if this is possible.

Share this post


Link to post
Share on other sites
If you don't render your scene each frame, you'll have problems everytime the window or its part needs to be redrawn. That means for example:
- in windowed mode when you move the window partly behind the edge of the screen
- in windowed mode when another window is displayed over your application window
- in windowed mode when you minimize the window
- in fullscreen mode when you alt-tab away

In this cases the part of the window (or the whole window) will be white until you swap buffers by calling present again.
Normally you call present frequently so you don't notice it, or you call present also as a reaction to the WM_PAINT windows message which tells you that the window needs to be redrawn. Neither is possible in your case.

[quote name='cozzie' timestamp='1353972471' post='5004349']
2 - print text to frontbuffer directly
[/quote]
I don't think you can do this in DirectX, but I never even thought about it so who knows :)

Share this post


Link to post
Share on other sites
Thanks.
I think I'll go for a simple 'buffer'/ string array then, during the initialization process.
Just draw the new succeeded step in loading, including the earlier ones, and then render all lines at once
(and delete the array after last progress update).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this