Jump to content
  • Advertisement
Sign in to follow this  
jagguy

using 3d for 2d confusion?

This topic is 4494 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

When creating a 2D game of any sort with directx/c++, some people have said that you should use the 3D section instead of the sprite interface. Now if you create a 2D background and you want it tiled for collision detection and other reasons. To do that in 3D you then have to create a vertex and index array for each tile. Also you would need the U,V coordinated for the texture to draw on, which would be a small fraction of the whole actual background texture. Each tile would have 4 vertices and an index array and 4 U,V points under well under 1.0. Then the camera would need to move around and each tile needs to be checked for collision and the other tiles off screen not drawn.... This seems to amount to a lot of complicated code for an ease of use I can't see any benefit for. I say use 2D api for 2d stuff and 3d api for 3d stuff with directx. What are you thoughts?

Share this post


Link to post
Share on other sites
Advertisement
Trouble is that DirectDraw is now officially deprecated so there is no guarantee that future versions of DirectX or newer graphics cards will support it. I believe it has been completely dumped from DirectX 10.

Since the improvements to the D3D interface from DirectX 8 onwards, I'm not actually convinced that DirectDraw is any simpler than D3D for 2D games. I appreciate there are some annoying restrictions like the power of two texture sizes on some cards (my GeForce 4 being among them) but I think these are outweighed by stuff like hardware alpha blending, rotation, scaling and so on.

Setting up the device is a hell of a lot easier than DirectDraw, particularly now all the back buffering is done under the hood, and with ID3DXSprite or a well written wrapper D3D 2D code doesn't need to be that complicated.

Don't get me wrong. I have been dragged kicking and screaming away from DirectDraw and was deeply resentful that I had to learn 3D interfaces to write 2D games but now I am beginning to get a handle on it, it doesn't seem so bad.

Once you have your head round all this vertex stuff and texture co-ordinates, you are pretty much set. There's no need to move cameras around. Just have an rhw in your vertex format and set each one to 1.0f and it's just like drawing 2D stuff as far as I can see (no idea how this works, but it does seem to work [smile]).

And then when you do want to move on to 3D, I'd assume that writing 2D stuff with D3D would give you a good foundation to build on.

Share this post


Link to post
Share on other sites
I think my post wasn't clear because I wasn't talking about Directdraw at all. I didn't think anyone still uses this anyway. I am using ID3DXSprite and that is what I was talking about for a background . I believe ID3DXSprite can be used for 3D as well (although this sounds odd).

You either use ID3DXSprite for a background with a file of a large size, and tile it. Compared to using CreateVertexBuffer,CreateIndexBuffer and a now complicated vertex structure with u,v points like (1/1024 * no tiles across + 1/1024 * no tiles down). Each tile would need to be created like this .

Also you need to work out the floating camera ona world view.

So how is this better than using ID3DXSprite for ease of coding and performance.

Share this post


Link to post
Share on other sites
Your post was clear, I knew you talking about the ID3DXSprite interface.

If you find it easier to use the Sprite interface then use it - The class was not designed to be inefficient so it should work well for you - under the hood, ID3DXSprite will handle stuff like the vertex buffer for you.

You don't need to make things more complicated for yourself :)

Share this post


Link to post
Share on other sites
I agree. ID3DXSprite is there to make your life easier when working with 2D, and by all means use it...

Share this post


Link to post
Share on other sites
I can get the hang of creating a 2d scene with vertex/index buffers and texture coords u,v if it makes performance and handling easier. I can do simple 3d stuff no problem so it isn't a big deal. I wanted to know if there was any advantage in doing this it looked more a more complex solution.

Share this post


Link to post
Share on other sites
In many -- all, if you're like me :P -- cases, ID3DXSprite will produce more efficient batching/rendering than you'll do with all of the index/vertex buffer work. I changed my rendering method from manual batching to the sprite interface a while back, and performance skyrocketed. I heartily -- yes, heartily! -- recommend taking advantage of it. [grin]

Share this post


Link to post
Share on other sites
Apologies for the confusion. I assumed when you said "2D API" that you meant DirectDraw. Certainly my bad.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!