gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:41:02 25 4
gpt4 key购买 nike

好吧,我只是想用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com