c++ - OpenGL/GLFW : glfwOpenWindow hanging (barebones application)

标签 c++ opengl window glew glfw

好吧,我只是想用 GLFW 打开一个基本窗口,当它打开并被清除为黑色时,它挂起并出现圆圈等待光标。 GUI 不可用,整个程序就死机了。

有什么帮助吗?

编辑有没有办法手动创建一个窗口并将 glfw 附加到该窗口?

代码:

// Attempt to start up GLFW
        f1("Attempting to start up GLFW");
        if(!glfwInit())
        {
            e("Could not start up GLFW!");
            SetVError(V_ERR_OGL_GLFWINIT);
            return false;
        }

        // Create window hints
        f1("Setting window hints");
        glfwOpenWindowHint(GLFW_FSAA_SAMPLES, V_OGL_ANTIALIAS);
        glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want 4.0!
        glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
        glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

        // Create the window
        f1("Creating main window");
        if(!glfwOpenWindow(V_OGL_WINDOW_W, V_OGL_WINDOW_H, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
        {
            e("Could not create main window!");
            SetVError(V_ERR_OGL_WINDOW);
            return false;
        }

        // Attempt to start up Glew
        f1("Attempting to startup Glew");
        if(glewInit() != GLEW_OK)
        {
            // Error and return
            e("Could not instantiate Glew!");
            SetVError(V_ERR_OGL_GLEWINIT);
            return false;
        }

        // Set the window's title
        f1("Setting window title");
        glfwSetWindowTitle(V_WINDOW_TITLE);

        // Clear the screen / set BG color
        f1("Clearing background");
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

        // Lastly, setup basic sticky keys
        f1("Enabling sticky keys");
        glfwEnable(GLFW_STICKY_KEYS);

主要代码:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpComString, int nShowCmd)
{
    // Generate logger instance (instantiate logging)
    VLogInit();

    // Log Title + Version
    i("VOGL Test "V_FULLVERSION);

    // Init OpenGL/Graphics
    if(!OGLStartup())
        return GetLastVError();
    else // Log that we succeeded
        f1("OGLStartup succeeded!");

    // Fork thread for window events
    hMainWindow = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&tcbMainWindow, NULL, 0, thMainWindow);

    // Alloc statuc
    DWORD status;

    // Wait for all threads to return
    while(true)
    {
        // Main Window
        GetExitCodeThread(hMainWindow, &status);
        if(status != STILL_ACTIVE)
            break;

        // Sleep for a little bit
        Sleep(10);
    }

    // All okay!
    f1("Terminating Program");
    return V_SUCCESS;
}

DWORD tcbMainWindow(LPVOID lpdwThreadParam)
{
    // Begin window loop
    do
    {

    } // Escape key or window closed
    while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED));

    // Success!
    return V_SUCCESS;
}

是的,一切都正确记录。 http://pastebin.com/sQ2pw2wN

最佳答案

您必须在主循环中交换前后帧缓冲区,如下所示:

// Begin window loop
do
{
  glfwSwapBuffers(); // <<<
} // Escape key or window closed
while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS 
      && glfwGetWindowParam(GLFW_OPENED));

为什么会卡住?

当您调用 glfwSwapBuffers(通常)时,glfw 管理操作系统事件(如刷新窗口、按下的键......)。

关于c++ - OpenGL/GLFW : glfwOpenWindow hanging (barebones application),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9236593/

相关文章:

c++ - 带phong阴影和光线追踪的伪像

java - 纹理渲染不正确(OpenGL)

c++ - Cocoa 会限制 C/C++ openGL 应用程序的整体性能吗?

c++ - 设置 qt c++ mainwindow 始终在 mac osx 底部

c++ - ADO Recordset Field Value to C++ vector/array(捕获指针值)

c++ - 尝试编译包含 Root (Cern) 参数的 C++ 代码

c# - 如何在 C# 的进程中退出子窗口后访问主窗口句柄

angularjs - 让 Protractor 测试占据整个屏幕

c++ - 我可以返回一个 vector 以使用 C++11 扩展现有 vector 吗?

OpenGL - 选择性世界渲染