我正在使用GLFW,所以用OpenGL设置一个Window.由于我刚刚开始学习OpenGL及其周围的所有内容,这可能听起来像一个愚蠢的问题,但为什么GLFW的示例程序在Window未被主动显示时使用接近100%的CPU(最小化或被另一个窗口隐藏) )?
这是GLFW的例子,我在Mac OS上使用Xcode运行它:
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
if (!glfwInit()) /* Initialize the library */
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
der*_*ass 10
无论窗口的最小化状态是什么,都会执行渲染循环.
如果要停止渲染,则必须稍微调整应用程序逻辑以跟踪窗口所处的状态.GLFW支持用户定义的回调,glfwSetWindowIconifyCallback()
以便在窗口最小化或恢复时注意到应用程序.您可以决定停止渲染循环,并可以使用glfwWaitEvents()等待某些事情发生(如正在恢复的窗口)而不使用所有可用的CPU时间.
| 归档时间: |
|
| 查看次数: |
1907 次 |
| 最近记录: |