【问题标题】:LWJGL Operation != undefined for type boolean, intLWJGL 操作 != 布尔类型未定义,int
【发布时间】:2016-12-05 03:10:39
【问题描述】:

我正在学习有关 lwjgl 基础知识的教程。我目前正在尝试制作一个简单的窗口。但是我有两个问题。

在我的 init() 方法中我写了

if(glfwInit() != GL_TRUE){
     throw new IllegalStateException("Unable to initialize GLFW");
}

在我的 run() 方法中我写了

if(glfwWindowShouldClose(window) == GL_TRUE){
     running = false;
}

在这两种情况下我都会得到

Exception in thread "EndlessRunner" java.lang.Error: Unresolved compilation problem: 
The operator != is undefined for the argument type(s) boolean, int

at Main.init(Main.java:28)
at Main.run(Main.java:43)
at java.lang.Thread.run(Unknown Source)

但似乎所有教程都以一种或另一种方式使用这些行。

【问题讨论】:

    标签: java eclipse lwjgl glfw


    【解决方案1】:

    这些方法的 Java 声明与 C 声明并不完全相同,因此您需要调整代码以匹配 Java 声明。

    在这两种情况下,这些方法都返回一个boolean

    public static boolean glfwInit()
    
    public static boolean glfwWindowShouldClose(long window)
    

    所以你使用truefalse而不是GL_TRUEGL_FALSE来使用它们:

    if (glfwInit() != true) {
    
    if (glfwWindowShouldClose(window) == true) {
    

    注意:如果 Eclipse 显示您的代码中有错误,您将无法成功运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-28
      • 1970-01-01
      • 2017-06-04
      相关资源
      最近更新 更多