# Fill custom shape when vertices/edges are provided fails in Directx

This topic is 935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi ,

I am trying to fill a custom shape which is defined by points that define its edges/vertices points.

The points are in clockwise order.

Image below will show the exactly what I mean by custom shape. Shapes are drawn and filled in red.

[attachment=32004:regions.PNG]

I have tried to use a triangle strip when drawing and filling it with a color but doesn't draw as expected.

Any suggestions how could they be achieved ?

##### Share on other sites

What does "doesn't draw as expected" mean?

##### Share on other sites

I meant the entire shape is not filled and but rather weird triangles are drawn at the edges.

I've included images below to explain things a bit more as to how my shapes are being rendered (shown in green color)

Using Linestrip:

[attachment=32007:LineStrip.PNG]

Using TriangleStrip:

[attachment=32008:TriangleStrip.PNG]

Thanks.

##### Share on other sites

It sounds/looks like you're trying to triangulate an arbitrarily shaped polygon. There's no immediately straightforward way to take an arbitrary shape and tell the GPU to fill it in.

Try searching online for "Polygon Triangulation", there are algorithms for doing it efficiently, but I suspect the answer isn't as simple as you're expecting.

##### Share on other sites

Is there any other way to fill an arbitrary shaped polygon other than using triangulation.

However, i will go as per your suggestion below:

Try searching online for "Polygon Triangulation", there are algorithms for doing it efficiently, but I suspect the answer isn't as simple as you're expecting.

However, if you have any other suggestions too then do let me know.

Thanks.

##### Share on other sites

The algorithm is trivial if your shape is always convex (that is, the direction change at each vertex always goes the same way). But from your second screenshot, it looks like the line that forms the perimeter of your shape may go left or right and thus not form a convex shape?

##### Share on other sites

I will have a read through after researching and understanding things a bit more on Polygon Triangulation and then post back once i understand or have question.

Thanks.

##### Share on other sites

You can use the stencil buffer. Here are a couple of screenshots from the application I'm working on (Curver, see signature) that may be helpful for demonstrating how to draw filled shapes:

The wireframe shows the geometry drawn in the two-sided stencil buffer, with stencilpass set to increment the buffer and ccw_stencilpass set to decrement it.  Then you draw a quad encompassing the shape with stencil testing enabled and viola.

I hope you find this useful.

##### Share on other sites

I haven't really had any exposure to stencil via Directx as i'm still a newbie hence would need to read on them before i can decide if they would be helpful in achieving my goal.

However, i'm wondering how to really draw the shape such as the signature letter "G " you've drawn. How could that be achieved which is really the problem im facing at the moment ?

Any suggestion on good resources to read from ?

Note:

I'm using C# with SharpDx with Directx11

Thanks.

Edited by dave09cbank

##### Share on other sites

@Amr

Ok i have looked a bit into stencil buffer but due to lcak of time i have shelved it for now but will read + learn more in due time.

So far using the native way of rendering polygon using triangles i have managed to get things further, or shall i say i'm almost there.

Now my polygon shape isn't rendered completely when compared to image shown in my original post at the top and i can't seem to figure it out. why...

So far what iv achieved is in image below:

[attachment=32016:Improved_shapeRender.PNG]

Points used to render:

[attachment=32017:Render_Points_values.PNG]

From the image above it seems some points are not being rendered.

AS to what i'm doing:

• Setting the primitive topology to be TriangleStrip
• Calling draw with no of points => draw(pointscount)

If i render the points using a pointlist they all render correctly as expected

But can't seem to figure out as what i'm doing wrong if i try to render they as triangle strip.

Any suggestions ?

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013708
×