Best way to go about 2D in DX9?

Started by
6 comments, last by theZapper 15 years, 9 months ago
I am curious about doing 2D drawing in DirectX 9. I've known for quite a while now that 2D was assimilated together with 3D a couple versions back, then deprecated for the most part. After doing a bit of researching I see that there is one primary method left for pure 2D (drawing directly to backbuffer), but I am skeptical about going that path for two reasons: 1) lack of documentation and tutorials, and 2) DirectX has since been optimized far more greatly for 3D functions. Now my other idea was to go 2.5D, where I could use planes with no perspective (I'm not entirely sure how this works, but they're facing the direction of the Z-axis...I think...) with textures applied to them. I am assuming that this is the better way, but a question comes up. Since the planes are in 3D space, then does that mean that ones drawn towards the edge of the screen are going to look odd? If there's a different method than either of these two, please let me know. Also, if you're wondering why I want to do 2D in DX9 (weird, I know, lol), it's because of many things that it has that true 2D libraries don't offer. Thanks in advance.
Advertisement
All you need to do is just use an Ortho Projection Matrix.
Well what exactly do you need to do? Do you need to just draw sprites to the screen, or do you need actual pixel-level access? The former is easy, you can just used textured quads. D3DX even has an interface that can make this very easy: ID3DXSprite. All you need to do is provide a position and a texture and the texture will be drawn there.

Anything fancier will require more complicated techniques.
Thanks for the fast replies, guys.

@BornToCode: I'm going to look into this.

@MJP: I want something more like the textured quads, because I find them easier to deal with than pure sprites. As long as I get all the bells and whistles of DX I'm happy. I found an article on GDNet specifically for using quads and I'm currently reading it.
Yeah I'd go with tetured quads, sprites feel a little unwieldy and out of place in a 3D world.
Quote:Original post by Kuraitou
@BornToCode: I'm going to look into this.


It's just a different way to look at things. It's a "non-human-eye" way, so it may be tough to think about, but essentially, nothing will be drawn smaller just because it is farther away -- it will be drawn the same size regardless of its distance from you.

See the picture here (on the right is the orthographic projection you want, on the left is a perspective projection):

http://www.joma.org/images/upload_library/4/vol2/photomanipulation/figure2.jpg
--== discman1028 ==--
Quote:Original post by Kuraitou
if you're wondering why I want to do 2D in DX9 (weird, I know, lol)

Absolutely 100% NOT weird -- this is a very common thing to do!

IMO we see this type of question here a lot but nobody hammers home the point that 3D and 2D are basically the same thing. Your graphics card is good at drawing triangles, and lots of them; Direct3D is just there to help you do it. Direct3D doesn't really care if the information you give it "looks" 1D, 2D, 2.5D, 3D, or whatever; its up to you to draw triangles in a meaningful way. Sure, there's a whole bunch of ways to help you transform 3D points into 2D coordinates to use on the screen, but by no means are you forced to use them. You can draw textured quads using transformed coordinates, or you can draw them using orthographic projection, or you can use the built in D3DXSprite functionality (which does the same thing internally), or you can make an entire sprite/billboard system in full 3D (although this is rarely needed.) And you can combine any of these techniques with "real" 3D techniques in any combination you choose.

Basically I am trying to convince you to look at Direct3D more as a renderer and less as a "scene description" API, even though it does have powerful helper functions for common 3D tasks. Each frame you basically get a blank canvas on which to draw whatever you want, and your job is to paint a pretty picture and not obsess over how many "dimensions" a human observer perceives from your assorted triangles!
Generally speaking, most HUDs or UIs you see in a game are just normal shapes drawn with an orthographic projection.

In OpenGL you can actually specify pixel co-ordinates when an orthographic projection is set, not sure if you can in DirectX.
---When I'm in command, every mission's a suicide mission!

This topic is closed to new replies.

Advertisement