I keep getting this error when I try to run this skeletal code. I am trying to work with OpenGL in Eclipse. I can't figure out what is causing this problem. How can I fix this? I have added the jar files to the user library as well.
CODE:
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import java.lang.Math;
import javax.swing.JFrame;
class ThirdGLEventListener implements GLEventListener {
/**
* Interface to the GLU library.
*/
private GLU glu;
/**
* Take care of initialization here.
*/
public void init(GLAutoDrawable gld) {
GL2 gl = gld.getGL().getGL2();
glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
gl.glViewport(-250, -150, 250, 150);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(-250.0, 250.0, -150.0, 150.0);
}
/**
* Take care of drawing here.
*/
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
/*
* put your code here
*/
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
}
public void displayChanged(GLAutoDrawable drawable,
boolean modeChanged, boolean deviceChanged) {
}
public void dispose(GLAutoDrawable arg0){
}
}
public class Trial423Class{
public static void main(String args[]){
//getting the capabilities object of GL2 profile
final GLProfile profile=GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities=new GLCapabilities(profile);
// The canvas
final GLCanvas glcanvas=new GLCanvas(capabilities);
ThirdGLEventListener b=new ThirdGLEventListener();
glcanvas.addGLEventListener(b);
glcanvas.setSize(400, 400);
//creating frame
final JFrame frame=new JFrame("Basic frame");
//adding canvas to frame
frame.add(glcanvas);
frame.setSize(640,480);
frame.setVisible(true);
}
}
THIS IS THE ERROR I KEEP GETTING.
ERROR: error1
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 1 at jogamp.opengl.windows.wgl.awt.WindowsAWTWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationImpl(WindowsAWTWGLGraphicsConfigurationFactory.java:171) at com.jogamp.nativewindow.GraphicsConfigurationFactory.chooseGraphicsConfiguration(GraphicsConfigurationFactory.java:424) at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1560) at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:611) at java.desktop/java.awt.Container.addNotify(Container.java:2804) at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839) at java.desktop/java.awt.Container.addNotify(Container.java:2804) at java.desktop/javax.swing.JComponent.addNotify(JComponent.882 13246945888:4839) at java.desktop/java.awt.Container.addNotify(Container.java:2804) at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839) at java.desktop/javax.swing.JRootPane.addNotify(JRootPane.java:729) at java.desktop/java.awt.Container.addNotify(Container.java:2804) at java.desktop/java.awt.Window.addNotify(Window.java:791) at java.desktop/java.awt.Frame.addNotify(Frame.java:495) at java.desktop/java.awt.Window.show(Window.java:1053) at java.desktop/java.awt.Component.show(Component.java:1728) at java.desktop/java.awt.Component.setVisible(Component.java:1675) at java.desktop/java.awt.Window.setVisible(Window.java:1036) at Trial423Class.main(Trial423Class.java:65)
It's a library bug. Update the library.
Good catch, thank you.
This typo was introduced with my commit:
commit 0a6a592c04a85d8124aa9d38b67f0caa1d739b75 Date: Fri Dec 10 05:24:32 2010 +0100
now fixed via commit
commit d335d99df25cc929d06765c3f1af3944f124f6a7 Date: Mon Jun 15 01:21:44 2020 +0200 Fix 'typo' in branching, valid config index is >= 0 (not < 0) This issue was introduced in commit 0a6a592c04a85d8124aa9d38b67f0caa1d739b75 and the '2nd choice branch' obviously never tested. Thanks to Lathanda finding this issue on 6/14/20.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.