Drawing a Loading Screen with Direct2D in SlimDX

Published September 30, 2013
Advertisement
[font=Arial]


I know that I have been saying that I will cover random terrain generation in my next post for several posts now, and if all goes well, that post will be published today or tomorrow. First, though, we will talk about Direct2D, and using it to draw a loading screen, which we will display while the terrain is being generated to give some indication of the progress of our terrain generation algorithm.

[/font]
[font=Arial]


Direct2D is a new 2D rendering API from Microsoft built on top of DirectX 10 (or DirectX 11 in Windows 8). It provides functionality for rendering bitmaps, vector graphics and text in screen-space using hardware acceleration. It is positioned as a successor to the GDI rendering interface, and, so far as I can tell, the old DirectDraw API from earlier versions of DirectX. According to the documentation, it should be possible to use Direct2D to render 2D elements to a Direct3D 11 render target, although I have had some difficulties in actually getting that use-case to work. It does appear to work excellently for pure 2D rendering, say for menu or loading screens, with a simpler syntax than using Direct3D with an orthographic projection.

[/font]
[font=Arial]


We will be adding Direct2D support to our base application class D3DApp, and use Direct2D to render a progress bar with some status text during our initialization stage, as we load and generate the Direct3D resources for our scene. Please note that the implementation presented here should only be used while there is no active Direct3D rendering occurring; due to my difficulties in getting Direct2D/Direct3D interoperation to work correctly, Direct2D will be using a different backbuffer than Direct3D, so interleaving Direct2D drawing with Direct3D rendering will result in some very noticeable flickering when the backbuffers switch.

[/font]

[font=Arial]


The inspiration for this example comes from Chapter 5 of Carl Granberg's Programming an RTS Game with Direct3D, where a similar Progress screen is implemented using DirectX9 and the fixed function pipeline. With the removal of the ID3DXFont interface from newer versions of DirectX, as well as the lack of the ability to clear just a portion of a DirectX11 DeviceContext's render target, a straight conversion of that code would require some fairly heavy lifting to implement in Direct3D 11, and so we will be using Direct2D instead. The full code for this example can be found on my GitHub repository, athttps://github.com/ericrrichards/dx11.git, and is implemented in the TerrainDemo and RandomTerrainDemo projects.

[/font][font=Arial]


progressBar_thumb%25255B1%25255D.png?imgmax=800

[/font]
[font=Arial]


Read More...

[/font]
1 likes 3 comments

Comments

Bacterius

A spartan progress bar!

October 01, 2013 01:24 PM
unbird

Still better by far than those pseudo-progress-thingies one sees everywhere.

Edit: Ah, sorry for not reading your entry fully earlier. Combining D2D with D3D11 is absurdly complicated. [url="http://www.gamedev.net/topic/635426-slimdx-directx11-text-rendering-problem/?hl=%2Binitd2dscreentexture"]This thread[/url] was very helpful. It's a SlimDX transliteration from [url="http://www.braynzarsoft.net/index.php?p=D3D11FONT"]braynzarsoft[/url].

With the platform update now available it's supposed to be easier though, haven't tried myself (one can omit the D3D10 stuff, I believe). I still use that code, since I don't want to kill PIX. Well actually I don't, I ported my D3D9 bitmap font :wink:

October 01, 2013 05:13 PM
ericrrichards22

Thanks, unbird. I'll have to give that a look.

November 08, 2013 04:24 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement