I can draw the outline of an ellipse but I want to draw a filled in ellipse, but I can't seem to get the code to work. Any help would be great! I am using DirectX 9 and D3DX.

  • \$\begingroup\$ Drawing vector-based shapes like ellipses, etc. are best done with Direct2D rather than Direct3D. \$\endgroup\$ – Chuck Walbourn Mar 7 '15 at 2:50
  • \$\begingroup\$ So are you recommending I rewrite the graphics engine with Direct2D instead of D3D? \$\endgroup\$ – Captain Picard Mar 7 '15 at 4:03
  • \$\begingroup\$ I don't know what your project is actually, but vector shapes like ellipses, rounded rectangles, etc. are natively supported by Direct2D. \$\endgroup\$ – Chuck Walbourn Mar 7 '15 at 4:22
  • \$\begingroup\$ I have looked a bit into Direct2D and it seems to fit very nicely what I want to do. \$\endgroup\$ – Captain Picard Mar 7 '15 at 12:35

There are multiple approaches:

  1. Cut-out texture

Create a fully transparent texture. Fill the texture with the ellipse shape on the CPU. Render the texture with alpha blend. You only need one texture per ratio of radii, so chances are you can generate some offline.

  1. Geometry

Create a tessellated sphere, pass radii to vertex shader, deform shpere into ellipsoid in the vertex shader. Project it orthographically onto the screen.

  1. Pixel Shader

Render a rectangle, pass the radii through to the pixel shader and use trigonometric functions to determine for each pixel whether it's inside the ellipse - or even better it's signed distance to the ellipse's edge. Then fill accordingly. If you compute the signed distance you can even fade it nicely toward the edges to achieve effects like bevel and emboss.

| improve this answer | |
  • \$\begingroup\$ How about a simpler version of (2) where you create the geometry as desired in the code instead? \$\endgroup\$ – Panda Pajama Apr 23 '15 at 10:05
  • 1
    \$\begingroup\$ That would work as well. I think the shader approach would be better if you (have to) care about performance and expect lots of different radii. \$\endgroup\$ – SmoCoder Apr 23 '15 at 12:25

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.