Sign in to follow this  
Narf the Mouse

What's the best way to do 2D graphics in DirectX?

Recommended Posts

Narf the Mouse    322
Edit: By "2D graphics", I mean the basics of drawing images/sprites on the screen.
Edit2: DirextX9 has Sprites, but DX11 doesn't. My engine is to support both.

I can see two solutions:

1) Paste images onto mesh quads and draw the quads.
2) Use Direct2D, which seems to be both depreciated? and not very featureful.

Further, tutorials on this issue would be appreciated.

Thanks. Edited by Narf the Mouse

Share this post


Link to post
Share on other sites
ankhd    2304
Hello.
try this out.[url="http://takinginitiative.net/2011/01/12/directx10-tutorial-9-the-geometry-shader/"]http://takinginitiative.net/2011/01/12/directx10-tutorial-9-the-geometry-shader/[/url]

Share this post


Link to post
Share on other sites
Narf the Mouse    322
[quote name='ankhd' timestamp='1341561480' post='4956247']
Hello.
try this out.[url="http://takinginitiative.net/2011/01/12/directx10-tutorial-9-the-geometry-shader/"]http://takinginitiat...eometry-shader/[/url]
[/quote]
Thanks; read, bookmarked.

Share this post


Link to post
Share on other sites
This site has a an example of how to render 2D objects to the screen using directx10 and 11. [url="http://rastertek.com/tutindex.html"]http://rastertek.com/tutindex.html[/url]

Share this post


Link to post
Share on other sites
eFoDay    300
Here are some things that lead me to believe Direct2D is a good choice for 2D graphics in DirectX:

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/dd370987(v=vs.85).aspx"]http://msdn.microsof...7(v=vs.85).aspx[/url]
[quote]
[color=#2A2A2A][font=verdana,geneva,sans-serif]This topic introduces [/font][/color][color=#ff0000][font=verdana, geneva, sans-serif]Direct2D, a new 2-D graphics API for Windows 7[/font][/color][color=#2A2A2A][font=verdana,geneva,sans-serif]. Direct2D provides Win32 developers with the ability to perform 2-D graphics rendering tasks with superior performance and visual quality.[/font][/color]

[b][font=verdana,geneva,sans-serif]What is Direct2D?[/font][/b]
[color=#ff0000][font=verdana, geneva, sans-serif]Direct2D is a hardware-accelerated, immediate-mode 2-D graphics API that provides high performance and high-quality rendering for 2-D geometry, bitmaps, and text.[/font][/color][color=#2A2A2A][font=verdana,geneva,sans-serif] The Direct2D API is designed to interoperate with existing code that uses GDI, GDI+, or Direct3D.[/font][/color]

[color=#2A2A2A][font=verdana,geneva,sans-serif]Direct2D is designed primarily for use by the following classes of developers:[/font][/color][list]
[*][font=verdana,geneva,sans-serif]Developers of large, enterprise-scale, native applications.[/font]
[*][font=verdana,geneva,sans-serif]Developers who create control toolkits and libraries for consumption by downstream developers.[/font]
[*][font=verdana,geneva,sans-serif]Developers who require server-side rendering of 2-D graphics.[/font]
[*][color=#ff0000][font=verdana, geneva, sans-serif]Developers who use Direct3D graphics and need simple, high-performance 2-D and text rendering for menus, user interface (UI) elements, and Heads-up Displays (HUDs).[/font][/color]
[/list]
[font=verdana, geneva, sans-serif][/quote][/font]

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/hh802478(v=vs.85).aspx"]http://msdn.microsof...8(v=vs.85).aspx[/url]
[font=verdana, geneva, sans-serif][quote][/font][font=verdana,geneva,sans-serif]Here are some of the [color=#ff0000]new[/color][color=#ff0000] additions to Direct2D for Windows 8[/color][color=#2A2A2A] Release Preview.[/color][/font]
[color=#2A2A2A][font=verdana,geneva,sans-serif]The list here shows these features and some related interfaces.[/font][/color]
[color=#ff0000][font=verdana, geneva, sans-serif]Starting with Windows 8 Direct2D is built on top of Direct3D 11.1[/font][font=verdana, geneva, sans-serif].[/font][/color]
[font=verdana, geneva, sans-serif][/quote][/font]

[color=#ff0000]Direct2D Quickstart for Windows 8 -[/color] [url="http://msdn.microsoft.com/en-us/library/windows/desktop/hh780340(v=vs.85).aspx"]http://msdn.microsof...0(v=vs.85).aspx[/url]

Share this post


Link to post
Share on other sites
mhagain    13430
Direct3D 9 doesn't actually have sprites.

What it has is a wrapper around vertex buffers, index buffers, textures, states and regular geometry. That's exactly all that ID3DXSprite is - a wrapper that draws ordinary textured triangles. It makes calls to the lower-level D3D API using code that you can write yourself, so that option is also there for 10 and 11.

Share this post


Link to post
Share on other sites
lonewolff    1182
[quote name='mhagain' timestamp='1341697135' post='4956748']
Direct3D 9 doesn't actually have sprites.

What it has is a wrapper around vertex buffers, index buffers, textures, states and regular geometry. That's exactly all that ID3DXSprite is - a wrapper that draws ordinary textured triangles. It makes calls to the lower-level D3D API using code that you can write yourself, so that option is also there for 10 and 11.
[/quote]

Direct3D9 has ID3DXSprite as you stated. Therefore, Direct3D9 has sprites.

Everything in programming is a 'wrapper' for something else, when you think about it.

Share this post


Link to post
Share on other sites
mhagain    13430
[quote name='lonewolff' timestamp='1341911756' post='4957557']
[quote name='mhagain' timestamp='1341697135' post='4956748']
Direct3D 9 doesn't actually have sprites.

What it has is a wrapper around vertex buffers, index buffers, textures, states and regular geometry. That's exactly all that ID3DXSprite is - a wrapper that draws ordinary textured triangles. It makes calls to the lower-level D3D API using code that you can write yourself, so that option is also there for 10 and 11.
[/quote]

Direct3D9 has ID3DXSprite as you stated. Therefore, Direct3D9 has sprites.

Everything in programming is a 'wrapper' for something else, when you think about it.
[/quote]

Try a test.

Fire up PIX.

Select a program using ID3DXSprite.

Do a single frame capture and tell it to also capture D3DX calls.

Run for a bit, press F12 to capture the frame, then quit.

Scroll down through the call list, find a call into ID3DXSprite, then expand it.

See all the SetTextureStageState calls, the SetTexture calls, the SetStreamSource calls, the DrawIndexedPrimitive calls? That's what I mean. It's [i]not[/i] hardware support for sprites, it's purely a software wrapper, and it's something you can write yourself for D3D11 using the equivalent calls.

It's also the case that D3DX is [i]not[/i] D3D. D3DX is a higher level utility library built on top of D3D (source: http://www.microsoft.com/en-us/download/details.aspx?id=22275, http://msdn.microsoft.com/en-us/library/windows/desktop/bb172965%28v=vs.85%29.aspx), and you can even use some D3DX functions and interfaces in OpenGL (such as the matrix library). The two of them should not be mixed up in this manner.

Share this post


Link to post
Share on other sites
lonewolff    1182
I guess you are right when you look at it depending on your point of view (hardware vs software) :)

But, the first link you provided is for DirectX 8.0b.

D3DX9 (utilities) are a standard a part of the DirectX 9 SDK (not a separate download), therefore (as far as I am concerned) sprites are a standard part of Direct X 9.

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