当我运行我的测试JOGL应用程序时,它表示根据OpenGl Extensions Viewer我的系统支持最多OpenGL 4.1 时,我在线程上只有GL2可用。
有没有人看到任何明显的原因为什么线程中只支持GL2?
我使用的是2015年中期的Macbook Pro,搭配Intel Iris和AMD Radeon R9显卡。
这是本书中的第一个练习[使用Java在OpenGL中进行计算机图形编程]。4
Java版:Java8
JOGL版本:2.3.2
GlueGen版本:2.3.2
import java.nio.*;
import javax.swing.*;
import static com.jogamp.opengl.GL4.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.common.nio.Buffers;
public class Code extends JFrame implements GLEventListener {
private GLCanvas myCanvas;
public Code() {
setTitle("Chapter 2 - program1");
setSize(600, 400);
setLocation(200, 200);
myCanvas = new GLCanvas();
myCanvas.addGLEventListener(this);
this.add(myCanvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void display(GLAutoDrawable drawable) {
GL4 gl = (GL4) GLContext.getCurrentGL();
drawable.setGL(new DebugGL4(gl));
float bkg[] = { 1.0f, 0.0f, 0.0f, 1.0f };
FloatBuffer bkgBuffer = Buffers.newDirectFloatBuffer(bkg);
gl.glClearBufferfv(GL_COLOR, 0, bkgBuffer);
}
public static void main(String[] args) {
new Code();
}
public void init(GLAutoDrawable drawable) {
GL4 gl = drawable.getGL().getGL4(); // This is where the code fails
String version = gl.glGetString(GL4.GL_VERSION);
String shaderversion = gl.glGetString(GL4.GL_SHADING_LANGUAGE_VERSION);
System.out.println("GLVERSION: " + version + " shading language: " + shaderversion );
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
public void dispose(GLAutoDrawable drawable) { }
}
例外:
/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/bin/java -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -classpath /private/var/folders/rd/tltb7sk928x_n429dyctdt8c0000gn/T/classpath1.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain Code
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Not a GL4 implementation on thread AWT-EventQueue-0
at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438)
at com.jogamp.opengl.Threading.invoke(Threading.java:223)
at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505)
at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
at sun.lwawt.LWRepaintArea.paintComponent(LWRepaintArea.java:59)
at sun.awt.RepaintArea.paint(RepaintArea.java:240)
at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314)
at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198)
at java.awt.Component.dispatchEventImpl(Component.java:4965)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.jogamp.opengl.GLException: Not a GL4 implementation
at jogamp.opengl.gl4.GL4bcImpl.getGL4(GL4bcImpl.java:40464)
at Code.init(Code.java:38)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:644)
at jogamp.opengl.GLDrawableHelper.init(GLDrawableHelper.java:667)
at com.jogamp.opengl.awt.GLCanvas$10.run(GLCanvas.java:1407)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1291)
... 30 more
Exception in thread "AWT-EventQueue-0" com.jogamp.opengl.GLException: Caught GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION ( 1282 0x502), on thread AWT-EventQueue-0
at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.opengl.awt.GLCanvas$12.run(GLCanvas.java:1438)
at com.jogamp.opengl.Threading.invoke(Threading.java:223)
at com.jogamp.opengl.awt.GLCanvas.display(GLCanvas.java:505)
at com.jogamp.opengl.awt.GLCanvas.paint(GLCanvas.java:559)
at com.jogamp.opengl.awt.GLCanvas.update(GLCanvas.java:866)
at sun.awt.RepaintArea.updateComponent(RepaintArea.java:255)
at sun.lwawt.LWRepaintArea.updateComponent(LWRepaintArea.java:47)
at sun.awt.RepaintArea.paint(RepaintArea.java:232)
at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1314)
at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1198)
at java.awt.Component.dispatchEventImpl(Component.java:4965)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: com.jogamp.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_OPERATION ( 1282 0x502),
at com.jogamp.opengl.DebugGL4bc.writeGLError(DebugGL4bc.java:31803)
at com.jogamp.opengl.DebugGL4bc.glActiveTexture(DebugGL4bc.java:232)
at jogamp.opengl.GLFBODrawableImpl.swapFBOImpl(GLFBODrawableImpl.java:471)
at jogamp.opengl.GLFBODrawableImpl.swapBuffersImpl(GLFBODrawableImpl.java:426)
at jogamp.opengl.GLDrawableImpl.swapBuffers(GLDrawableImpl.java:88)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1295)
... 31 more
Process finished with exit code 0
答案 0 :(得分:4)
事实证明,OSX回归到OpenGL 2.1,因此您需要自己设置核心配置文件。
$ glxinfo | grep OpenGL
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: AMD Radeon R9 M370X OpenGL Engine
OpenGL version string: 2.1 ATI-1.42.15
OpenGL shading language version string: 1.20
我可以通过将GLCapabilities传递给GLCanvas构造函数来设置核心版本(OpenGL 4.1)。
这是新的固定构造函数:
public Code() {
setTitle("Chapter 2 - program1");
setSize(600, 400);
setLocation(200, 200);
// This was the fix
GLProfile glp = GLProfile.getMaxProgrammableCore(true);
GLCapabilities caps = new GLCapabilities(glp);
myCanvas = new GLCanvas(caps);
myCanvas.addGLEventListener(this);
this.add(myCanvas);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
答案 1 :(得分:1)
要在Mac上运行本书的示例,我已在此网站上发出说明:http://athena.ecs.csus.edu/~gordonvs/errataMac.html
总之,您需要:
如果发现了更多的特质,我会将它们添加到网站上的说明中。