简体   繁体   English

在MAC OS下解决GLFW问题

[英]Getting Problems with GLFW under MAC OS

i have to run a java lwjgl game on a Mac but there are problems with GLFW. 我必须在Mac上运行java lwjgl游戏,但GLFW存在问题。

> Exception in thread "main" java.lang.ExceptionInInitializerError
at org.lwjgl.glfw.GLFW.glfwShowWindow(GLFW.java:1612)
at assignment7.windowmanager.Window.init(Window.java:65)
at assignment7.windowmanager.Window.start(Window.java:74)
at assignment7.windowmanager.Window.<init>(Window.java:35)
at assignment7.windowmanager.MyWindow.<init>(MyWindow.java:20)
at assignment7.MainGameLoop7.main(MainGameLoop7.java:14)

Caused by: java.lang.IllegalStateException: Please run the JVM with -XstartOnFirstThread. 引起:java.lang.IllegalStateException:请使用-XstartOnFirstThread运行JVM。 at org.lwjgl.system.macosx.EventLoop.(EventLoop.java:17) ... 6 more 在org.lwjgl.system.macosx.EventLoop。(EventLoop.java:17)... 6更多

this is my error code 这是我的错误代码

the implementation for the windows class: windows类的实现:

package assignment7.windowmanager;

import assignment7.entitites.Scene;
import assignment7.utilities.Input;
import org.lwjgl.opengl.GL;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;

import java.awt.Dimension;



/**
 * Created by Dennis Dubbert on 06.09.16.
 */
public abstract class Window {
    protected int   width, height;
    protected long  window;

    /*
     * In ScreenSize wird die Gr��e des aktuellen Bildschirms abgespeichert.
     * Daraufhin wird die initiale x- und y-Koordinate auf die Mitte des Bildschirmes gesetzt.
     * Da aber die linkere obere Ecke des Fensters zentriert w�re und nicht die Mitte dessen, 
     * wurde 320 von der x-Koordinate und 240 von der y-Koordinate abgezogen. (was der H�lfte des Fensters entspricht. Siehe MyWindow.java)
     */
    protected Dimension ScreenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    protected int xWindowPos = (int) ScreenSize.getWidth()/2 - 320;
    protected int yWindowPos = (int) ScreenSize.getHeight()/2 - 240;

    public Window(int width, int height) {
        this.width = width;
        this.height = height;
        start();
    }

    private void init(){
        if(glfwInit() != GL_TRUE){
            System.err.println("Could not initialize our glfw!");
            return;
        }

        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

        window = glfwCreateWindow(width, height, "assignment7", NULL, NULL);

        glfwSetWindowPos(window, 80, 30);


        if(window == NULL){
            System.err.println("Could not create our Window!");
            return;
        }




        Input.init(window, this);
        glfwMakeContextCurrent(window);
        //here is one Error
        glfwShowWindow(window);

        GL.createCapabilities();

        System.out.println("Your OpenGL version is " + glGetString(GL_VERSION));
        onInit();
    }

    public void start(){
        init();

        while(true){

            update();
            render();

            if(glfwWindowShouldClose(window) == GL_TRUE){
                break;
            }
        }

        glfwDestroyWindow(window);
        glfwTerminate();
    }

    private void update(){
        //here is an Error, too
        glfwPollEvents();
        onUpdate(glfwGetTime());
    }

    private void render(){
        if(Scene.getAmountOfCollisions() == 5){
            glfwDestroyWindow(window);
            glfwTerminate();
            System.exit(1);
        }
        onRender();
        glfwSwapBuffers(window);
    }

    public void moveWindowPos(int x, int y){

        /*
         * Um das leichte ruckeln zu entfernen k�nnte man statt einmal um 1 zu erh�hen/erniedrigen 10 mal um 0.1f erh�hen/erniedrigen.
         * Gedanke dahinter: die Taktrate der GPU ist um einiges Schneller als die einfache erh�hung um 1. 
         * Erste Idee (noch falsch!): 
         * if( x < 0 ){
            for(float i = x; i < 0; i++){
                glfwSetWindowPos(window, xWindowPos-=0.1f, yWindowPos);
                }
            }
        if( x > 0 ){
            for(float i = 0; i < x; i++){
                glfwSetWindowPos(window, xWindowPos+=0.1f, yWindowPos);
            }
        }
        if( y < 0 ){
            for(float i = y; i < 0; i++){
                glfwSetWindowPos(window, xWindowPos, yWindowPos-=0.1f);
            }
        }
        if( y > 0 ){
            for(float i = 0; i < y; i++){
                glfwSetWindowPos(window, xWindowPos, yWindowPos+=0.1f);
            }
        }
         */
                xWindowPos = xWindowPos+x;
                yWindowPos = yWindowPos+y;
                glfwSetWindowPos(window, xWindowPos, yWindowPos);

    }

    protected abstract void onInit();
    protected abstract void onUpdate(double currentTime);
    protected abstract void onRender();
    public abstract void onResize(int width, int height);
    public abstract void onKeyboard(float cursorPositionX, float       cursorPositionY, int pressedKey, int mods);
    public abstract void onMouse(float cursorPositionX, float cursorPositionY, int button, int action);

}

Maybe you can help me 也许你可以帮助我

From the error you posted above it seems like you just need to add -XstartOnFirstThread to the command you are using to run the program. 从上面发布的错误看来,您只需要将-XstartOnFirstThread添加到用于运行程序的命令中。 So it should be something like this. 所以它应该是这样的。

java -XstartOnFirstThread -jar executable.jar

If you are using an ide you will have to edit the run configuration to include this argument. 如果您使用的是ide,则必须编辑运行配置以包含此参数。

This error is occurring because your frame management must be done in the main thread of your application. 发生此错误是因为您的帧管理必须在应用程序的主线程中完成。 Also, be careful because a lot of the GLFW commands can only be called from the main thread. 另外,要小心,因为很多GLFW命令只能从主线程调用。 You can tell which ones this applies to in the documentation for each command (in the notes section). 您可以在每个命令的文档中(在注释部分中)确定这适用于哪些。 example

You just need to configure the Run Configuration in Eclipse, like this: 您只需要在Eclipse中配置Run Configuration,如下所示:

first choose the run configuration 首先选择运行配置

paste the -XstartOnFirstThread to the run argument 将-XstartOnFirstThread粘贴到run参数

then click run, you won't see this exception any more. 然后单击“运行”,您将不再看到此异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM