# Text drawing seems to be happening out of order, compared to a filter(BLUR)

**URL:** https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224
**Category:** Coding Questions
**Created:** [May 30, 2022, 1:05pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224 "2022-05-30T13:05:58Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![interstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/interstar/32/2248_2.png) [@interstar](https://discourse.processing.org/u/interstar)
#### Post date: [May 30, 2022, 1:05pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/1 "2022-05-30T13:05:58Z")

</div>

I’m trying to generate a static image with a blurred background and some unblurred text in front of it.

Here’s my code

```auto
  void drawIt() {
    background(0);
    strokeWeight(4);

    pushMatrix();
    for (int j=0; j<20; j++) { 
      for (int i=0; i<20; i++) {
        fill(150, random(200), 30);
        stroke(150, random(200), 30);
        line(random(width), random(height), random(width), random(height));
      }
      filter(BLUR);
      rotate(j*0.4);
    }
    popMatrix();
    fill(255,255,255,255);
    stroke(255,255,255,255);
    textSize(48);
    text(name, 40, 100);     
  }

```

It’s doing what I’d expect, EXCEPT that the text which I think I’m drawing at the end, is a) blurry, and b) seems to be BEHIND some of the lines I’m drawing.

I’m mystified by this. Never seen anything like it before.

This is all happening within a single frame and the image is saved directly afterwards

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [May 30, 2022, 1:55pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/2 "2022-05-30T13:55:54Z")

</div>

Hi,

Sorry! deleted my prior post as it seems not being correct … 🙂  
I’ve tested your code and for me it is working as expected !?  
Lines getting more and more blured and the text isn’t blured at all onto the top of the image.  
Maybe the issue is in the code you’ve not provided here …

Cheers  
— mnse

 ![dummy](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/7/f7666aae1b65615be322b2f2340a76ba88d1a844.jpeg)

---

<div class="post-metadata">

### Author: ![interstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/interstar/32/2248_2.png) [@interstar](https://discourse.processing.org/u/interstar)
#### Post date: [May 30, 2022, 2:44pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/3 "2022-05-30T14:44:47Z")

</div>

Yes. I just tested it and you are right.

That’s even weirder!!!

In a stand alone sketch, this code works exactly as expected.

But in the context of my sketch it doesn’t???

The main app is a musical one, dealing with MIDI and recording audio files, so it’s a bit complex to go into here. But I can’t see any reason why it should be different. The main draw() of the sketch is

```auto

void draw() {
  background(0); 
  stroke(255);
 
  // draw the audio waveforms
  for(int i = 0; i < in.bufferSize() - 1; i++) {
    line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
    line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
  }
   robbie.step();
}

```

And it’s in that robbie.step() call, that, when the sketch finally finishes the other stuff it’s doing, which is all audio, it calls this function :

```auto
  void drawIt() {
    background(0);
    strokeWeight(4);

    pushMatrix();
    for (int j=0; j<20; j++) { 
      for (int i=0; i<20; i++) {
        fill(150, random(200), 30);
        stroke(150, random(200), 30);
        line(random(width), random(height), random(width), random(height));
      }
      filter(BLUR);
      rotate(j*0.4);
    }
    popMatrix();
    fill(255,255,255,255);
    stroke(255,255,255,255);
    textSize(48);
    text(name, 40, 100);    
    saveFrame("background.png");
  }

```

Which is exactly the same except for two things :

- the text() call takes a variable rather than a literal
- I saveFrame() at the end of it.

Otherwise it’s identical to the one that runs correctly as a stand-alone.

And here’s its output …

 ![background](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/f/cf4ca236e65b8ba5c5958ec413337a1d2b7e6da4.png)

What the … ???

---

<div class="post-metadata">

### Author: ![The\_Traveler](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_traveler/32/16252_2.png) [@The\_Traveler](https://discourse.processing.org/u/The_Traveler)
#### Post date: [May 30, 2022, 3:57pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/4 "2022-05-30T15:57:18Z")

</div>

```auto
The main app is a musical one, dealing with MIDI and recording audio files,

```

With midi and recording your also dealing with more system interrupts than just a standalone dealing with drawing to a surface.

The traditional way of debugging it would be to comment out parts of your midi/recording code one part at a time until you isolate the offending code. Cheers.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [May 30, 2022, 5:56pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/5 "2022-05-30T17:56:33Z")

</div>

Hello,

The framerate drops significantly with filter(BLUR).

You are doing a rotation about the origin (0, 0) in the corner and won’t see all of the lines.

I was trying to improve performance:

- I removed the rotate() and used smaller loop iterations.
- You could extend the random limits beyond the sketch window for a similar effect.

Test code:

