getscanline for vertical sync

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5917
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

getscanline for vertical sync

Post 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  

User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Yes! Now let's hope this works on all machines and cards ;-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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.
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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
Last edited by Rescator on Tue Sep 02, 2008 5:41 am, edited 1 time in total.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
Post Reply