7

我正在努力使用 GLFW 3 函数 glfwCreateWindow 创建一个窗口。我设置了一个错误回调函数,它几乎只是打印出错误号和描述,并且根据 GLFW 库尚未初始化,即使 glfwInit 函数刚刚返回成功?

这是我的代码的摘录

// Error callback function prints out any errors from GFLW to the console
static void error_callback( int error, const char *description )
{
    cout << error << '\t' << description << endl;
}


bool Base::Init()
{
    // Set error callback
    /*!
     *  According to the documentation this can be use before glfwInit,
     *  and removing won't change anything anyway
     */
    glfwSetErrorCallback( error_callback );



    // Initialize GLFW
    /*!
     *  This return succesfull, but...
     */ 
    if( !glfwInit() )
    {
        cout << "INITIALIZER: Failed to initialize GLFW!" << endl;
        return false;
    }
    else
    {
        cout << "INITIALIZER: GLFW Initialized successfully!" << endl;
    }



    // Create window
    /*!
     *  When this  is called, or any other glfw functions, I get a
     *  "65537    The GLFW library is not initialized" in the console, through
     *  the error_callback function
     */
    window = glfwCreateWindow( 800,
                               600,
                               "GLFW Window",
                               NULL,
                               NULL );


    if( !window )
    {
        cout << "INITIALIZER: Failed to create window!" << endl;
        glfwTerminate();
        return false;
    }


    // Set window to current context
    glfwMakeContextCurrent( window );


    ...


    return true;
}

这是控制台中打印的内容

INITIALIZER: GLFW Initialized succesfully!
65537    The GLFW library is not initialized
INITIALIZER: Failed to create window!

我认为我收到了错误,因为设置不完全正确,但我已经尽我所能在这个地方找到了最好的东西

我从 glfw.org 下载了 windows 32 并将其中的 2 个包含文件粘贴到 minGW/include/GLFW 中,将 2 个 .a 文件(来自 lib-mingw 文件夹)粘贴到 minGW/lib 和 dll 中,也来自 lib- mingw 文件夹,进入 Windows/System32

在我拥有的 code::blocks 中,从构建选项-> 链接器设置,链接了下载中的 2 个 .a 文件。我相信我需要链接更多的东西,但我可以弄清楚我应该从什么或从哪里得到这些东西。

4

2 回答 2

4

我尝试重新安装代码块和 mingw,解决了这个问题。

似乎 GLFW3 出于某种原因不喜欢同时安装以前的版本,所以如果其他人遇到类似的问题,您可能想尝试一下。

于 2013-07-03T16:51:29.267 回答
1

我在 Cocos 3.8.1 和 3.10 也遇到过类似的问题。我从未安装过代码块或 mingw,因此为我安装它们没有意义。

cocos 目录下的 GLFW.lib 文件已过期。

http://www.glfw.org/download.html,将项目中的lib文件替换为最新的,可能会解决你的错误。

于 2016-04-15T18:56:39.327 回答