GLFW-无需使用循环而保持窗口
GLFW - hold window without using loop
为了使结果打开(窗口屏幕),我必须执行以下操作:
while (glfwGetWindowParam(GLFW_OPENED))
{
// do some stuff
glDrawPixels(...);
glfwSwapBuffers();
}
但是,这个循环穿过时循环的主体,直到我停止它。我不想实时渲染。
glfw具有等效于SDL_WAITEVENT:
SDL_Surface* screen;
// do something with screen
SDL_Flip(screen);
SDL_Event event;
while (SDL_WaitEvent(&event))
{
// handle input
}
如果我尝试执行这样的操作,则该程序会呈现结果,但是过了一会儿就停止响应:
//do stuff
glDrawPixels(...);
glfwSwapBuffers();
while (glfwGetWindowParam(GLFW_OPENED))
{
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
{
glfwTerminate();
}
}
您的典型GLFW主应用循环可能看起来像这样:
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
update();
draw();
glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
输入可以通过回调(例如键盘输入回调)来处理。我使用包装程序类来处理我的glfw东西,所以创建一个窗口后,我会做这样的事情:
glfwSetWindowUserPointer(window, this);
glfwSetKeyCallback(window, glfwKeyCallback);
和我的键盘回调看起来像这样:
void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
GlfwApp * instance = (GlfwApp *) glfwGetWindowUserPointer(window);
instance->onKey(key, scancode, action, mods);
}
和onkey方法的基类实现如下:
void GlfwApp::onKey(int key, int scancode, int action, int mods) {
if (GLFW_PRESS != action) {
return;
}
switch (key) {
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, 1);
return;
}
}
您可以在这里和这里看到整个班级。
glfw3具有glfwWaitEvents
,可能会做您想要的。
http://www.glfw.org/docs/latest/group__window.html#ga554e3781f0a997656b26b26b2c56c56c56c56c835e
而不是使用glfwgetWindowParam()我认为您可能想考虑使用glfwwindowshouldclose()。它采用指向GLFW窗口的指针。这是指向具有GLFWWINDOWSHOUNDCLOSE()http://www.glfw.org/docs/latest/group/group__window.html
相关文章:
- 如何循环打印顶点结构
- 如何在C++中从两个单独的for循环中添加两个数组
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 正在尝试了解输入验证循环
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 在包含窗口标头时难以解决循环依赖关系问题
- 使用 while 循环时不显示窗口
- 使用 QLinkedList 循环浏览不同的窗口屏幕
- 如何设计窗口渲染循环
- 如何在C++循环中创建形状并将其附加到窗口
- GLFW-无需使用循环而保持窗口
- 当窗口聚焦时,OpenGL程序不会循环
- Qt-如何在不使用插槽的情况下检测自定义事件循环中的关闭窗口
- GDI 窗口中的游戏循环/一段时间后不刷新并崩溃
- 将游戏服务器线程循环限制为 30FPS,而无需游戏引擎/渲染窗口
- 是否可以捕获翻译/调度消息循环中的窗口消息/事件
- C++ WTL8.1 如何在具有消息循环的新线程中创建窗口
- 在窗口循环中,在窗口控件上获取鼠标移动比子类化更容易
- 在Qt窗口中运行游戏循环
- 当消息循环在另一个线程上时,等待窗口关闭