简体   繁体   English

如何在窗口失焦或调整大小时停止暂停OpenGL?

[英]How to stop OpenGL from pausing when the window is out of focus or resizing?

I'm trying to prevent my rendering from stopping when my window is out of focus or resizing. 我正试图阻止我的渲染在我的窗口失焦或调整大小时停止。 In addition to the resizing, if I resize my window smaller, then bigger again anything that wasn't visible when it was smaller is now black. 除了调整大小之外,如果我将窗口调整得更小,那么当它变小时,任何不可见的东西现在都变黑了。 Is there any way to fix this? 有没有什么办法解决这一问题?

There are really two distinct things going on here. 这里真的有两件不同的事情。 The moving/resizing problem is caused by the windows DefWindowProc function which applications use to handle messages that aren't explicitly handled by the application itself. 移动/调整大小问题是由Windows DefWindowProc函数引起的,应用程序使用它来处理未由应用程序本身显式处理的消息。 In the case of moving or resizing, it blocks, creating a new message queue to handle most messages, but there are a few that it will still dispatch to the application's main event queue, like WM_TIMER . 在移动或调整大小的情况下,它会阻塞,创建一个新的消息队列来处理大多数消息,但是有一些它仍然会分派到应用程序的主事件队列,如WM_TIMER You can find lots more information in this answer . 您可以在此答案中找到更多信息。

The second issue is that your program only "owns" the pixels inside your window, and only those that are not covered up by other windows. 第二个问题是你的程序只“拥有”窗口内的像素,只有那些没有被其他窗口遮盖的像素。 When you make the window smaller, the pixels at the edge need to be overwritten to show the window border or whatever's behind the window. 当您缩小窗口时,需要覆盖边缘处的像素以显示窗口边框或窗口后面的任何内容。 When the window is made bigger, some drivers automatically set the newly acquired pixels to black, while others leave them at whatever they were before (usually part of the window border). 当窗口变大时,一些驱动程序会自动将新获取的像素设置为黑色,而其他驱动程序则将它们留在以前的任何位置(通常是窗口边框的一部分)。 The OS doesn't remember if those pixels had some specific color the last time the window was that size, because most of the time the program doesn't care. 操作系统不记得那些像素在上次窗口大小时是否具有某种特定颜色,因为大多数时候程序并不关心。 Instead, windows sends a WM_PAINT message to indicate that the application should redraw the window. 相反,Windows发送WM_PAINT消息以指示应用程序应重绘窗口。 Your program should either directly handle this, or use a library like GLFW that abstracts it. 您的程序应该直接处理它,或者使用像GLFW这样抽象它的库。 In addition, you need to handle resize events by calling glViewport with the new size of the window. 此外,您需要通过使用窗口的新大小调用glViewport来处理resize事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否有可能以编程方式防止游戏在其 window 失去焦点时暂停? - Is it possible to programmatically prevent a game from pausing when its window loses focus? 停止 windows 在具有不同 DPI 的显示器之间切换时自动调整特定 window 的大小? - Stop windows from automatically resizing a specific window when it switches between monitors with different DPIs? 如何阻止Perl程序在完成后关闭窗口? - How to stop a Perl program from closing its window when it is finished? 双击时暂停批处理文件,但从控制台窗口运行时不暂停? - Pausing a batch file when double-clicked but not when run from a console window? 当滚动条可见时,停止浏览器调整网站大小 - Stop browser from resizing website when scrollbar is visible 当工作站锁定然后解锁时,如何防止窗口调整大小? - How do I prevent Window resizing when the Workstation is Locked then Unlocked? 移动/调整窗口大小时闪烁 - Flicker when moving/resizing window 如何停止启用 Windows 10 功能“对焦辅助”? - How to stop Windows 10 feature “focus assist” from being enabled? 如何防止窗口大小暂时调整? - How to prevent window resizing temporarily? 当窗口用户将焦点输入到输入区域时如何响应事件? - How to react event when window user enter focus into an input area?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM