Polygon Texture

Jul 5, 2009 at 11:02 PM

I need to draw user-created polygons at the right layer.  The polygon brush always draws it in the very back.  My idea for a solution is to create a polygon texture, similar to the rectangle and circle brushes,  Then draw from there.  How would I go about making this polygon texture?

Jul 5, 2009 at 11:48 PM

The reason for the polygon brush to be different than the other brushes, is that it is a lot faster to draw using graphicscard primitives instead of generating a texture and drawing that. At least that is what I'm told :) I have not tested it.

To create a polygon texture you simply have to use your imagination. One way of creating a simply polygon algorithm is to draw lines from one point to the next with the thickness of a border. Then you fill the polygon texture with white by iterating each pixel in the texture and see if the current pixel is inside or outside the border. There are several ways of checking if the pixel is inside the polygon or not, it all depends on what requirements you have to the texture. Should it support holes, should it be optimized for convex polygons and so on.

The simples way is to check if you have passed the border of the polygon. Since you made your border beforehand you can simply check if you have gone from a black pixel (border) to an uncolored pixel (inside polygon). When you reach the border again, you will be outside the polygon.

Jul 6, 2009 at 12:28 AM
Edited Jul 6, 2009 at 12:28 AM

Ok, thanks for the explanation.  Is there anyway to change the layer the polygons are drawn at when using primitives?  When I draw a texture 1st then the polygon 2nd, the polygon appears behind the texture :(




Jul 6, 2009 at 9:07 PM

Any ideas genbox? :)

Jul 6, 2009 at 9:39 PM

I'm not sure - I'm no expert on drawing stuff.

The polygonbrush does support layering, but if you use the spritebatch to draw the textures with, they might not come up right. You could try asking on Ziggyware's forum or gamedev.net, they know a lot more about the drawing system than me.