I would like to draw triangles, and polygons
To draw a triangle I use this method that I found on internet :
this.p.setStyle(Paint.Style.STROKE);
int triangleColors[] = {
this.p.getColor(), this.p.getColor(), this.p.getColor(),
this.p.getColor(), this.p.getColor(), this.p.getColor()
};
float verts[] = {
ptsFloat.get(0).x, ptsFloat.get(0).y,
ptsFloat.get(1).x, ptsFloat.get(1).y,
ptsFloat.get(2).x, ptsFloat.get(2).y
};
c.drawVertices(Canvas.VertexMode.TRIANGLES,
verts.length,
verts,
0,
null,
0,
triangleColors,
0,
null,
0,
0,
this.p);
But the result is null, I’ve nothing drawn …
Whereas, drawLine, drawCircle works perfectly well, have you any idea why this method doesn’t work ? Futhermore, I don’t have any traces in my logcat console for helping me !
OK So after trying it out for myself I realized that the issue is your color array. If you are using the same color for each point then you don’t need that array. The getColor() function is not returning the int values you need. If you need different colors then use Color.X for that color to be assigned to that part of the triangle.