我试图弄清楚如何在Raspberry Pi上使用OpenGL而不必启动X11。我发现https://www.raspberrypi.org/forums/viewtopic.php?f=81&t=73489指的是jogamp的NEWT框架http://jogamp.org/jogl/doc/NEWT-Overview.html。有一些示例应用程序,但大多数都非常复杂,我很难将它们提炼下来。
我有另一个JOGL 2.3.2 java应用程序在amd64 linux X windows中运行正常(尚未在Pi上尝试过)。它有像
这样的方法public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
// Enable VSync
gl.setSwapInterval(1);
gl.glShadeModel(GL2.GL_FLAT);
try {
attachShaders(gl);
} catch (Exception e) {
e.printStackTrace();
}
}
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
//....
}
public static void main(String[] args) {
JFrame jf = new JFrame();
jf.setSize(800,800);
jf.getContentPane().setLayout(new BorderLayout());
jf.getContentPane().add(new Pepper(), BorderLayout.CENTER);
jf.setVisible(true);
}
正如您所看到的,main
方法非常标准。它会创建一个JFrame
并使用此类扩展GLCanvas
填充它。
我想知道我应该编写什么样的main
例程来创建一个没有X11的NEWT的GLWindow
实例,然后使用我现有的类来display
在那个GLWindow上。如果相同的main
例程使用和不使用X11,则可以获得奖励。
答案 0 :(得分:0)
在amd64上的X11中工作的骨架是
public static void main(String[] argv)
throws InterruptedException
{
GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
caps.setBackgroundOpaque(true);
final GLWindow glWindow = GLWindow.create(caps);
glWindow.setSize(800,600);
glWindow.setVisible(true);
Pepper pepper = new Pepper();
glWindow.addGLEventListener(pepper);
Animator animator = new Animator(glWindow);
animator.start();
}
但是如果没有amd64上的X11,这将无效。
在Raspberry Pi上无头,它失败了
libEGL warning: DRI3: xcb_connect failed
libEGL warning: DRI2: xcb_connect failed
libEGL warning: DRI2: xcb_connect failed
Caught handled GLException: EGLGLXDrawableFactory - Could not initialize shared resources for EGLGraphicsDevice[type .egl, v0.0.0, connection decon, unitID 0, handle 0x0, owner true, NullToolkitLock[obj 0x14096e9]] on thread main-SharedResourceRunner
[0]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createSharedResource(EGLDrawableFactory.java:518)
[1]: jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:353)
[2]: java.lang.Thread.run(Thread.java:745)
Caused[0] by GLException: Failed to created/initialize EGL display incl. fallback default: native 0x0, error 0x3001/0x3001 on thread main-SharedResourceRunner
[0]: jogamp.opengl.egl.EGLDisplayUtil.eglGetDisplayAndInitialize(EGLDisplayUtil.java:297)
[1]: jogamp.opengl.egl.EGLDisplayUtil.access$300(EGLDisplayUtil.java:58)
[2]: jogamp.opengl.egl.EGLDisplayUtil$1.eglGetAndInitDisplay(EGLDisplayUtil.java:320)
[3]: com.jogamp.nativewindow.egl.EGLGraphicsDevice.open(EGLGraphicsDevice.java:125)
[4]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createEGLSharedResourceImpl(EGLDrawableFactory.java:532)
[5]: jogamp.opengl.egl.EGLDrawableFactory$SharedResourceImplementation.createSharedResource(EGLDrawableFactory.java:516)
[6]: jogamp.opengl.SharedResourceRunner.run(SharedResourceRunner.java:353)
[7]: java.lang.Thread.run(Thread.java:745)
Exception in thread "main" com.jogamp.opengl.GLException: Profile GL2 is not available on null, but: []
at com.jogamp.opengl.GLProfile.get(GLProfile.java:991)
at com.jogamp.opengl.GLProfile.get(GLProfile.java:1004)
at NewtPepper.main(NewtPepper.java:15)
在覆盆子pi的X11下,它失败了
libEGL warning: DRI2: failed to authenticate
Exception in thread "main" java.lang.InternalError: Available GLVersions not set for EGLGraphicsDevice[type .egl, v1.4.0, connection decon, unitID 0, handle 0x63488be8, owner true, NullToolkitLock[obj 0x16eb2ec]]
at com.jogamp.opengl.GLProfile.initProfilesForDeviceCritical(GLProfile.java:1952)
at com.jogamp.opengl.GLProfile.initProfilesForDevice(GLProfile.java:1875)
at com.jogamp.opengl.GLProfile.initProfilesForDefaultDevices(GLProfile.java:1842)
at com.jogamp.opengl.GLProfile.access$000(GLProfile.java:80)
at com.jogamp.opengl.GLProfile$1.run(GLProfile.java:230)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.opengl.GLProfile.initSingleton(GLProfile.java:216)
at com.jogamp.opengl.GLProfile.getProfileMap(GLProfile.java:2297)
at com.jogamp.opengl.GLProfile.get(GLProfile.java:988)
at com.jogamp.opengl.GLProfile.get(GLProfile.java:1004)
at NewtPepper.main(NewtPepper.java:15)