```auto
String name = "Hello";

void setup()
 {
 size(800, 800, P2D);
 textSize(48);
 }

void draw()
  {
  background(0);
  drawIt();
  println(frameRate);
  }

void drawIt() {
    background(0);
    strokeWeight(4);

    pushMatrix();
    for (int j=0; j<10; j++) 
      { 
      for (int i=0; i<10; i++) 
        {
        fill(150, random(200), 30);
        stroke(150, random(200), 30);
        line(random(width), random(height), random(width), random(height));
        }
      filter(BLUR);
      //rotate(j*0.4);
      }
    popMatrix();
    fill(255, 255, 255, 255);
    stroke(255, 255, 255, 255);
    //textSize(48);
    text(name, 40, 100);    
    //saveFrame("background.png");
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/c/cc658e61983bbb6d9d538bab84870fde1a43a7fd.jpeg)

The loading of this loop and resulting slow frameRate should be considered.

Try it commenting the _filter(BLUR)_ and see what happens.

I don’t think this is related but sharing nonetheless:

> [@Blurry Text Solution](https://discourse.processing.org/t/blurry-text-solution/11293):
>
> I was using different text sizes in a recent project and was getting blurry fonts. I solve this issue by setting the largest text size in setup() and problem solved! Here is the code I used to test this: /\* Project: Blurry Text Author: GLV Date: 2019-05-15 Version: 01 \*/ void settings() { size(1024, 768, P3D); } void setup() { textSize(128); // Set to largest text size used to prevent blurring of text } void draw() { background(0); text24(); t…

`:)`

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [May 31, 2022, 7:39am UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/6 "2022-05-31T07:39:11Z")

</div>

Hi,

would you please try to put the saveFrame out of your function and put it at the end of draw after robbie.step, put a noLoop after it and look for the result if it is still such messed up.  
Afterwards remove the noLoop but instead call the saveFrame by adding some hashes ie. “background-#####.png”, run it for some seconds and look if the generated pictures are ok or still messed up.

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [May 31, 2022, 11:29am UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/7 "2022-05-31T11:29:24Z")

</div>

Hello @interstar,

Another tip for saving frames…

See comments here:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/9/7/9781d3a822961ce2b676f6e353b6fc037fbe3359.png)

`:)`

---

<div class="post-metadata">

### Author: ![interstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/interstar/32/2248_2.png) [@interstar](https://discourse.processing.org/u/interstar)
#### Post date: [May 31, 2022, 2:27pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/8 "2022-05-31T14:27:28Z")

</div>

OK.

I’ve just discovered that one of the other issues is that I was using P3D as the renderer in my sketch.

If I take this option out, the problem seems to disappear. But I have also changed the architecture so that instead of doing it in a single frame I now draw it over multiple frames with the blur happening once per frame.

What’s definitely true though, is that it was the P3D which seemed to be putting the text BEHIND some of the lines.

Thank you everyone for your ideas. They were all very useful helping me to think about this.

---

<div class="post-metadata">

### Author: ![interstar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/interstar/32/2248_2.png) [@interstar](https://discourse.processing.org/u/interstar)
#### Post date: [May 31, 2022, 2:29pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/9 "2022-05-31T14:29:18Z")

</div>

In fact here’s a complete sketch without any frames at all where P3D still seems to have this effect

```auto
String name = "Hello World";
size(812, 375, P3D);

background(0);
strokeWeight(4);

pushMatrix();
for (int j=0; j<20; j++) { 
  for (int i=0; i<20; i++) {
    fill(150, random(200), 30);
    stroke(150, random(200), 30);
    line(random(width), random(height), random(width), random(height));
  }
  filter(BLUR);
  rotate(j*0.4);
}
popMatrix();
fill(255, 255, 255, 255);
stroke(255, 255, 255, 255);
textSize(48);
text(name, 40, 100);

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [May 31, 2022, 11:26pm UTC](https://discourse.processing.org/t/text-drawing-seems-to-be-happening-out-of-order-compared-to-a-filter-blur/37224/10 "2022-05-31T23:26:36Z")

</div>

Hello,

See this in code:

```auto
// Either one of these work:
//hint(DISABLE_DEPTH_TEST);
translate(0, 0, 1)

```

Give this a try:

```auto
String name = "Hello World";
size(812, 375, P3D);

background(0);
strokeWeight(4);

pushMatrix();
for (int j=0; j<20; j++) { 
  for (int i=0; i<20; i++) {
    //fill(150, random(200), 30);
    stroke(150, random(200), 30);
    line(random(width), random(height), random(width), random(height));
  }
  filter(BLUR);
  rotate(j*0.4);
}
popMatrix();

// Either one of these work:
//hint(DISABLE_DEPTH_TEST);
translate(0, 0, 1);

fill(255, 255, 255, 255);
//stroke(255, 255, 255, 255);
textSize(48);
text(name, 40, 100);

```

I commented out some of the unnecessary color settings.

Reference:  
[https://processing.org/reference/hint\_.html](https://processing.org/reference/hint_.html)

`:)`
