blendMode() doesn't work with text

edited March 2017 in Questions about Code

Hello,

In my program I want to use different blend modes when drawing text, but the text is not affected by the blendMode() function call.

Here's a simple program that demonstrates the issue, just move the mouse over the rectangle and see how the ellipse is correctly blended, as opposed to the letter 'K'.

void setup(){
    size(600, 600, P2D);

    rectMode(CENTER);
    textSize(100);
    textAlign(CENTER, CENTER);
}

void draw(){
    blendMode(NORMAL);
    background(50);

    noStroke();
    fill(255);
    rect(300, 300, 100, 100);

    blendMode(EXCLUSION);
    text("K", mouseX+50, mouseY);
    ellipse(mouseX-50, mouseY, 75, 75);
}

Answers

  • It works with size(600, 600). :-/

  • I tried this... partial solution as I had to change he background color to zero to nullify the effect of exclusion btw backgrounds.

    Kf

    PGraphics gr;
    void setup() {
      size(600, 600, P2D);
      rectMode(CENTER); 
      imageMode(CENTER);
      smooth(4);
    
      gr=createGraphics(200, 200, P2D);
      gr.beginDraw();
      gr.background(0);  
      gr.fill(255);
      gr.noStroke();
      gr.textSize(100);
      gr.textAlign(CENTER, CENTER);
      gr.text("K", gr.width/2+50, gr.height/2);
      gr.ellipse(gr.width/2-50, gr.height/2, 75, 75);
      gr.endDraw();
    }
    
    void draw() {
      blendMode(NORMAL);
      background(0);
      noStroke();
      fill(255);
      rect(300, 300, 100, 100);
    
      blendMode(EXCLUSION);
      image(gr, mouseX, mouseY);
    }
    
Sign In or Register to comment.