如何修复加载纹理错误?

时间:2016-11-27 21:48:01

标签: eclipse textures jogl opengl-2.0

我正在研究GL2,有一个函数(来自学校)加载纹理:

bookTex = loadTexture(gl, "wattBook.jpg");

private Texture loadTexture(GL2 gl, String filename) {
    Texture tex = null;
    try {
      File f = new File(filename);
      BufferedImage img = ImageIO.read(f); // read file into BufferedImage
      ImageUtil.flipImageVertically(img);
      tex = AWTTextureIO.newTexture(GLProfile.getDefault(), img, false);
      // Different filter settings can be used to give different effects when the texture
      tex.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
      tex.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
    }
    catch(Exception e) {
      System.out.println("Error loading texture " + filename); 
    }
    return tex;
}

然而,它总是抛出异常:(它有太多错误行,所以我只是复制前面行)

*Error loading texture wattBook.jpg
Exception in thread "main-FPSAWTAnimator#00-Timer0" com.jogamp.opengl.util.AnimatorBase$UncaughtAnimatorException: java.lang.RuntimeException: com.jogamp.opengl.GLException: Caught NullPointerException: null on thread AWT-EventQueue-0
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:92)
    at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
    at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.RuntimeException: com.jogamp.opengl.GLException: Caught NullPointerException: null on thread AWT-EventQueue-0
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:201)
    at com.jogamp.opengl.Threading.invokeOnOpenGLThread(Threading.java:202)
    at com.jogamp.opengl.Threading.invoke(Threading.java:221)
    at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505)
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
    ... 4 more*

我在Mac上的Eclipse上运行它,并且已经设置了GL环境。有人可以解释这个错误以及如何解决它?谢谢!

0 个答案:

没有答案