why is this code crashing ?
in
Programming Questions
•
2 years ago
Hi all,
i am trying to have a second window (to display a preview of the main windows using FBO like explained here : http://processing.org/discourse/yabb2/YaBB.pl?num=1207160412/15 )
but the code is crashing : java JVM crashes with no message (i am on windows 7 32bits java 1.6_021 with nvidia video card)
the crash seems to be related to attaching the GLCanvas to the JFrame and displaying it. (displaying the windows without attaching the canvas to it, or not displaying the window seems not to crash).
any idea ?
henri
- import java.awt.Frame;
import javax.media.opengl.*;
import com.sun.opengl.util.FPSAnimator;
void setup(){
size(100,100,OPENGL);
PreviewFrame frame = new PreviewFrame();
}
void draw(){
}
public class PreviewFrame {
GLCanvas canvas;
public PreviewFrame() {
Frame f = new Frame("preview");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new GLRenderer());
f.add(canvas);
f.setSize(300, 300);
FPSAnimator animator = new FPSAnimator(canvas, 60);
animator.start();
f.setVisible(true);
}
class GLRenderer implements GLEventListener {
GL gl;
public void init(GLAutoDrawable drawable) {
this.gl = drawable.getGL();
gl.glClearColor(0, 0, 0, 0);
}
public void display(GLAutoDrawable drawable) {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
gl.glColor3f(random(1), random(1), random(1));
gl.glRectf(-0.8f, 0.8f, 50%random(100)/100f* -0.8f, 0.7f);
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
}
}
1