[英]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.