Jump to content
  • Advertisement
Sign in to follow this  
dave09cbank

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites

Thanks for the reply Adam,

 

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

I have used LineStrip, LineStripWithAdjacency, TriangleStrip, TriangleStripWithAdjacencybut had no luck so far. 

 

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 this post


Link to post
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 this post


Link to post
Share on other sites

Thanks for the reply @Adam. 

 

 

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 this post


Link to post
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:

 

gd-shape-wireframe.png

 

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.

 

gd-shape.png

 

I hope you find this useful.

Share this post


Link to post
Share on other sites

Thanks @Amr for your reply.

 

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 this post


Link to post
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 ?

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!