PGraphics text has ugly edges

Hello,

I'm trying to draw text inside of a PGraphics, but it looks ugly. Code:

PGraphics g;

void setup() {
  size(400, 400);

  g = createGraphics(width, height);

  g.beginDraw();
  g.fill(255);
  g.text("In PGraphics", 4, 48);
  g.endDraw();
}

void draw() {
  background(32);

  fill(255);
  text("In Draw", 4, 24);

  image(g, 0, 0);
}

Here's a screenshot:

screenshot

What's going wrong with this? I tried adding a background(0) call to the PGraphics, but it didn't help, because the background needs to be transparent. I am going to draw color in my final sketch, so I can't really use blending modes.

EDIT: Just providing more details: I need to use JAVA2D, because my sketch uses clip(), and P2D breaks clip() with transform().

Answers

  • Try generating your pg inside draw instead of setup().

    Kf

  • @kfrajer this had absolutely no effect, tried to move the g.* calls to draw(), removing noLoop(), all of this had no effect.

  • Answer ✓

    For me, a 100% transparent white color for PGraphics::background(): pg.background(-1, 0);. L-)

    Seems to give a much better smooth result for text() than a 100% transparent black: pg.clear(). =P~

  • @GoToLoop It worked! Thank you very much.

  • Also, I have noticed that the pg.background(-1, 0); approach as suggested by GoToLoop works only for white text, change the background color to the text color to fix this. Unfortunately, this also means that multiple colors are not supported (but in my case that's OK, as all of my text and elements are white/defined by user).

Sign In or Register to comment.