Java OpenGL window 一打开就关闭
Java OpenGL window closes as soon as it opens
我正在使用 maven 导入 jogamp 依赖项。
这里是pom.xml内容:
<dependencies>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
下面的代码应该创建一个 window。
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
public class Renderer {
private static GLWindow window = null;
public static void init(){
GLProfile.initSingleton();
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
window = GLWindow.create(caps);
window.setSize(640, 360);
window.setResizable(false);
window.setVisible(true);
}
public static void main(String[] args){
init();
}
}
在我的例子中,它创建了一个 window,它一打开就关闭,并显示 Process finished with exit code 0
。我遵循了 these instructions,但即使将 joal 和 jocl 支持添加到 maven 中也没有用。
你需要FPSAnimator
public static void init(){
GLProfile.initSingleton();
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
window = GLWindow.create(caps);
window.setSize(640, 360);
window.setResizable(false);
window.setVisible(true);
FPSAnimator animator = new FPSAnimator(window, 30);
animator.start();
}
我正在使用 maven 导入 jogamp 依赖项。
这里是pom.xml内容:
<dependencies>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
下面的代码应该创建一个 window。
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
public class Renderer {
private static GLWindow window = null;
public static void init(){
GLProfile.initSingleton();
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
window = GLWindow.create(caps);
window.setSize(640, 360);
window.setResizable(false);
window.setVisible(true);
}
public static void main(String[] args){
init();
}
}
在我的例子中,它创建了一个 window,它一打开就关闭,并显示 Process finished with exit code 0
。我遵循了 these instructions,但即使将 joal 和 jocl 支持添加到 maven 中也没有用。
你需要FPSAnimator
public static void init(){
GLProfile.initSingleton();
GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities caps = new GLCapabilities(profile);
window = GLWindow.create(caps);
window.setSize(640, 360);
window.setResizable(false);
window.setVisible(true);
FPSAnimator animator = new FPSAnimator(window, 30);
animator.start();
}