Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Do you need Direct3D? Or is that changeable? –  The Communist Duck Dec 29 '10 at 13:34

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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