synchronizing_20with_20video_20refresh
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
synchronizing_20with_20video_20refresh [2018/03/31 13:19] – external edit 127.0.0.1 | synchronizing_20with_20video_20refresh [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Synchronizing with video refresh===== | =====Synchronizing with video refresh===== | ||
- | //by Richard Russell, April 2007//\\ \\ //**(Note that the code in this article requires DirectX 7 or later).**// | + | //by Richard Russell, April 2007//\\ \\ //**(Note that the code in this article requires DirectX 7 or later).**// |
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
IF ddraw%=0 THEN ERROR 100, " | IF ddraw%=0 THEN ERROR 100, " | ||
Line 22: | Line 24: | ||
SYS `DirectDrawCreateEx`, | SYS `DirectDrawCreateEx`, | ||
!(^IDirectDraw{}+4) = !IDirectDraw% | !(^IDirectDraw{}+4) = !IDirectDraw% | ||
- | Here an error results if Direct Draw isn't available. In practice you may prefer not to issue an error but to fall back to using timers or the WAIT statement to set the frame rate. The animation will not be as smooth but at least your program will still run.\\ \\ The simplest way of achieving synchronization is to wait for the beginning of each video frame before updating your graphics output. To do that you can use code similar to the following (**do not use this method - see below**):\\ \\ | + | </ |
+ | |||
+ | Here an error results if Direct Draw isn't available. In practice you may prefer not to issue an error but to fall back to using timers or the WAIT statement to set the frame rate. The animation will not be as smooth but at least your program will still run.\\ \\ The simplest way of achieving synchronization is to wait for the beginning of each video frame before updating your graphics output. To do that you can use code similar to the following (**do not use this method - see below**): | ||
+ | |||
+ | <code bb4w> | ||
_DDWAITVB_BLOCKBEGIN = 1 | _DDWAITVB_BLOCKBEGIN = 1 | ||
REPEAT | REPEAT | ||
Line 28: | Line 34: | ||
PROCpaint | PROCpaint | ||
UNTIL FALSE | UNTIL FALSE | ||
- | Here it is assumed that your output will be updated in **PROCpaint**.\\ \\ Unfortunately there are a couple of shortcomings with this simple method. Firstly, the **WaitForVerticalBlank** function does not always work reliably. Secondly, it uses 100% CPU time while waiting for the next frame, which is undesirable (the importance of this will depend on how much time is spent ' | + | </ |
+ | |||
+ | Here it is assumed that your output will be updated in **PROCpaint**.\\ \\ Unfortunately there are a couple of shortcomings with this simple method. Firstly, the **WaitForVerticalBlank** function does not always work reliably. Secondly, it uses 100% CPU time while waiting for the next frame, which is undesirable (the importance of this will depend on how much time is spent ' | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
lastline% = 0 | lastline% = 0 | ||
Line 37: | Line 47: | ||
SYS " | SYS " | ||
UNTIL FALSE | UNTIL FALSE | ||
- | Again it is assumed that your output will be updated in **PROCpaint**. The call to **timeBeginPeriod** is to ensure that the **Sleep** function waits for the shortest possible (non-zero) period.\\ \\ This method may not result in as accurate synchronization as the previous one, but it avoids wasting CPU time and allows you to carry out low-priority ' | + | </ |
+ | |||
+ | Again it is assumed that your output will be updated in **PROCpaint**. The call to **timeBeginPeriod** is to ensure that the **Sleep** function waits for the shortest possible (non-zero) period.\\ \\ This method may not result in as accurate synchronization as the previous one, but it avoids wasting CPU time and allows you to carry out low-priority ' | ||
+ | |||
+ | <code bb4w> | ||
SYS IDirectDraw.Release%, | SYS IDirectDraw.Release%, | ||
+ | </ |
synchronizing_20with_20video_20refresh.1522502386.txt.gz · Last modified: 2024/01/05 00:16 (external edit)