Change or fix text Background in P3D

Hi people, have a new question:

When using P3D the text is written with the original background of your sketch (or any color, don’t know from where it takes the color).

I was trying to put a text but there appear a text background that I don like, much easier to see the picture:


Can I delete the background color of the text or something? (in other texts I don’t have any problem, but this one is bothering me)

This is the code if it helps in something:

float b=0;

void setup(){
  size(1024,900,P3D);
  background(0);
  noStroke();
}
void draw(){
  background(0);
  b = map(mouseY,0,height,-190,200);
  pushMatrix();
  translate(width/2+200,height/2);
            pushStyle();
            fill(0,0,255);
            stroke(0,0,255);
            textSize(50);
            fill(0,0,255);
            text("Z",0,0,10);
            text("z",20,-10,10);
            text("Z",30,-50,10);
            popStyle();
  fill(255);
  beginShape();  
  vertex(-150,0);
    bezierVertex(-150,0,-10,-190,150,0);
    bezierVertex(150,0,10,190,-150,0);
  endShape(CLOSE);
  fill(0);
  ellipse(0,0,100,100);
  fill(255);
  ellipse(0,0,40,40);
  fill(122);
  beginShape();  
  vertex(-150,0);
    bezierVertex(-150,0,-10,-190,150,0);
    bezierVertex(150,0,10,b,-150,0);
  endShape(CLOSE);
  popMatrix();
}
1 Like

actually in P2D and P3D there is no background for text
and this way it suddenly works

float b=0;

void setup() {
  size(1024, 900, P3D);
  background(0);
  noStroke();
}
void draw() {
  background(0);
  translate(width/2+200, height/2);
  draw_eye();
 // if ( b > 100) 
    draw_text();
}

void draw_eye() {
  push();
  b = map(mouseY, 0, height, -190, 200);
  fill(255);
  beginShape();  
  vertex(-150, 0);
  bezierVertex(-150, 0, -10, -190, 150, 0);
  bezierVertex(150, 0, 10, 190, -150, 0);
  endShape(CLOSE);
  fill(0);
  ellipse(0, 0, 100, 100);
  fill(255);
  ellipse(0, 0, 40, 40);
  fill(122);
  beginShape();  
  vertex(-150, 0);
  bezierVertex(-150, 0, -10, -190, 150, 0);
  bezierVertex(150, 0, 10, b, -150, 0);
  endShape(CLOSE);
  pop();
}

void draw_text() {
  push();
  textSize(50);
  fill(0, 0, 255);
  text("Z", 0, 0, 10);
  text("z", 20, -10, 10);
  text("Z", 30, -50, 10);
  pop();
}

and it also works with the text at

  text("Z", 0, 0);
  text("z", 20, -10);
  text("Z", 30, -50);

But note that here the text is drawn AFTER the shapes…

you draw the text prior, but try to raise it with z = 10
and so you seem to have found some renderer bug?


void draw() {
  background(0);
  translate(width/2, height/2);
  translate(200,0);
  draw_eye(); if ( b > 100)  draw_text();
  translate(-400,0);
  draw_eye(); if ( b > 100)  draw_text();
}

2 Likes

Thanks @kll, its works!! :hugs::hugs:

Had all untidy because of the things I was trying (change color depending on the open or close it is, the scroll of the eyelid was added after, etc…) (the entire code is too large, but all comented :sweat_smile:)

and so you seem to have found some renderer bug?

That seems :thinking:

1 Like

Possibly just the way that layering and compositing works in the graphics pipeline.

Some solutions:

  1. change draw order – draw text last
  2. render text to a PGraphics (which has a transparent background) and then place it in a z layer using image();
  3. try using hint(); e.g. pg.hint(ENABLE_DEPTH_SORT); – this may require you to separate out your other layers as well. https://processing.org/reference/hint_.html

Trying to do 2D in 3D is often going to cause a variety of unwelcome z-fighting problems. In general it is much easier to:

  1. create a P3D sketch
  2. create a P2D PGraphics
  3. draw your 2D scene(2) exactly as you want, with no layering problems, on the PGraphics
  4. place it in your 3D space with image()
2 Likes