Loading...
Logo
Processing Forum

Fill not total?

in Programming Questions  •  9 months ago  
Short form question: I have a PShape made with custom vertices. Each time I draw the PShape I may need to change the colour of. I would like to do:
Copy code
  1. PShape aShape;
  2. method A(){      
  3.       aShape=createShape(triangles);
  4.       //add vertices from float array with aShape.vertex(.,.,..)
  5.       aShape.end();
  6. }
And in the draw, I'd like to do something like
Copy code
  1. fill(....) or aShape.fill(....)
  2. shape(aShape);
 
but doing so, I only get the last triangle of the PShape getting a fill change!
 
I can hack this by
Copy code
  1. method A(){
  2.       fill(...);
  3.       drawSphere();
  4. }
  5. method drawSphere(){
  6.       beginShape();
  7.       //vertex info
  8.       endShape();
  9. }
but I'm actually displaying many of these shapes per frame, on the order of a few ten thousand. So I'd prefer only to create the shape once.
 
Background:
I'm basically trying to emulate something I could do in OpenGL 3.0/C++. I could send the shape(s) to the GPU once for the duration of the program, send a new colour and matrixes  to the vertex shader when needed. I know I can basically write pure OpenGL 2.0/Java code but I want to avoid this overkill (how the code looks and its simplicity is equally important). I'm looking for as simplistic away to just send the one colour to the change the fill of my pshape.
 
Looking at the source and other documentation though, I'm unsure if I'm actually getting a speed up with the one shape (it seems to send the whole object each time?). Maybe someone with OpenGL 2.0/Processing experience could atleast say this is mote because the sphere is being sent each time anyway?

Replies(5)

Re: Fill not total?

9 months ago
You can. See the following example...

Code Example
Copy code
  1. // Processing 2.0b7

  2. PShape star;
  3.  
  4. void setup() {
  5.   size(640, 360, P2D);
  6.   smooth();
  7.   star = createShape();
  8.   star.stroke(255);
  9.   star.strokeWeight(2);
  10.   star.vertex(0, -50);
  11.   star.vertex(14, -20);
  12.   star.vertex(47, -15);
  13.   star.vertex(23, 7);
  14.   star.vertex(29, 40);
  15.   star.vertex(0, 25);
  16.   star.vertex(-29, 40);
  17.   star.vertex(-23, 7);
  18.   star.vertex(-47, -15);
  19.   star.vertex(-14, -20);
  20.   star.end(CLOSE);
  21. }
  22.  
  23. void draw() {
  24.   background(51);
  25.   translate(mouseX, mouseY);
  26.   star.fill(map(mouseX, 0, width, 0, 255));
  27.   shape(star);
  28. }

Re: Fill not total?

9 months ago
In my post I had implied I already tried using a PShape's fill method. By changing your code from  size(640, 360, P2D) to   size(640, 360, P3D), your code generates the same anomaly as mine. Below is an image of your example with the P3D change.
 
 

Re: Fill not total?

9 months ago
I can confirm the problem in Processing 2.0b7 + P3D.

I also tested it with P3D in Processing 0216 (more recent than 2.0b7, built from svn) and it didn't show this problem.

So you can either wait for the next beta release or build from svn yourself.

I work with IDE's and scripting languages mostly. It makes me feel old school & good when I have an excuse to hand-compile something. Even if that is just running ant. Even if this doesn't work, thanks a lot.

Re: Fill not total?

8 months ago
Apparently in the source for PGraphics3D, they've commented out the portion where shapes made with TRIANGLES and other techniques are instantiated. Leaving only Group, path, and Geometry.
 
PShape.end has also been changed to PShape.endShape();
 
There are a few breaking changes for 3D.

I had came up with a hack to get it to work with 2.0b7 but it didn't actually work.