The issue of dynamic flickering of light and dark in the screen when using Direct2D for rendering

sas asa 0 信誉分
2024-07-27T10:57:35.3466667+00:00

I'm learning to use Direct2D to draw some graphics. However, during each drawing process, the screen first becomes darker, then slightly brighter after the drawing stabilizes and remains unchanged. So every time a drawing occurs, the screen appears to flicker once. In this context, each drawing refers to the process starting from context->BeginDraw() and ending with swapchain->Present().

Some experiments and known information:

  1. Currently, I am using D2D device context for rendering. When I previously used hwndrendertarget for drawing, there was no issue of flickering on the screen.

It is noteworthy that, theoretically, only one frame is rendered during each draw cycle, but the screen first dims and then brightens, resulting in two distinct changes. The dimming seems to occur even before the begindraw() and enddraw() calls complete, and before the present() function finishes.

If the subsequent drawing processes are connected fast enough, the screen remains relatively dim. Once there are no further drawing processes, the screen returns to a brighter state and remains so until the next drawing process initiates, causing the screen to dim again.

I attempted to remove ValidateRect from the WM_PAINT message handler in my program. This time, the screen no longer flickered, but it caused the program to continuously consume significant GPU and CPU resources, even though no user interaction was taking place and no animations were being played on the screen.

  1. The resources used for drawing, along with their parameters, are essentially the same as those in the official examples.When using the color 0x1e4a56, you are more likely to observe this flickering.
Windows API - Win32
Windows API - Win32
一组适用于桌面和服务器应用程序的核心 Windows 应用程序编程接口 (API)。 以前称为 Win32 API。
78 个问题
{count} 票