Jump to content
  • Advertisement
Sign in to follow this  
helix

2D in DirectX

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

What topics should I review if I wanted to do some 2D programming in DirectX9 (specifically, cinematics and UI)? I've done practically all my work in DirectX with D3D so this is new to me and I'm not sure where to start.

Share this post


Link to post
Share on other sites
Advertisement
DirectX's old 2D component was DirectDraw. Support for that was dropped in DX7. With DX8 and 9 use D3D, or DirectGraphics as it's now called. Use textured quads (use RHW coordinates to give positions in pixels rather than 3D space), ID3DXSprite, CopyRects (DX8), or UpdateSurface(DX9).

Try to draw each object that uses the same texture together, unless you require a specific ordering for alphablending. Changing textures takes time, and limits the number of items you can draw at once.

For on/off transparency, alphatest can be used rather than alphablend. If you have smooth alphavalues, and use a middle alpharef value like 128, and linear interpolation, you can even get some really nice smooth curved results, even when scaling up the image.

If you're doing textured quads, try to build a list of many sprites to draw at once, rather than one quad per draw call.

If you're doing textured quads, offset each UV to 0.5 texels to stop unwanted filtering when drawing sprites. (ie: (0.5/texturewidth, 0.5/textureheight) to (1.0 + 0.5/texturewidth, 1.0 + 0.5/textureheight) or ((srcx+0.5)/texwidth, (srcy+0.5)/texheight) to ((srcx+width+0.5)/texwidth, (srcy+height+0.5)/texheight) )

If you're doing lots of direct pixel manipulation with the CPU it may be faster to keep your buffer in system memory and copy it to the graphics cards once you're done.

Experiment first. See what you can do first as it may affect what/how you try to do things.

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!