使用JOGL的Raspberry Pi上的LibGDX-运行时错误

codeday· 2019-11-20
本文来自 codeday ,作者 codeday
我正在尝试使用JOGL后端(https://github.com/gouessej/libgdx/)在Raspberry Pi 2上运行LibGDX桌面应用程序(一个简单的应用程序,显示图像,没有其他内容).

在当前的libgdx版本中,JoglApplicationConfiguration是抽象的,有两个子类:JoglAwtApplicationConfiguration和JoglNewtApplicationConfiguration.

当我尝试使用JoglAwtApplicationConfiguration来运行它时,出现错误:

 [java] glGetError 0x500
 [java] glGetError 0x500
 [java] JoglApplication: Couldn't initialize audio, disabling audio
 [java] java.lang.ExceptionInInitializerError
 [java]     at com.badlogic.gdx.backends.jogamp.JoglApplicationBase.<init>(JoglApplicationBase.java:54)
 [java]     at com.badlogic.gdx.backends.jogamp.JoglNewtApplication.<init>(JoglNewtApplication.java:49)
 [java]     at com.mygdx.game.desktop.DesktopLauncher.main(DesktopLauncher.java:14)
 [java] Caused by: com.jogamp.openal.ALException: Error opening default OpenAL device
 [java]     at com.jogamp.openal.util.ALut.alutInit(ALut.java:69)
 [java]     at com.badlogic.gdx.backends.jogamp.audio.OpenALAudio.<clinit>(OpenALAudio.java:41)
 [java]     ... 3 more
 [java] AL lib: (EE) ALCplaybackOSS_open: Could not open /dev/dsp: Nie ma takiego pliku ani katalogu
 [java] glGetError 0x500
 [java] Exception in thread "main-Animator#00" com.jogamp.opengl.util.AnimatorBase$UncaughtAnimatorException: com.jogamp.opengl.GLException: Caught NoSuchFieldError: gl on thread main-Animator#00
 [java]     at com.jogamp.opengl.util.DefaultAnimatorImpl.display(DefaultAnimatorImpl.java:61)
 [java]     at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:451)
 [java]     at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:198)
 [java]     at java.lang.Thread.run(Thread.java:724)
 [java] Caused by: com.jogamp.opengl.GLException: Caught NoSuchFieldError: gl on thread main-Animator#00
 [java]     at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
 [java]     at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1311)
 [java]     at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1131)
 [java]     at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:680)
 [java]     at com.jogamp.opengl.util.DefaultAnimatorImpl.display(DefaultAnimatorImpl.java:54)
 [java]     ... 3 more
 [java] Caused by: java.lang.NoSuchFieldError: gl
 [java]     at com.mygdx.game.MyGdxGame.render(MyGdxGame.java:21)
 [java]     at com.badlogic.gdx.backends.jogamp.JoglGraphicsBase.display(JoglGraphicsBase.java:164)
 [java]     at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:691)
 [java]     at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:673)
 [java]     at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:442)
 [java]     at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1277)
 [java]     ... 6 more
 [java] EGLDisplayUtil.EGLDisplays: Shutdown (open: 1)
 [java] EGLDisplayUtil: Open EGL Display Connections: 1
 [java] EGLDisplayUtil: Open[0]: 0x1: EGLDisplayRef[0x1: refCnt 2]

