#### Archived

This topic is now archived and is closed to further replies.

# 2D and 3D rendering within a BeginScene()

This topic is 6155 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a major problem: I can render textured tringles very well, then I tried to render normal surfaces on the back buffer, and then continue with textured triangles, the result is that my normal surfaces aren''t rendered always, they even take some time to reapering, this behavior is random in all my normal surface which are rendered to the back buffer. Then I try to call BeginScene() and render my triangles, then call EndScene(), and start drawing normal surfaces, then call agian BeginScene() | EndScene() to the rest of triangles, but the result was the same, my surfaces sometimes dissapear randomly >:[ So, What can I do? /\ /__\ C.Z. Hagen

##### Share on other sites
1. Don''t use more than one BeginScene and one EndScene per frame - on most cards this will kill your framerate, and on some such as the Neon and Kyro will lead to all sorts of strange things dissapearing, flickering etc.

2. Some drivers batch up all the triangles you draw in a frame between a BeginScene and EndScene call, so when you call Draw*Primitive*() nothing actually gets drawn. The real drawing happens later inside the EndScene() call (or concurrently after the call returns).

3. Those drivers which do batch trinagles between BeginScene and EndScene DO NOT batch up 2D drawing calls such as Blt and BltFast. Those drivers should also tell you this in the CAPS flags, look for the NO2DDURING3DSCENE.

4. The preferable way to mix 2D and 3D on *ALL* graphics cards is to do the 2D graphics as texture mapped quads.

5. When you perform a 2D operation which requires the contents of the backbuffer to be known, then all 3D drawing gets serialised so you lose all parellism between hardware graphics acceleration and the CPU. Doing any 2D, particularly Locks kills performance for this reason - expect at least a 20fps difference (thats why using GetDC and TextOut to write FPS counts is so bad) - its the equivilent of having a multiprocessor system then removing one of the processors (one is forced to wait for the other).

6. If you really must mix 2d and 3d, then your frame should look something like this to work reliably on all cards:

  void RenderAFrameOfMyCoolGame(){ pDev->BeginScene(); pDev->DrawPrimitive(...); // All 3D drawing and state setting goes here // *ABSOLUTELY NO* 2D drawing (Blt, BltFast, Lock) goes here pDev->EndScene(); // Do as much non graphics work here as possible // to give the graphics card a chance to finish drawing // the 3D part of the scene CalculateReallyComplexPhysicsStuff(); // All 2D drawing goes here // *ABSOLUTELY NO* 3D drawing here pDDS->Blt(..); pDDS->Flip(...); // or pDev->Present(...);}

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com