this will return the vertical scan line without any performance hit.
I haven't got the time to implement a solution but I'm sure those of you are pulling your hair out trying to find a way to do tear free drawing will figure it out.
considering that direct draw is depreciated for windows isn't there another way to do this that will still work with future versions instead of just today?
the code doesn't work in Vista, it runs but never does anything and the messagerequester never comes up to complain, and the value of ret is always 0. I don't think direct draw is fully supported in Vista, there is a ddraw.dll in Vista though. I don't think this exists any longer in the DirectX SDK for March 2008.
SFSxOI wrote:"does this function still exisit under Vista?"
the code doesn't work in Vista, it runs but never does anything and the messagerequester never comes up to complain, and the value of ret is always 0. I don't think direct draw is fully supported in Vista, there is a ddraw.dll in Vista though. I don't think this exists any longer in the DirectX SDK for March 2008.
From the research I've been doing regarding this method, I think using DirectX3D is the more up-to-date way of doing it.
Seems to work fine here. (Vista Home Premium x86)
Just added some more lines of code to show the line. (I hope the ret<>0 part is correct, didn't check just assumed).
#DD_OK=0
#DDERR_VERTICALBLANKINPROGRESS=39
#DDERR_UNSUPPORTED=42
#DDERR_INVALIDPARAMS=87
#DDERR_INVALIDOBJECT=88
IDD.IDirectDraw7
If OpenLibrary(0,"ddraw.dll")
If CallFunction(0,"DirectDrawCreateEx",0,@IDD.IDirectDraw7,?IID_IDirectDraw7,0)<>0
MessageRequester("Warning:","Couldn't init DirectDraw")
End
Else
bopen = #True
EndIf
Else
MessageRequester("Warning:","Couldn't init DirectDraw")
End
EndIf
;****************** the business
If bopen
line.w
ret = IDD\GetScanLine(@line)
If ret<>#DD_OK
Select ret
Case #DDERR_VERTICALBLANKINPROGRESS
MessageRequester("ScanLine:","Vertical blank is in progress.")
Case #DDERR_UNSUPPORTED
MessageRequester("ScanLine:","Action not supported.")
Case #DDERR_INVALIDPARAMS
MessageRequester("ScanLine:","One or more of the input parameters is invalid.")
Case #DDERR_INVALIDOBJECT
MessageRequester("ScanLine:","DirectDraw received a pointer that was an invalid DirectDraw object.")
EndSelect
Else
MessageRequester("ScanLine:",Str(line))
EndIf
EndIf
;*******************
IDD\Release()
;*****************
DataSection
IID_IDirectDraw7:
Data.l $15e65ec0
Data.w $3b9c, $11d2
Data.b $b9, $2f, $00, $60, $97, $97, $ea, $5b
EndDataSection
Last edited by Rescator on Tue Sep 02, 2008 5:41 am, edited 1 time in total.
MicroSoft Windows SDK wrote:IDirectDraw::GetScanLine
The GetScanLine method returns the scan line that the monitor is currently updating to the display.
Syntax
HRESULT GetScanLine(
LPDWORD lpdwScanLine
);
Parameters
lpdwScanLine
Points to the DWORD that will contain the scan line the display is currently on.
Return Values
Value Description
DD_OK The method succeeded.
DDERR_INVALIDOBJECT DirectDraw received a pointer that was an invalid DirectDraw object.
DDERR_INVALIDPARAMS One or more of the input parameters is invalid.
DDERR_UNSUPPORTED Action not supported.
DDERR_VERTICALBLANKINPROGRESS Vertical blank is in progress.
Updated my code in post 7 to include the DD error constants and handling.
#DDERR_VERTICALBLANKINPROGRESS might be "usefull" in your program as that is when the display driver is performing the vertical blank (flipping buffers I assume?)
Otherwise DD_OK means it is between vertical blanks.
Anything else than those two are an actual error obviously.
Just stumbled over some mention on the net that GetScanLine may not work on all hardware. (not sure which drivers/cards do not support this, might explain your issue SFSxOI.
Also, under Vista tearing and vblank is not a real issue any more.
Just decide on a framerate for your project and update at those intervals,
only flip buffers when you actually have updated the graphics etc. XP will always have issues, and I'm not sure what happens on Vista if you turn off Aero but I suspect it will behave just like XP in that case. But with Vista Aero the tearing should be history.