first frame of sequence not displaying with Flip 1

BlitzMax Forums/BlitzMax Beginners Area/first frame of sequence not displaying with Flip 1

GreenVertical(Posted 2013) [#1]
Hi
I am fairly new to blitzmax and still finding my feet. I am having a bit of an issue with my code in that the first drawn frame is never shown on screen. The issue only occurs when I use Flip 1 (it draws all the frames when Flip 0 or Flip -1 is used). I must be misunderstanding something about the way Flip 1 works but I don't understand why this should make a difference in this case?

I have given a highly simplified minimal example of my code below to illustrate the problem I am having....



The code is meant to show three things in succession. With this code the red rectangle is never drawn but the green and blue rects are. With Flip set to 0 -all three are seen. I get the same behaviour on both my computers so I don't think it is a graphics card issue. Is the first 'flip' never actually rendered when you use Flip 1?
many thanks in advance.

GreenVertical


Floyd(Posted 2013) [#2]
I can't tell you why this is happening, but a workaround seems simple enough. If you want to use Flip 1 then throw in a superfluous one at the start.

Graphics 800,600,0,10 

Flip 1

For frame=1 To 3
Cls
	Select frame
	Case 1
		SetColor(255,0,0) 'red
		DrawRect(100,100,80,20)
	Case 2
		SetColor(0,255,0) 'green
		DrawRect(300,100,80,20)
	Case 3
		SetColor(0,0,255) 'blue
		DrawRect(500,100,80,20)
	End Select
	Flip 1
	Delay 1000
Next
End



Midimaster(Posted 2013) [#3]
This is not the style FLIPs are used in games, better do this:

Graphics 800,600,0,10 
FPS%=CreateTimer(60)
FrameTime%=0
Repeat
	If FrameTime<Millisecs()
		FrameTime=Millisecs()
		frame=frame+1
	Endif
	Cls
	Select frame
		Case 1
			SetColor(255,0,0) 'red
			DrawRect(100,100,80,20)
		Case 2
			SetColor(0,255,0) 'green
			DrawRect(300,100,80,20)
		Case 3
			SetColor(0,0,255) 'blue
			DrawRect(500,100,80,20)
		case 4
			End
		End Select
	Flip 0
	WaitTimer FPS
Until KeyHit(Key_Escape)


The main loop should flip every 1/60msec, also if nothing happens. Move a second window fast over your game window to see the difference. In your sample the screen will be destroyed after removing the window. The second sample shows a "stabil" screen.


col(Posted 2013) [#4]
Hiya,

@Midimaster
The OP said it works ok with Flip 0 and/or Flip -1 but not with Flip 1. Sure enough if you change the code to Flip 1 the same bug appears.

@GreenVertical
Detailed explaination:-
On a Windows system the default graphics driver is DirectX9. DirectX9 internals ( therefore Max2D DirectX9 internals too ) are unnecessarily complicated with how the display is setup to refresh with or without vertical sync. The 'bug' happens because when Max2D first initialises the display adapter and its Max2D graphics subsystem it uses a Flip 0 to flip the screen as fast as possible a couple of times to ensure that DirectX9 is setup and ready to go. This therefore sets up DirectX9 to use a specific refresh rate with the display device. As you are using Flip 1 then you want to change the refresh rate which means resetting the internals of DirectX. This 'reset' takes one frame within the Max2D system, hence why you don't see the very first frame in your code.

The only work-around is as Floyd suggested, or you could use the OpenGL graphics driver ( which doesn't suffer the same internal complications but may have others issues. These are not Max2D issues but DirectX and OpenGL issues ) by using

SetGraphicsDriver GLMax2DDriver()

before you use the Graphics([...]) command.


GreenVertical(Posted 2013) [#5]
Excellent! Thanks col -the SetGraphicsDriver GLMax2DDriver() command solves the problem.
Thanks also Midimaster - I will tweak the logic of my program flow in light of your suggestion.