2012-02-11 78 views
0

好吧,我只是试图用GLFW打开一个基本窗口,并且它打开并清除为黑色时,它挂起并出现等待光标的圆圈。 GUI不可用,整个程序都冻结。OpenGL/GLFW:glfwOpenWindow挂(准系统应用程序)

任何帮助?

编辑有没有办法手动创建一个窗口,并有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

+0

你的主循环在哪里,这段代码进入你的程序有多远?此外,GLFW附带一些例子;你是否考虑从其中一个人那里学习? – 2012-02-11 00:19:53

+0

@NicolBolas - 增加了主要代码。是的,这几乎是从教程 – Qix 2012-02-11 00:25:49

回答

2

您必须在交换主循环背面和正面的帧缓冲区,就像这样:

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

为何冻结?

GLFW管理操作系统事件(比如刷新窗口,键按下得到的是,...)当你调用glfwSwapBuffers(通常情况下)。

+0

没有,仍悬挂c/p'd。 :C – Qix 2012-02-11 13:38:42

+0

不是,这是一个线程问题。显然OpenGL不是线程安全的。现在我发现了好东西,因为在开发早期很容易重新设计基本线程架构。 – Qix 2012-02-12 12:12:42

+0

所以是的,你是对的! – Qix 2012-02-12 12:13:06