Page 1 of 1

getscanline for vertical sync

Posted: Sun Aug 31, 2008 2:30 am
by idle
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.


Code: Select all


IDD.IDirectDraw7                 

If OpenLibrary(0,"ddraw.dll")
  If CallFunction(0,"DirectDrawCreateEx",0,@IDD.IDirectDraw7,?IID_IDirectDraw7,0) <> 0
    MessageRequester("Warning:","Couldn't init DirectDraw",0)
    End
  Else
    bopen = #True
  EndIf
Else
  MessageRequester("Warning:","Couldn't init DirectDraw",0)
  End
EndIf

;****************** the business

If bopen
   line.w
   ret = IDD\GetScanLine(@line)
EndIf

;*******************

IDD\Release() 

;*****************

DataSection
  IID_IDirectDraw7:
    Data.l $15e65ec0
    Data.w $3b9c, $11d2
    Data.b $b9, $2f, $00, $60, $97, $97, $ea, $5b
EndDataSection  


Posted: Sun Aug 31, 2008 10:30 am
by blueznl
Yes! Now let's hope this works on all machines and cards ;-)

Posted: Sun Aug 31, 2008 3:16 pm
by SFSxOI
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?

Posted: Sun Aug 31, 2008 4:39 pm
by blueznl
Hmmm it is, but for now it will do until Fred & team fixes FlipBuffers().

I'm pretty sure by the time this call is gone, he'll have it done :-)

First question that comes to mind: does this function still exisit under Vista?

Posted: Sun Aug 31, 2008 8:36 pm
by SFSxOI
"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.

Posted: Mon Sep 01, 2008 1:00 am
by Demivec
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.

Posted: Tue Sep 02, 2008 5:26 am
by Rescator
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).

Code: Select all

#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

Posted: Tue Sep 02, 2008 5:31 am
by Rescator
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.

Posted: Tue Sep 02, 2008 5:43 am
by Rescator
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.

Posted: Tue Sep 02, 2008 8:01 am
by Rescator
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.