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)
   drawing text over lines
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: drawing text over lines  (Read 247 times)
d_ _ _

WWW
drawing text over lines
« on: Nov 23rd, 2003, 9:14pm »

Hi,
 
I'm new to this forum and fairly new to Processing as well.
 
Here's my problem.  I have this piece of code that randomly draws 100 horizontal lines and then draws the word "strange".  I would expect the text to be drawn on top of the white lines, however, the lines seem to overwrite the string.
 
Code:

void setup() {
  size(200,200);
  f = loadFont("BauerBodoni.vlw.gz");
  textFont(f, 50);
}
void loop() {
  background(125);
  // draw 100 random white lines accross the canvas
  stroke(255);
  for (int i = 0; i < 100; i++) {
    float x = random(200);
    line(x,0,x,200);
  }  
  // then draw a string
  fill(0);
  text("strange",30,100);
}

 
If I change line(x,0,x,200) to draw a rectangle of width 1 instead ( rect(x,0,1,200) ), then my text appears in the foreground as expected.
 
Does anyone have an explanation for this behaviour, and could point out what I am doing wrong?
 
Regards,
 
David
 
 
arielm

WWW
Re: drawing text over lines
« Reply #1 on: Nov 23rd, 2003, 10:24pm »

text is currently done with transparent images (one for each letter) and texture mapping (based on the default polygon engine, the same that is used for drawing, say, cubes).
 
at this point, thin lines (when no strokeWidth is defined) are always drawn on top of polygons, so that is the technical explanation for your troubles.
 
when you draw a rectangle and your scene is considered 3d by the drawing engine, your rectangle is also rendered as a polygon, this is the reason why you succeed in having the text shown behind in that case (something called z-buffering is deciding which polygon pixels should be shown, depending on their z value...)
 
if it's still important for you to have lines in top of the text, you could try using a strokeWidth greater than one: in theory, your lines should then be rendered as polygons.
 

Ariel Malka | www.chronotext.org
d_ _ _

WWW
Re: drawing text over lines
« Reply #2 on: Nov 23rd, 2003, 10:28pm »


Thanks! That was very clear and helpful.
 
David
 
Pages: 1 

« Previous topic | Next topic »