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\$
  • \$\begingroup\$ Can you draw 3d stuff? \$\endgroup\$ – Bálint Oct 8 '16 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\$ – Arjan Singh Oct 8 '16 at 16:31
  • \$\begingroup\$ Then drawing circles is just drawing a lot of triangles \$\endgroup\$ – Bálint Oct 8 '16 at 19:19
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\$

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.