Understanding and using renderers

edited May 2017 in Questions about Code

Im not confident in my understandings of how graphics works. Saying that i want to use processing features to draw, use transformations for relatively simple GUI ecc... which would i choose between P2D P3D OPENGL ecc... Id like that every access to the application wouldnt be dependent on previous ones, so lets say how would one do the following?

I tried to write an exemplified test:

public class Test { public static void main(String[] args) { // TODO Auto-generated method stub JFrame f=new JFrame(); f.setBounds(0,0,1000,600); PApplet app=new TestApplet(); f.add(app); try{ app.init(); }catch(Exception e){ e.printStackTrace(); } f.show(); f.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { System.exit(0); } } ); } }

public class TestApplet extends PApplet {

public void init() {
    super.init();
    JTextField tf=new JTextField("test");
    JTextField tf2=new JTextField("test");
    JTextField tf3=new JTextField("test");
    JTextField tf4=new JTextField("test");
    JTextField tf5=new JTextField("test");
    JTextField tf6=new JTextField("test");
    this.setLayout(null);
    this.add(tf);
    this.add(tf2);
    this.add(tf3);
    this.add(tf4);
    this.add(tf5);
    this.add(tf6);
    tf.setBackground(new Color(255));
    tf2.setBackground(new Color(255));
    tf3.setBackground(new Color(255));
    tf4.setBackground(new Color(255));
    tf5.setBackground(new Color(255));
    tf6.setBackground(new Color(255));
    tf.setBounds(100, 50, 200, 20);
    tf2.setBounds(100, 150, 200, 20);
    tf3.setBounds(100, 250, 200, 20);
    tf4.setBounds(100, 350, 200, 20);
    tf5.setBounds(100, 450, 200, 20);
    tf6.setBounds(100, 550, 200, 20);
    size(950,550,P3D);
}

public void draw(){
    background(0);
    this.fill(255,0,0);
    clip(000,000,200,200);
    drawSomething(15);
    clip(400,400,200,200);
    drawSomething(32);
    noClip();
    rect(800,10,10,100);
    text("aaaaaaaa",500,50);
}

public void drawSomething(int depth){
       if(depth==0)return;
    this.pushMatrix();
    this.translate(depth, depth);
        this.rect(depth,depth,depth,depth);
        drawSomething(--depth);
        this.popMatrix();
}

}

First of i always get this on the size() instruction

Exception in thread "Animation Thread" processing.core.PApplet$RendererChangeException at processing.core.PApplet.size(PApplet.java:1785) at processing.core.PApplet.size(PApplet.java:1742) at ygg.view.TestApplet.init(TestApplet.java:38) at ygg.view.Test.main(Test.java:19)

Then i occasionally get:

java.lang.NullPointerException at processing.opengl.PJOGL.clearDepth(PJOGL.java:2404) at processing.opengl.PGraphicsOpenGL.backgroundImpl(PGraphicsOpenGL.java:5335) at processing.core.PGraphics.backgroundFromCalc(PGraphics.java:6983) at processing.core.PGraphics.background(PGraphics.java:6898) at processing.core.PApplet.background(PApplet.java:15122) at ygg.view.TestApplet.draw(TestApplet.java:42) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source)

and:

java.lang.NullPointerException at processing.opengl.PJOGL.enable(PJOGL.java:1640) at processing.opengl.PGraphicsOpenGL.clipImpl(PGraphicsOpenGL.java:2280) at processing.core.PGraphics.clip(PGraphics.java:1789) at processing.core.PApplet.clip(PApplet.java:11783) at ygg.view.TestApplet.draw(TestApplet.java:44) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source)

and:

Exception in thread "Animation Thread" java.lang.NullPointerException at processing.opengl.PJOGL.enable(PJOGL.java:1640) at processing.opengl.PGraphicsOpenGL.clipImpl(PGraphicsOpenGL.java:2280) at processing.core.PGraphics.clip(PGraphics.java:1789) at processing.core.PApplet.clip(PApplet.java:11783) at ygg.view.TestApplet.draw(TestApplet.java:44) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source) processing.core.PApplet$RendererChangeException at processing.core.PApplet.size(PApplet.java:1785) at processing.core.PApplet.size(PApplet.java:1742) at ygg.view.TestApplet.init(TestApplet.java:38) at ygg.view.Test.main(Test.java:19)

and: Exception in thread "Animation Thread" java.lang.NullPointerException at processing.opengl.PJOGL.getError(PJOGL.java:1700) at processing.opengl.PGraphicsOpenGL.report(PGraphicsOpenGL.java:5393) at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1705) at processing.core.PApplet.handleDraw(PApplet.java:2406) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source) processing.core.PApplet$RendererChangeException at processing.core.PApplet.size(PApplet.java:1785) at processing.core.PApplet.size(PApplet.java:1742) at ygg.view.TestApplet.init(TestApplet.java:42) at ygg.view.Test.main(Test.java:19)

or else no message at all(except on size).

i reproduced this on 50+ runs, closing old instances each time, even if multiple instances dont seem to cause more or less problems.

In this little code on contrary to the full one im using im seeing awt components only after minimizing and maximizing again, and they do have properties i wouldnt expect.

also i dindt recieve the too many pop message even if i stressed the depth to 32. normally i would get it sometimes randomly at beginning of code, maybe on 100+ run that would have happened also.

this behaviour is present on win7 ,2 machines using win10 and on a 32bit winXp (which is all i have tested with) both from eclipse environment(on win7 and win10) and runnable jars (even if the 2 show some differences in how much they tend to crash).

the application im actually using tends to work fine except the occasional crashes(at start and on a 20% prob.) and the awt/swing components are fine and well, and usually after a crash, many more are bound to occour subsequently.

The initial exception is enough to make me understand im getting something really wrong, the instruction seems to work tough? size and render are set.

the fail chance of this little code is rather depressing while the full application tend to work better and constented me to "ignore" the problem full extent for quite some time, suggesting me that something could be done to make this work.

How should one correctly embed a PApplet in a frame in order to avoid the first error? is there something that can be done to avoid the less frequent others?

Im sorry to not have bothered to include a minimal example before because if tought that some really big mistake could have already transpired in what i posted before

processing.core.PApplet$RendererChangeException at processing.core.PApplet.size(PApplet.java:1785) at processing.core.PApplet.size(PApplet.java:1742) at ygg.view.TestApplet.init(TestApplet.java:42) at ygg.view.Test.main(Test.java:19) Exception in thread "Animation Thread" java.lang.RuntimeException: Too many calls to popMatrix(), and not enough to pushMatrix(). at processing.opengl.PGraphicsOpenGL.popMatrix(PGraphicsOpenGL.java:3811) at processing.core.PApplet.popMatrix(PApplet.java:13322) at ygg.view.TestApplet.drawSomething(TestApplet.java:63) at ygg.view.TestApplet.drawSomething(TestApplet.java:62) at ygg.view.TestApplet.draw(TestApplet.java:49) at processing.core.PApplet.handleDraw(PApplet.java:2386) at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240) at processing.core.PApplet.run(PApplet.java:2256) at java.lang.Thread.run(Unknown Source)

did finally show up as i was writing right now.

Tagged:

Answers

Sign In or Register to comment.