似乎LWJGL 3.0.0-SNAPSHOT已经可用了,所以我不得不选择LWJGL 3.0.0。但是,对我来说,看起来Mac二进制文件已经坏了。
我使用以下脚本下载了本机,这些脚本过去一直在使用。唯一改变的是:
<lwjgl.version>3.0.0SNAPSHOT</lwjgl.version> -> <lwjgl.version>3.0.0</lwjgl.version>
的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Meltdown</groupId>
<artifactId>Bitflip</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Bitflip</name>
<properties>
<lwjgl.version>3.0.0</lwjgl.version>
<!--<lwjgl.version>3.0.0-SNAPSHOT</lwjgl.version>-->
<swt.version>4.5.1</swt.version>
<joml.version>1.8.0</joml.version>
<class>game.SpaceGame</class>
<source>1.8</source>
<target>1.8</target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<profiles>
<profile>
<id>mac</id>
<activation>
<os>
<family>Mac</family>
</os>
</activation>
<dependencies>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl-platform</artifactId>
<version>${lwjgl.version}</version>
<classifier>natives-osx</classifier>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.cocoa.macosx.x86_64</artifactId>
<version>${swt.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>res</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.lwjgl.demo.${class}</mainClass>
</transformer>
</transformers>
<finalName>lwjgl3-demos</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>oss.sonatype.org</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>swt-repo</id>
<url>http://maven-eclipse.github.io/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.joml</groupId>
<artifactId>joml</artifactId>
<version>${joml.version}</version>
</dependency>
<dependency>
<groupId>org.lwjgl</groupId>
<artifactId>lwjgl</artifactId>
<version>${lwjgl.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
为了确保我在LWJGL的网页上运行示例代码进行了测试:link to src
package org.gooeybits.meltdown.alt;
import org.lwjgl.Version;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
public class Test {
// The window handle
private long window;
public void run() {
System.out.println("Hello LWJGL " + Version.getVersion() + "!");
try {
init();
loop();
// Free the window callbacks and destroy the window
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
} finally {
// Terminate GLFW and free the error callback
glfwTerminate();
glfwSetErrorCallback(null).free();
}
}
private void init() {
// Setup an error callback. The default implementation
// will print the error message in System.err.
GLFWErrorCallback.createPrint(System.err).set();
// Initialize GLFW. Most GLFW functions will not work before doing this.
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
// Configure our window
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable
int WIDTH = 300;
int HEIGHT = 300;
// Create the window
window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create the GLFW window");
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
glfwSetWindowShouldClose(window, true); // We will detect this in our rendering loop
});
// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
// Center our window
glfwSetWindowPos(
window,
(vidmode.width() - WIDTH) / 2,
(vidmode.height() - HEIGHT) / 2
);
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);
// Make the window visible
glfwShowWindow(window);
}
private void loop() {
// This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the GLCapabilities instance and makes the OpenGL
// bindings available for use.
GL.createCapabilities();
// Set the clear color
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window); // swap the color buffers
// Poll for window events. The key callback above will only be
// invoked during this call.
glfwPollEvents();
}
}
public static void main(String[] args) {
new Test().run();
}
}
我还设置了以下VM选项:
-XstartOnFirstThread
-Djava.awt.headless=true
下载了以下本机二进制文件(Maven):
libglfw.dylib
libjemalloc.dylib
liblwjgl.dylib
libopenal.dylib
编译和运行项目时,它会正常执行,不会出现警告/错误或异常。唯一缺少的是窗口。我试过全屏和独立。但没什么。
我的问题是,你能看到我做过的任何奇怪的事情,或者你有类似的事情吗?
更新:此通话永不返回。
window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
答案 0 :(得分:0)
解决。
我卸载了CUDA驱动程序和JDK。重新启动并安装了Java 8 build 91,而不是build 92.
它有效。但是我仍然不知道我的CUDA安装是否有问题,或者它是否是JDK。
但如果有人遇到类似问题,请试一试。
java -cp .:./jar/*:./native -Djava.library.path=./native/ -Dorg.lwjgl.util.Debug=true -XstartOnFirstThread HelloWorld
Hello LWJGL 3.0.0 build 90!
[LWJGL] Version: 3.0.0 build 90
[LWJGL] OS: Mac OS X v10.11.5
[LWJGL] JRE: 1.8.0_91 x86_64
[LWJGL] JVM: Java HotSpot(TM) 64-Bit Server VM v25.91-b14 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL] Loaded from java.library.path: ./native/liblwjgl.dylib
[LWJGL] ThreadLocalUtil state: UnsafeState
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] Loading library: glfw
[LWJGL] Loaded from java.library.path: ./native/libglfw.dylib
[LWJGL] Loading library: objc
[LWJGL] Loaded from java.library.path: ./native/libobjc.dylib
[LWJGL] Loading library: /System/Library/Frameworks/OpenGL.framework
[LWJGL] Success