nchannon
asked on
Screen tearing with direct draw
Hi how do I synchronise my screen refresh rate with direct draw when I blit the back buffer to the primary surface so to get rid of the tearing effect on the screen
Thanks
Thanks
Assuming your using the DdFlip function, its one of the flags in the DD_FLIPDATA structure. DirectDraw has been the name for a few API's that might not be the one you're asking about.
ASKER
Hi No im not Flip I am using blit from back buffer to primary surface in a windows form not full screen
Hello again nchannon, always a enjoy your questions.
Gimme a clue, what variety of DirectDraw is this and what version of Windows? Are you not using DdFlip because that function doesn't exist in the DD in question?
Gimme a clue, what variety of DirectDraw is this and what version of Windows? Are you not using DdFlip because that function doesn't exist in the DD in question?
ASKER
Hi Im glad you enjoy my questions your answers have been very helpful in the past.
I am using DD version 7 running on XP.
No Im not using the Flip function m_pddsPrimary->Flip( NULL, DDFLIP_WAIT ) because im running in windowed view and have set lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL)
When I copy my backbuffer to the primary surface to display on the monitor I call this:
m_pddsPrimary->Blt(&rcDest , m_pddsBackBuffer, &rcSrc, DDBLT_WAIT, NULL); but I get this tearing effect due to the refresh rate from my monitor and the refresh rate from DD not being in sync
hope you can help me out with this.
I am using DD version 7 running on XP.
No Im not using the Flip function m_pddsPrimary->Flip( NULL, DDFLIP_WAIT ) because im running in windowed view and have set lpDD->SetCooperativeLevel(
When I copy my backbuffer to the primary surface to display on the monitor I call this:
m_pddsPrimary->Blt(&rcDest
hope you can help me out with this.
ASKER
Hi I think this is the solution to my tearing problem:
dd->WaitForVerticalBlank(D DWAITVB_BL OCKBEGIN, 0);
m_pddsPrimary->Blt(&rcDest , m_pddsBackBuffer, &rcSrc, DDBLT_WAIT, NULL);
if not ill post back
dd->WaitForVerticalBlank(D
m_pddsPrimary->Blt(&rcDest
if not ill post back
Yeah, you've got it, problem solved I think. Feel free to delete the question, I wont object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thats interesting, the two methods are waiting for the same event. Maybe WaitForVerticalBlank stops both cores or skips a frame?
I guess the most CPU efficient way to do this would be to have some kind of vertical blank callback, so that the program doesn't wait at all. You could get a decent approximation with a timer. Get it to trigger an event after 20 milliseconds, do the frame processing, wait for the vertical blank then wait another 20 milliseconds. That way the program would be idle some of the time.
On the plus side, the program is running 0.6%, if vertical blank takes it to 10%, that suggests it could do about 16 times as much work between each frame.
I guess the most CPU efficient way to do this would be to have some kind of vertical blank callback, so that the program doesn't wait at all. You could get a decent approximation with a timer. Get it to trigger an event after 20 milliseconds, do the frame processing, wait for the vertical blank then wait another 20 milliseconds. That way the program would be idle some of the time.
On the plus side, the program is running 0.6%, if vertical blank takes it to 10%, that suggests it could do about 16 times as much work between each frame.
ASKER
I found the solution my self