Sara
Sara

Reputation: 823

Screen Tearing when rendering using Windows API

I am trying to render an animation using Windows API. My problem is that half of the screen shows the previous frame, and the bottom half shows the current frame. I thought that this would be fixed when using a double buffer, but I have inserted

BitBlt(hdc, 0, 0, iWidth, iHeight, hdcMem, 0, 0, SRCCOPY);

which I understand is a double buffer, but the horizontal division still exists. How can I fix this?

Upvotes: 2

Views: 634

Answers (2)

Adrian McCarthy
Adrian McCarthy

Reputation: 48038

GDI BitBlt wasn't designed for rapid, continuous animation. Whether you get tearing or not may depend on your hardware and drivers.

There are other graphics APIs, like Direct2D and Direct3D (and the deprecated DirectDraw) which will let you synchronize to the vertical sync.

Upvotes: 2

Raymond Chen
Raymond Chen

Reputation: 45172

BitBlt is not synchronized to the vertical blank, so if you BitBlt to the screen at the same time the hardware is rendering to the display, it may tear. Double-buffering with BitBlt reduces the likelihood of tearing but does not eliminate it. To eliminate it, you need to do your BitBlt during the vertical blank period.

Upvotes: 6

Related Questions