- Home /
Algorithm to fill a shape defined by 4 pixel points?
I'm developing an application where a user can define 4 pixel points on screen, and what I would like to do is fill this shape with pixels using SetPixels.
While I can do this easily for square or rectangular shapes, I was wondering if there is any efficient code or algorithm to do this for more irregular four-sided shapes, such as trapezoids etc.
Note : Filling the shape with a mesh is not an option.
So far the best option I can think of is to draw the outline, then draw a line from each pixel point of every outline, to every other outline point, but I'm not sure that's very efficient.
You should be careful with filling arbitrary points. When you have arbitrary points, there's no guarantee that they form a convex shape, so your idea would break.
Here are some slides that you might be able to get ideas from. I would personally use GL and render screen space triangles using your points, though I'm not sure if you would consider this creating a mesh or not. Using GL triangles would require either triangulating the polygon defined by your points or some stencil buffer tricks.
Answer by Torigas · Jul 07, 2015 at 12:12 PM
If you really want to fill it the old way, which i wouldn't suggest, you should look up the following things: https://en.wikipedia.org/wiki/Line_drawing_algorithm
http://alienryderflex.com/polygon_fill/
I, too would suggest you just use given solutions, for example defining a quad.