Jump to content
  • Advertisement
Sign in to follow this  
Kuraitou

Best way to go about 2D in DX9?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!