java - 无法在 ubuntu 上为 eclipse 设置 lwjgl

标签 java linux eclipse ubuntu-14.04 lwjgl

嘿,我正在尝试在 ubuntu 上为 eclipse 设置 lwjgl,我遇到了一些问题需要帮助我已经将 lwjgl jar 添加到构建路径并将其指向 native 文件夹但是当我尝试运行提供的测试代码时没有运气在网站上我得到这个错误

enter image description here

这是代码

import org.lwjgl.*;
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 HelloWorld {

// 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 HelloWorld().run();
}

}

项目层次结构图

enter image description here

并构建路径图像

enter image description here

最佳答案

LWJGL 需要 Java 8 或更高版本的最新夜间构建版本。您下载的 jar 是使用 JDK 8 编译的,它使用了 Java 7 JRE 不支持的文件格式版本。

在 Ubuntu 上,您可以安装 openjdk-8-jdk 包,但如果您使用的是 Ubuntu 14.04,则必须使用 PPA 或替代包,因为 OpenJDK 8 is not available there .

关于java - 无法在 ubuntu 上为 eclipse 设置 lwjgl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37285113/

相关文章:

java - 我在循环时程序跳过第一个输入时遇到问题。请帮忙

linux - 昨天的scp文件

c - cat 命令中的 "-u"选项有什么用?

c++ - 我的 Xlib 包装器类 (C++) 中的段错误

java - android定时器异常onResume

java - 文件系统交互异常: Could not access target file while using documents4j

java - 从 Eclipse 解密保存的密码

java - 如何在 Eclipse 中为开发模式设置 MySQL + Tomcat + GWT

java - android列出 Assets 子目录文件的权限

java - 滑动拼图,开关图标