Sign in to follow this  

2D in DirectX

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

This topic is 4749 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.

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