2

I have a C/C++ MFC application where a moving image from left to right displays with StretchDIBits in a window. And the screen tearing happens in the window.

Please understand I am not talking about flickering but screen tearing as flickering is more like whole screen blinking while screen tearing causes some scattering part of the image not synchronized when the image moves to right or left so that a moving vertical line temporarily looks broken one in a very short period of time.

At first, I thought StretchDIBits was the cause but changing it to SetDIBitsToDevice didn't help at all. So I am suspecting it's GDI and googling about it supported my doubt.

I saw this article to fix the problem but it'd be cleaner to directly use DirectX in my opinion.

So at this point, I am thinking about using DirectX or OpenGL to prevent this tearing but not sure if this approach will work or if there is any better approach. So my question is

  • Would going with OpenGL or DirectX solve this problem?
  • Is there any better approach than going with OpenGL and DirectX?

Any clue will be appreciated.

To save time, please don't recommend not to use MFC as this is one of the requirements.

Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
  • 1
    It seems the resources you've already found describe the problem well and offer a solution, so what's your question? GDI was never designed to be synchronized with the video output as displaying moving images is outside of its scope. – Mark Ransom May 19 '14 at 17:39
  • @MarkRansom Thanks for your comment. As I said, I wondered if there is any better approach than going with DirectX or OpenGL. You can say that about GDI but moving the image up and down in GDI still works without the tearing. So I hope this is not an unreasonable question to ask. – Tae-Sung Shin May 19 '14 at 17:49
  • 1
    Yes, Direct3D and OpenGL are the only technologies that allow to remove/reduce image tearing. Some modern display adapters/drivers don't have such problems at all, but there are still a lot of computers where image tearing is observed. – Alex F May 19 '14 at 17:54
  • @AlexFarber Thanks for your comment. So do you mean, for example, changing graphics card to better one would solve this problem even with GDI? – Tae-Sung Shin May 19 '14 at 17:57
  • Yes. On one of my computers I had two Win7 partitions (the same computer, the same display adapter). In one of these partitions there was no image tearing, even if GDI program redraws the whole window with white/black color 30 times per second. – Alex F May 19 '14 at 18:01
  • I didn't have time to investigate this better, but I kmow for 100%, that some Win7 computers just don't have this problem. probably it is solved on the kernel level. – Alex F May 19 '14 at 18:03
  • @AlexFarber I can look into it. Thanks! – Tae-Sung Shin May 19 '14 at 18:04

0 Answers0