vertical tearing

BlitzMax Forums/BlitzMax Programming/vertical tearing

Grey Alien(Posted 2006) [#1]
Anyone know why this code produces vertical tearing (mouse the mouse left/right) in windowed mode and doesn't in full-screen mode? I know that flip 0 in full-screen mode will produce vertical tearing.

Graphics 800,600,0,0
'Graphics 800,600,32

While Not KeyHit(KEY_ESCAPE)
  Cls
  
  If KeyHit(KEY_SPACE) Then fix = 1 - fix
  
  mx = MouseX()
  my = MouseY() 
  
  DrawRect mx,my,200,200
  
  DrawText "Fix = " + fix, 12, 12
  
  Flip
Wend
End


If I set the last param of graphics to be 85 (my windows refresh rate) it's fine of course. This infers that setting Hz of 0 isn't using the default windows Hz but actually something else like 60! Am I misinterpreting what happens when you set the Hz flag to 0?


TartanTangerine (was Indiepath)(Posted 2006) [#2]
Windowed and Fullscreen actually have different Flip methods. Windowed mode performs the Flip by actually blitting the backbuffer to the front buffer, and that's another reason why it's slower.


Grey Alien(Posted 2006) [#3]
I see ... I think ...


skidracer(Posted 2006) [#4]
Using a hertz parameter of 0 seems to be completely undocumented so I am unsure how you are misinterpreting it's meaning.

For graphics to match the desktop refresh rate on windows try:

hz=GetDeviceCaps(GetDC(0),VREFRESH)


tonyg(Posted 2006) [#5]

Note the creating graphics with an unsupported refresh rate will not fail - instead, a default refresh rate will be used.


Isn't using a hertz of '0' the same as specifying an unsupported refresh rate?
There was LOTS of discussion about hertz and lots of theories but no final explanation IIRC.


Grey Alien(Posted 2006) [#6]
For graphics to match the desktop refresh rate on windows try:

hz=GetDeviceCaps(GetDC(0),VREFRESH)
that's great thanks, I'll try that as it seems a bit naff if windowed mode has tearing.

Tonyg: Yeah I read that same thing and saw people using 0. I guess maybe it does use a default refresh rate of 60Hz or someting BUT not the desktop default refresh rate. Really there ought to be an easy way of making a game window that matches the windows desktop refresh rate to avoid tearing.


Leiden(Posted 2006) [#7]
You can try forcing vsync on in your display properties. This prevents the tearing,


Dreamora(Posted 2006) [#8]
I would assume that you have VSync deactivated by default in your driver settings. In this case even flip true would not change anything. If it changes something, then you have default out, take application setting as VSync behavior set.


tonyg(Posted 2006) [#9]
guess maybe it does use a default refresh rate of 60Hz or someting

That was one of the theories. Mark explained that Bmax would select the best hertz for the monitor (i.e. the monitor setting) but, from other tests, it seemed to be taking the first setting (normally 60) on the possible refresh values for the monitor.


Grey Alien(Posted 2006) [#10]
Leiden and Dreamora: Actually I prefer vsync in my games so I have it set to "On, unless app specifies) The issue is not the graphics adapter but the fact that windows is running at a different Hz than the Max window which is flipping independently of the desktop Hz.

TonyG: That would explain it, so it's either picking 60Hz, which is the default Hz if you leave that flag out of Graphics, or the first available Hz setting (at chosen res and bit depth) after checking the card's possible display modes. However I don't think it's doing the second thing because I have an FPS counter in-game that is showing 60 and I know my video card can display at 56Hz in 800x600x32bit and my FPS counter would detect that (I think).


Yan(Posted 2006) [#11]
As far as I can make out, BMax only does soft syncing in windows mode (makes sense). A 'hertz' value of 0 makes BMax always do a 'Flip 1'. This means that you're really doing a 'Flip 0', hence the tearing.

Try this (again)...
Graphics 800, 600, 0, 15 'set 'hertz' To 0 And try not to blink

Local x#, y#
Local xv# = Rnd(-4, 4), yv# = Rnd(-4, 4)
Local flipVar = -1
Local refreshRate = GetDeviceCaps(GetDC(PrimaryDevice.hWnd), VREFRESH)

Repeat
	x# :+ xv#
	If (x# < 0) Or (x# > 799)
		xv# = -xv#
		x# :+ xv#
	EndIf 
	
	y# :+ yv#
	If (y# < 0) Or (y# > 599)
		yv# = -yv#
		y# :+ yv#
	EndIf
	
	If KeyHit(KEY_SPACE)
		flipVar :+ 1
		If flipVar > 1 Then flipVar = -1
	EndIf
	
	Cls
	DrawOval x# - 15, y# - 15, 30, 30
	
	DrawText "Flip = " + flipVar, 12, 12
	DrawText "Screen Refresh = " + refreshRate, 12, 24
	
	Flip flipVar
Until KeyHit(KEY_ESCAPE)

End



AntonyWells(Posted 2006) [#12]
What's up with all the moronic names lately? David the Donkey. Candy the camal. Ian the igunana.

Come on people. There are names that actually make sense and don't sound like the product of two year old's playtime.


Chris C(Posted 2006) [#13]
Oh I'm sooo tempted to change my nick to ChrisTheCrazyCameleon....


Yan(Posted 2006) [#14]
Is it because I'm making a satirical statement about the puerility of forum nicknames?

Is it, perhaps, because I haven't the inspired imagination to use the name of a film character or of a pointless spectacle?

Is it just because I can?

Who knows?


Grey Alien(Posted 2006) [#15]
Ian: Yes I see, with Hertz at 0, there is no difference in the 3 flip types.