0
\$\begingroup\$

I am currently trying to draw a simple 2D circle and an arc in DirectX but there are no resources online with info on how I can do this. Lines & Points are built into DirectX anyway so that has never been a problem.

Can somebody explain how I can do this? I'm not talking about a sphere or any other 3D geometry. Just a simple 2D Circle and Arc.

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ Can you draw 3d stuff? \$\endgroup\$
    – Bálint
    Oct 8, 2016 at 9:52
  • \$\begingroup\$ @Bálint Yeah, Cubes with Textures, Diffuse & Specular reflections etc. Haven't moved on to other types of geometry yet because I'm trying to implement SSAO and other rendering techniques at the moment. But I don't imagine 2D being hard at all. \$\endgroup\$ Oct 8, 2016 at 16:31
  • \$\begingroup\$ Then drawing circles is just drawing a lot of triangles \$\endgroup\$
    – Bálint
    Oct 8, 2016 at 19:19

2 Answers 2

1
\$\begingroup\$

You need to approximate these shapes with triangles. Assembling a circle from triangles can be done like the following pseudo-code:

list<Vector2> vertices;
float radius = 10;
vertices.Add(Vector2(0,0)) // center point
for (float i = 0; i <= 100; i += 1.0f)
{
    float t = PI * 2 * i / 100;
    vertices.Add(Vector2(radius * cos(t), radius * -sin(t)));
}

Then you can draw these vertices with a triangle fan primitive topology.

\$\endgroup\$
0
\$\begingroup\$

You could draw a quad and use a pixel shader to fill the circle/arc.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .