I can draw triangles, but not filled triangles.

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

I can draw triangles, but not filled triangles.

Postby doma » Wed Oct 08, 2008 11:53 pm

Howdy,
I'm able to draw triangles using the drawVerticies call, but I can't seem to get them to fill. Can any of you throw me a hint?

Here's what I'm doing...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.   //Early on, I create my blue paint and set the style to 'FILL'
  2.  
  3.   Paint pBlue = new Paint();
  4.  
  5.   pBlue.setColor(android.graphics.Color.BLUE);
  6.  
  7.   pBlue.setStyle(Paint.Style.FILL);
  8.  
  9.  
  10.  
  11.   //in my view's onDraw function...
  12.  
  13.  {
  14.  
  15. ...
  16.  
  17.   canvas.drawCircle(250, 370, 30, pBlue);    
  18.  
  19.                
  20.  
  21.    float [] points  = new float[8];
  22.  
  23.       points[0] = 10;
  24.  
  25.       points[1] = 10;
  26.  
  27.  
  28.  
  29.       points[2] = 100;
  30.  
  31.       points[3] = 10;  
  32.  
  33.                
  34.  
  35.       points[4] = 50;
  36.  
  37.       points[5] = 100;
  38.  
  39.  
  40.  
  41.       points[6] = 10;
  42.  
  43.       points[7] = 10;
  44.  
  45.       canvas.drawVertices(VertexMode.TRIANGLES, 8, points, 0, null, 0, null, 0, null, 0, 0, pBlue);
  46.  
  47.  
  48.  
  49. ...
  50.  
  51. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


What happens is I get a filled circle (which is good).
But then the triangle draws just as a wireframe. It is not filled in. (which is bad)

I also tried leaving out the last point (10,10) which was an attempt to 'close' the triangle. In that case I use 6 as the second param to drawVertices. It still draws the same triangle and doesn't fill it.

So, it appears that 'FILL' works when doing rects or circles, but not for drawVertices. Is that expected, or am I doing this wrong?

Your wisdom is much appriciated. :-)

-doma
doma
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 08, 2008 11:36 pm

Top

Postby plusminus » Thu Oct 09, 2008 1:12 am

Hello doma,

i've not been working with [font=Courier New]canvas.drawVertices[/font], but I can say that canvas.drawPath works really fine and it supports FILL.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby doma » Thu Oct 09, 2008 1:26 am

excellent!

I abandoned drawVertices and tried drawPath and it works great. My triangls are now filled in.

my new onDraw now contains this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. {
  3.  
  4.  ...
  5.  
  6.   Path path = new Path();
  7.  
  8.   path.moveTo(10,10);
  9.  
  10.   path.lineTo(100,10);
  11.  
  12.   path.lineTo(50,100);
  13.  
  14.   g.drawPath(path, p);
  15.  
  16. ...
  17.  
  18. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


thanks plusminus.

-doma
doma
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 08, 2008 11:36 pm

Postby plusminus » Thu Oct 09, 2008 1:30 am

No problem :)
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Re: I can draw triangles, but not filled triangles.

Postby Craigo » Mon Jun 22, 2009 12:47 pm

doma wrote:Howdy,
I'm able to draw triangles using the drawVerticies call, but I can't seem to get them to fill. Can any of you throw me a hint?


DrawVerticies does its own shading (just like when you use OpenGL). Except it's _really_ slow! See HERE for an example.
Craigo
Junior Developer
Junior Developer
 
Posts: 10
Joined: Tue Mar 17, 2009 3:30 am
Location: Sydney, Australia

Re:

Postby man » Wed Jan 09, 2013 11:12 am

plusminus wrote:No problem :)



Hey plusminus, I want to draw line in different patterns(for Example:- http://stackoverflow.com/questions/1420 ... 8_14209819) but I dont understand how can I do this. Can you suggest me some way by using that I can fulfill my requirement.
- m@n
man
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jan 09, 2013 11:03 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests