GLFW 3初始化了,但不是吗?

时间:2013-06-29 15:33:28

标签: c++ opengl glfw

我正在努力创建一个带有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

在代码::块中,我有来自构建选项 - &gt;链接器设置,链接下载的.a文件。我相信我需要链接更多的东西,但我可以弄清楚什么,或者我应该从哪里得到这些东西。

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:1)

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

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

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