I'm trying to work with 2D graphics using Direct3D 9, but am not sure where to start. Right now I'm using a texture as the "draw buffer", and drawing that texture to screen. For the simplest things, it works. But I can't see a way to e.g. draw lines, arcs, and the like onto the texture. How should I go about doing this?

  • \$\begingroup\$ Do you need Direct3D? Or is that changeable? \$\endgroup\$ – The Communist Duck Dec 29 '10 at 13:34

The GDI approach:

  • Create a bitmap and a device context
  • Render your 3d graphics into the bitmap using GDI
  • StretchBlit the bitmap onto the texture

The Pixel approach:

  • Lock the texture and fill the pixels using e.g. Bresenham's algorithm.

The Render approach:

  • Use DrawPrimitiveUP with D3DPT_LINELIST or D3DPT_LINESTRIP for drawing lines.

  • Arcs, circles and other curved shapes can be composited from lines.

  • For filled shapes generate meshes using D3DXCreateShpere/Box/Torus etc. and render those using orthographic projection. You'd use a sphere mesh to render filled circles, a box mesh for filled rectangles and a torus would allow for curved shape outlines.


Use Sprites in Direct3D 9. Very simple way of creating 2D objects in a 3D space.

There's a tutorial here: Sprite Tutorial

I've used sprites to create a 2D HUD in my 3D games and they turn out pretty well.

To draw lines, just use the D3DPT_LINELIST or D3DPT_LINESTRIP primitives with DrawPrimitive().

Drawing Arcs might be a little bit more difficult. You could look into drawing Bezier curves for that: Bezier Curves


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.