FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   changing the color in the middle of a quad strip?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: changing the color in the middle of a quad strip?  (Read 3236 times)
arielm

WWW
changing the color in the middle of a quad strip?
« on: May 29th, 2003, 12:35pm »

i understand that something like:
 
Code:

fill(red)
beginShape(QUAD_STRIP)
vertex(...)
vertex(...)
fill(blue)
vertex(...)
...
endShape()

 
won't work because everything is drawn inside endShape()...
 
but is there some way to do it in processing without having to deal with multiple shapes?
 
or is it something totally uncompatible anyway with the low-level poygon drawing algorithm?
 
thanks!
 
n.b: i'm trying another method of drawing text, which is based on a texture mapped quad-strip (and i would like to be able to control the color or the transparency of each "char", all this within one single beginShape(QUAD_STRIP) operation...
 

Ariel Malka | www.chronotext.org
REAS


WWW
Re: changing the color in the middle of a quad str
« Reply #1 on: May 29th, 2003, 1:45pm »

but it does work. try this:
Code:

void setup()
{
  size(200, 200);
  noStroke();
}
 
void loop()
{
  fill(255, 0, 0);
  beginShape(POLYGON);
  vertex(50, 50);
  vertex(100, 50);
  fill(0, 255, 0);
  vertex(100, 100);
  fill(0, 0, 255);
  vertex(50, 100);
  endShape();
}

 
i don't think i understand the question.
« Last Edit: May 29th, 2003, 1:46pm by REAS »  
arielm

WWW
Re: changing the color in the middle of a quad str
« Reply #2 on: May 29th, 2003, 5:10pm »

nice! (actually i didn't realize that this kind of vertex coloring was possible...)
 
but i'm still stuck because i want to draw multiple quads within one single beginShape(QUAD_STRIP), each of the quads having its own discrete color:
 
Code:

void setup()
{
  size(200, 200);
}
 
void draw()
{
  stroke(0);
  beginShape(QUAD_STRIP);
  fill(255, 0, 0);
  vertex(50, 50);
  vertex(50, 100);
  vertex(100, 100);
  vertex(100, 50);
  fill(0, 255, 0);  // 2nd quad is starting here...
  vertex(150, 50);
  vertex(150, 100);
  endShape();  
}

 
in this example, the 1st quad is red, and the second quad's color is a gradient between red and green (i would like it to be only green)
 
thanks!
 

Ariel Malka | www.chronotext.org
arielm

WWW
Re: changing the color in the middle of a quad str
« Reply #3 on: May 30th, 2003, 1:32pm »

after checking a thing or two, i've put this example online, which can serve as a clear base to reformulate my question:
http://proce55ing.net/discourse/yabb/board_Tools_action_display__num_1054293190.html
 
- vertex coloring seems great for achieving transparency effects (not yet checked it)
 
- my problem is how to color the characters arbitrarly (seems that vertex coloring is not suitable because of the gradient it produces, and adding more vertices as a trick seems a waste...)
 
- i could color each letter in the original image buffer that serves as a texture mapping for the quad-strip, but then i can't use imageMode(ALPHA) so i loose the transparency (cookie-cut) of the letters!
 
is there an imageMode i'm not aware of, that can draw (non monochrome) textures with proper alpha transparency
 
thanks!
 
 
added later: well, the answer lied within the question: RGBA is the mode i was looking for... seems to work at the same speed, which is great!
« Last Edit: May 30th, 2003, 2:26pm by arielm »  

Ariel Malka | www.chronotext.org
arielm

WWW
Re: changing the color in the middle of a quad str
« Reply #4 on: May 30th, 2003, 5:59pm »

now that character-coloring works, i tried to implement a simple depth effect, but without sucess!
 
it seems that vertex coloring doesn't work with texture-mapping (?)
 
please take a look at the following depth effect that works okay with QUAD_STRIP:
http://www.chronotext.org/processing/depth_002
 
Code:

float fovy, aspect;
float elevation, azimuth, distance;
 
void setup()
{
  size(300, 300);
  framerate(20.0);
  background(0);
 
  fovy = 60.0;
  aspect = (float) width / (float) height;
 
  distance = 220.0;
  elevation = radians(300.0);
  azimuth = radians(0.0);
}
 
void loop()
{
  beginCamera();
  perspective(fovy, aspect, 1.0, 1000.0);
  translate(0.0, 0.0, -distance);
  rotateX(-elevation);
  rotateZ(-azimuth);
  endCamera();
 
  ring(0.0, 0.0, 0.0, 100.0, 30.0, radians(12.0));  // the last param controls L.O.D
 
  azimuth += radians(2.0);
}
 
void ring(float x, float y, float z, float r, float h, float dd)
{
  boolean b = false;
  float xx, yy;
 
  noStroke();
  beginShape(QUAD_STRIP);
  for (float d = 0; d < TWO_PI; d += dd)
  {
    b = !b;
    xx = x + cos(d) * r;
    yy = y - sin(d) * r;
    fill(255, 0, 0, 153.0 + sin(PI + d + azimuth) * 102.0);  // depth effect...
    vertex(xx, yy, b ? z : z + h);  
    vertex(xx, yy, b ? z + h : z);  
   }
  endShape();
}

 
unfortunately, when applied to a QUAD_STRIP with texture mapping, this technique is not working (when values other than 255 are used for either r,g,b,a: the texture is not rendered...)
 
clues?
 
added later: to be more exact, it is not that the texture is not rendered, but rather the shape of the quad-strip is appearing almost transparent (not viewable on a black background) and the texture doesn't seem to be rendered at all...
 
i also tried to turns lights(), without dealing at all with vertex-coloring, but this time, the texture and it's cookie-cut are showing but they are rendered in black!?
« Last Edit: Jun 1st, 2003, 1:11am by arielm »  

Ariel Malka | www.chronotext.org
benelek

35160983516098 WWW Email
Re: changing the color in the middle of a quad str
« Reply #5 on: Jun 1st, 2003, 12:41pm »

yikes, it'd be interesting to map out the rendering strategies of p5's code these days
 
anywho, nice examples. you know, you could probably also bend/transform the text in interesting ways using this texturing technique.
 
arielm

WWW
Re: changing the color in the middle of a quad str
« Reply #6 on: Jun 1st, 2003, 1:32pm »

hi benelek,
 
bending, blending, transforming, blurring text... all this is in the program for the next few weeks
 
meanwhile, i'm learning a bit about lights in p5 (between me and you: very interesting!)
 

Ariel Malka | www.chronotext.org
arielm

WWW
Re: changing the color in the middle of a quad str
« Reply #7 on: Jun 5th, 2003, 2:09pm »

okay, finally i found a workaround for vertex coloring and texture mapping:
http://proce55ing.net/discourse/yabb/board_Proce55ing_software__bugs_action_display_num_1054456405.html
 
the bottom line: vertex coloring (including alpha coloring) can work for texture mapping, but only if hint(SMOOTH_IMAGES) is turned on and the image used is of format ALPHA
 
ligths() can affect images too, the same restrictions as above are applied...
 

Ariel Malka | www.chronotext.org
Pages: 1 

« Previous topic | Next topic »