1

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 !

Bibu
  • 1,249
  • 2
  • 17
  • 40

1 Answers1

1

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.

MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
  • Thank you @Mikelsrael but it's what I'm doing no ? Because my color array has the same size that my vertice array – Bibu May 14 '12 at 08:59
  • Yeah but not the texs. It says it also need to have the same size, but you are sending null. "he array size of the verts, texs, and colors arrays must all match the vertexCount." Maybe just to test if that is the issue send the verts as texs as well and see if you get anything. – MikeIsrael May 14 '12 at 09:03
  • what is the color you set in your paint? Is it definitely different from your background color? – MikeIsrael May 14 '12 at 09:18
  • The color is Red, my background is a map, so yes it's definitely different. – Bibu May 14 '12 at 09:23
  • ok see my edited answer this got it working on my system, is there a case where you need different colors for each point? – MikeIsrael May 14 '12 at 11:14
  • Ok, if I understand everything you say, I must have something like that so : 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, null, 0, null, 0, 0, this.p); and the color is defined in my paint (p). I need only one color for each point – Bibu May 14 '12 at 11:50
  • 1
    your are a genius ! It's work great !! Thank you very much for your time. – Bibu May 14 '12 at 12:03