- Home /
Coloring polygons using GL.QUADS
Hi,
I'm trying to color loops (polygons drawn with GL.QUADS) and it's only working when the loop has 4 points.
Here's a screenshot :
When there are 4 points, the loops is fully colored, but when there are more than 4 points, only one part of the loop is colored.
Here's the function I've written :
public void ColorLoop(Loop l){
// Color loop if closed, bool canColor is true and loops is not inversed
if (l.isClosed() && l.canColorLoop && !l.isInverse()){
float nearClip = cam.nearClipPlane + 0.00001f;
Vector2[] points = l.getPoints();
GL.Begin (GL.QUADS);
GL.Color (l.getLoopColor());
for (int i = 0; i < points.Length - 1; i++){
GL.Vertex(cam.ViewportToWorldPoint(new Vector3(points[i].x, points[i].y, nearClip)));
}
GL.End();
}
}
Any idea on how to color all the loop, even when it has more thant 4 points ?
Thanks !
Answer by Graham-Dunnett · Sep 07, 2014 at 08:40 AM
A quad can only have 4 vertices. That's what quad means. For more complex shapes draw it using a sequence of triangles, or triangle strip.
Thanks for your answer. I found this Triangulator script : link text This script is creating a mesh using a Vector2 array containing all the points of the polygons.
Anyone coud help me with this script and the one I've written to draw and color a triangulated polygon using GL.TRIANGLES ? :)
How complex are the shapes you are trying to draw? If the shapes are simple, and you have the list of vertices in some correct order, and the shape is convex, then you can triangulate the shape by computing the centre of the shape (add all the verts together and divide by the number of verts) and draw two vertices and the centre for each triangle.
Your answer
Follow this Question
Related Questions
Trouble in GL lines - change color 2 Answers
Changing two different objects renderer colour 1 Answer
GL.Color() has no effect on android 1 Answer
How do I change GL LINES color? 1 Answer
When should I call GL.Begin/End? 0 Answers