好吧所以我只是想用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
答案 0 :(得分:2)
您必须在主循环中交换后框架和前框架缓冲区,如下所示:
// Begin window loop
do
{
glfwSwapBuffers(); // <<<
} // Escape key or window closed
while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS
&& glfwGetWindowParam(GLFW_OPENED));
为什么会冻结?
当你拨打glfwSwapBuffers
(通常)时,glfw管理操作系统事件(,如刷新窗口,按下键,...... )。