Why are fonts jagged in draw() but not in setup()??

edited January 2014 in Using Processing

When I setup my code like this:

PFont f;
void setup(){
  size(400, 400);
  f = createFont("Arial", 16, true);
  textFont(f);
  fill(0);
  text("Red", width/2, height/2);
}

I get nice, smoothly rendered text.

However, when I recode like this:

PFont f;
void setup(){
  size(400, 400);
  f = createFont("Arial", 16, true);
  textFont(f);
}
void draw(){
  fill(0);
  text("Red", width/2, height/2);
}

I get incredibly jagged-looking text. How does one get smooth text in draw()?![smooth]

Tagged:

Answers

  • edited January 2014

    setup() runs once, draw() runs an 60 times per second (default) until your sketch is closed.

    The text is smooth at the beginning, but as you are rendering more and more layers of text at the same spot (60 layers per second), without clearing the background, even anti-aliased fonts will become aliased.

    Just insert something like background(#d1d1d1); before the text() call or add noLoop(); to your setup() function;

  • Perhaps the FAQ article should be something along the lines of "Why are my text and graphics so ugly and blocky?"

Sign In or Register to comment.