Jump to content

  • Log In with Google      Sign In   
  • Create Account


Text disappearing? (D3DXFONT)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 25 November 2012 - 03:32 PM

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, 25 November 2012 - 03:34 PM.


Sponsor:

#2 Tom KQT   Members   -  Reputation: 1562

Like
0Likes
Like

Posted 26 November 2012 - 01:42 AM

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]

#3 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 26 November 2012 - 01:58 AM

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).

#4 Steve_Segreto   Crossbones+   -  Reputation: 1514

Like
0Likes
Like

Posted 26 November 2012 - 02:07 AM

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.

#5 Tom KQT   Members   -  Reputation: 1562

Like
0Likes
Like

Posted 26 November 2012 - 02:26 AM

In your example/ reply I believe all text is rendered in the end, when I exectute 'present'? (or am I overseeing something).

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, 26 November 2012 - 02:32 AM.


#6 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 26 November 2012 - 03:33 AM

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.

#7 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 26 November 2012 - 05:27 PM

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.

#8 Tom KQT   Members   -  Reputation: 1562

Like
0Likes
Like

Posted 27 November 2012 - 02:00 AM

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.

2 - print text to frontbuffer directly

I don't think you can do this in DirectX, but I never even thought about it so who knows :)

#9 cozzie   Members   -  Reputation: 1585

Like
0Likes
Like

Posted 28 November 2012 - 05:01 PM

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).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS