Home > Enterprise >  Different rendering in the simulation or using saveFrame() using Processing in Intellij
Different rendering in the simulation or using saveFrame() using Processing in Intellij

Time:02-06

After many years with Processing IDE, I missed Intellij IDEA too much so I went back for it but Processing stays on :wink:

However, the shapes drawn are way less sharp than in the real PDE, for example, a simple circle is rendered differently using both time the latest version of Processing available 4.1.2, Java 17, the same PC and the same monitor :

In PDE :

public void setup() {
    size(500, 500);
}


public void draw() {
    background(40);
    noStroke();
    fill(255);
    circle(width/2, height/2, 400);
    saveFrame("./PDE.png");
    noLoop();
}

and the result is :

saveFrame() or direct view using Processing IDE

With Intellij however :

import processing.core.PApplet;

public class Main extends PApplet {

    public void settings() {
        size(500, 500);
    }


    public void draw() {
        background(40);
        noStroke();
        fill(255);
        circle(width/2, height/2, 400);
        saveFrame("Intellij IDEA.png");
        noLoop();
    }
    public static void main(String... args) {
        Main pt = new Main();
        PApplet.runSketch(new String[]{"testRendering"}, pt);
    }
}

the saveFrame() is exactly the same as with Processing IDE but the real view in the sketch is :real view in the sketch with Intellij

I guess that it is a problem of renderer but I can't change it using fullScreen(P2D) for example because it throws errors. The only solution I found were using Maven but I am not so I'd rather find a solution for my problem.

CodePudding user response:

This problem arises because the window is being scaled (according to windows scaling settings) but its content is not rendered in a higher resolution (hence the "jaggies").

It's a problem only with the default (Java AWT) renderer. To fix it:

  • Call System.setProperty("sun.java2d.uiScale", "1") before PApplet.runSketch() -- this will prevent the window from being scaled.

An alternative solution is to use the JavaFX renderer (size(500, 500, FX2D)), which seems to behave correctly (the content renders at a higher resolution).

If however high DPI scaling is not desired with the FX2D renderer, you can call System.setProperty("prism.allowhidpi", "false")to disable it.

  • Related