使用JoglNewtApplicationConfiguration时出现其他错误:

 [java] glGetError 0x500
 [java] glGetError 0x500
 [java] JoglApplication: Couldn't initialize audio, disabling audio
 [java] java.lang.ExceptionInInitializerError
 [java]     at com.badlogic.gdx.backends.jogamp.JoglApplicationBase.<init>(JoglApplicationBase.java:54)
 [java]     at com.badlogic.gdx.backends.jogamp.JoglAwtApplication.<init>(JoglAwtApplication.java:49)
 [java]     at com.mygdx.game.desktop.DesktopLauncher.main(DesktopLauncher.java:16)
 [java] Caused by: com.jogamp.openal.ALException: Error opening default OpenAL device
 [java]     at com.jogamp.openal.util.ALut.alutInit(ALut.java:69)
 [java]     at com.badlogic.gdx.bacAL lib: (EE) ALCplaybackOSS_open: Could not open /dev/dsp: Nie ma takiego pliku ani katalogu
 [java] kends.jogamp.audio.OpenALAudio.<clinit>(OpenALAudio.java:41)
 [java]     ... 3 more
 [java] Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: Creating window failed
 [java]     at com.badlogic.gdx.backends.jogamp.JoglAwtApplication.<init>(JoglAwtApplication.java:103)
 [java]     at com.mygdx.game.desktop.DesktopLauncher.main(DesktopLauncher.java:16)
 [java] Caused by: java.lang.reflect.InvocationTargetException
 [java]     at java.awt.EventQueue.invokeAndWait(EventQueue.java:1272)
 [java]     at java.awt.EventQueue.invokeAndWait(EventQueue.java:1247)
 [java]     at com.badlogic.gdx.backends.jogamp.JoglAwtApplication.<init>(JoglAwtApplication.java:101)
 [java]     ... 1 more
 [java] Caused by: java.lang.ClassCastException: com.jogamp.nativewindow.DefaultGraphicsConfiguration cannot be cast to com.jogamp.nativewindow.awt.AWTGraphicsConfiguration
 [java]     at com.jogamp.opengl.awt.GLCanvas.chooseGraphicsConfiguration(GLCanvas.java:1557)
 [java]     at com.jogamp.opengl.awt.GLCanvas.addNotify(GLCanvas.java:615)
 [java]     at java.awt.Container.addNotify(Container.java:2769)
 [java]     at java.awt.Window.addNotify(Window.java:770)
 [java]     at java.awt.Frame.addNotify(Frame.java:487)
 [java]     at java.awt.Window.pack(Window.java:807)
 [java]     at com.badlogic.gdx.backends.jogamp.JoglAwtApplication$1.run(JoglAwtApplication.java:63)
 [java]     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
 [java]     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
 [java]     at java.awt.EventQueue.access$200(EventQueue.java:103)
 [java]     at java.awt.EventQueue$3.run(EventQueue.java:694)
 [java]     at java.awt.EventQueue$3.run(EventQueue.java:692)
 [java]     at java.security.AccessController.doPrivileged(Native Method)
 [java]     at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
 [java]     at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
 [java]     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
 [java]     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
 [java]     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
 [java]     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
 [java]     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
 [java]     at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

使用两者,该应用程序构建良好,但是在我尝试运行它时出现错误.
有人能帮我吗?

我的应用程序代码(使用libgdx生成器生成):

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture img;

    @Override
    public void create () {
        batch = new SpriteBatch();
        img = new Texture("badlogic.jpg");
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(img, 0, 0);
        batch.end();
    }
}

和启动器类:

package com.mygdx.game.desktop;

import com.badlogic.gdx.backends.jogamp.*;
import com.mygdx.game.MyGdxGame;

public class DesktopLauncher {
    public static void main (String[] arg) {
        JoglNewtApplicationConfiguration config = new JoglNewtApplicationConfiguration();
        new JoglNewtApplication(new MyGdxGame(), config);
        // OR:
        //JoglAwtApplicationConfiguration config = new JoglAwtApplicationConfiguration();
        //new JoglAwtApplication(new MyGdxGame(), config);
    }
}
最佳答案
如果OpenAL初始化失败
“ AL lib:(EE)ALCplaybackOSS_open:无法打开/ dev / dsp:没有这样的文件或目录”
这源于libopenal声音库,
找不到您的树莓派声卡
那么您有三个选择:

A)为Pi的声卡加载OSS linux内核驱动程序

sudo modprobe snd_pcm_oss

B)禁用OpenAL软oss驱动程序:
编辑/etc/openal/alsoft.conf
并确保驱动程序列表包含-oss(它会禁用尝试使用不存在的dsp文件的OSS后端)

C)最好的解决方案是,如果OpenAL-soft项目可以检测到OSS后端不工作并使用其ALSA后端重试,但是这种解决方案将需要有人协作并修补上游的OpenAL-soft才能使OpenAl-soft工作在Raspberry Pi上开箱即用:http://kcat.strangesoft.net/openal.html