Problem with executable file and full screen mode

Blitz3D Forums/Blitz3D Beginners Area/Problem with executable file and full screen mode

Rooster(Posted 2015) [#1]
I have run in to a problem with the executable file the game I'm making when I run it in full screen. What happens is the game will run just fine except it flickers really bad, as in give you a seizure bad. It's just fine in windowed mode.

So does anyone know what might cause this?


Matty(Posted 2015) [#2]
Have you set the backbuffer()?

If it is rendering to the frontbuffer this will happen.


Rooster(Posted 2015) [#3]
Yes, it's set to backbuffer.


Matty(Posted 2015) [#4]
You will have to post some code that reproduces this problem then.


Rooster(Posted 2015) [#5]
I just tried to do that by copying the bb file and striping away all the unnecessary code.
But for some reason the executable from the copy wasn't flickering, even with out deleting anything. But then the next few executable I made started flickering again, and it keeps going back and forth.

So I'm starting to think it's not my code (which I don't believe I changed), and something to do with the way I'm converting it to a exe file.

Sorry if that was confusing.


Floyd(Posted 2015) [#6]
So I'm starting to think it's not my code (which I don't believe I changed), and something to do with the way I'm converting it to a exe file.


In that case try one of the samples included with Blitz3D, such as \samples\mak\castle\castle.bb

You might have to change the Graphics3D command to full screen. I don't remember how it is set in the original example.

Then create an exe in whatever way seems to be causing you problems. Does that work properly? If yes then how does the code differ from yours.


Bobysait(Posted 2015) [#7]
According to what I understand from your problem, use Flip (True) instead of Flip (False)
What you're seeing is the tearing screen effect. (and if it does not happen in windowed mode, it makes me feel you're under win 10/8)

This problem has been discussed a few times in the past days, you 'll maybe find what you're looking for in the last topics from <Blitz3d Programming> section.


steve_ancell(Posted 2015) [#8]
In addition to what Bobysait just said, have you made sure you're not in debug mode?


Rooster(Posted 2015) [#9]
I forgot to say that I'm using 2D graphics, so sorry for any confusion that may have caused.
I been playing around with the code a little more today, and I found that lowering the frame rate seems to fix it. But then that leaves my game running at 15/20 fps instead of 30.

I also made a smaller program that dose the almost the same thing(the flickering looks a little different) .


Global img

Graphics 640,480,0,1

 img = LoadImage ("test1.png") 

 SetBuffer BackBuffer () 

 game_timer =CreateTimer (100)

While Not KeyDown (1)

 Cls 

 For t= 10 To 500 Step 10
  DrawImage img,t,240

 Next

 Flip (1)

 WaitTimer (game_timer)

Wend

End


This and my game run just fine from blitz3d but have flickering problems when running from a exe file.

So is this a speed problem, and if so how would I about fixing it?

and thanks for all the help so far. :)


steve_ancell(Posted 2015) [#10]
Try swapping the following to lines around:

img = LoadImage ("test1.png")

SetBuffer BackBuffer ()


Rooster(Posted 2015) [#11]
Switching them didn't seem to help any.


steve_ancell(Posted 2015) [#12]
OK, try putting the graphics command above the img global.


steve_ancell(Posted 2015) [#13]
This seems to work, if an image moving across the screen is what you were after.


Global img

Graphics 640,480,0,1

img = LoadImage ("test1.png") 

SetBuffer BackBuffer () 

game_timer =CreateTimer (100)

While Not KeyDown (1)
	
	For t= 10 To 500 Step 10
		Cls
		DrawImage img,t,240
		Flip(1)
		
	Next
	
	WaitTimer (game_timer)
	
Wend

End



Rooster(Posted 2015) [#14]
No, the for/next loop was for creating multiple images on the screen. But that made me think about why I was doing that, and after a little bit of testing I found that I could get the same results as with my game if I used bigger image(6272/2320 pixles).
Now the map for the game is 3000 by 450, so could it be the size of the images I'm using is causing the problem? If so then what is a safe size?


Matty(Posted 2015) [#15]
Is 640x480 even supported properly by your graphics card/os these days?


Rooster(Posted 2015) [#16]
Well it seems to run just fine for me. The actual game is 800x600 though.


Bobysait(Posted 2015) [#17]
@steve_ancell :
You can't debug with random order just to see what happens ...

	For t= 10 To 500 Step 10
		Cls
		DrawImage img,t,240
		Flip(1)
		
	Next

This will just clear the screen after every image drawn.


Try swapping the following to lines around:

img = LoadImage ("test1.png")

SetBuffer BackBuffer ()


This won't do anything at all.
An image is loaded into memory, there is nothing related to the current buffer


OK, try putting the graphics command above the img global.


A global declaration is just a global declaration, while there is no initialization, it won't change anything.

I'm sorry but, whatever you might want to help, you're just leading to a very wrong way.


@Rooster :
If you cumulate WaitTimer and Flip(true) it will be hard to get syncrhonization on your timer if its framerate is higher than your screen rate, and the next flip can even miss the screen blank on the loop and will have to wait for a second vertical blank to draw on screen.


steve_ancell(Posted 2015) [#18]
@Bobysait:
On the global and swapping around thing, I think I was getting mixed up with loading images before setting the Graphics command. I wasn't quite with it yesterday and haven't used Blitz3D for quite some time, I use Monkey-X most of the time now.

I was unclear about what Rooster was trying to achieve, hence what I did in the For/Next loop.

@Rooster:
Could you let us know are you trying to get this part of your program to do?, it might help us all get to the bottom of it if we knew what you're trying to achieve. ;)


steve_ancell(Posted 2015) [#19]
Matty:
Is 640x480 even supported properly by your graphics card/os these days?


Rooster:
Well it seems to run just fine for me. The actual game is 800x600 though.


I always do something along the lines of this to get around the oversize/undersize issues, all you need to do is multiply your image widths and heights with scaleX and scaleY respectively and then resize your images bases on the resulting floats. Also multiply those same variables with your drawing positions, this should make them remain consistant across different screen sizes when you deploy any games you make.


Global deviceWidth# = GraphicsWidth()
Global deviceHeight# = GraphicsHeight()
Global desiredWidth# = 800
Global desiredHeight# = 600
Global scaleX# = (deviceWidth# / desiredWidth#)
Global scaleY# = (deviceHeight# / desiredHeight#)




[edit]Also set a boundary. Use that to prohibit the drawing of an image when it is fully outside the drawable area, this will speed things up when there's a lot going on.[/edit]


Rooster(Posted 2015) [#20]
@Bobysait
I just tried commenting out WaitTimer to see if it had any effect on the problem, but that just made it worse. Not sure if that it what you meant in your last post. It also reminded me that the placement of Flip and Cls seemed to have some effect on the severity of the flickering.

@steve_ancell
The code I posted was supposed to reproduce the problem that I'm having(but using one big image works better[edit] reproduces the problem better[/edit]).
It is kind of like what the main loop for my game would be like with out all the extra code that doesn't effect the problem in it (the For/Next loop was just there to put multiple images out there, but as I said one big image works better).


steve_ancell(Posted 2015) [#21]
You could even draw those multiple images to one big image buffer and then draw that buffer to the screen, although I think it might be a bit slow on some machines.


Rooster(Posted 2015) [#22]
Huh? I'm sorry that just went over my head.


steve_ancell(Posted 2015) [#23]
You said you get better results with drawing one image at render time. If you wanted to draw multiple images you can draw them to an image buffer after creating it with CreateImage then setting the drawing buffer to that buffer.

The idea would be, after drawing to the created image buffer, to switch drawing to the back buffer, drawing the image buffer and then flip the screen. That's kind of how stuff is done in Java but I'm not sure if Blitz3D would benefit from that same method.

Did that make it any clearer?. I'm better at doing things rather than explaining them, I guess that's why I never became a school teacher. LOL


steve_ancell(Posted 2015) [#24]
This might explain it better, it theoretically only spams an image once to the screen after it's had graffiti drawn to it.

Let us know if it works without flickering.


Graphics 800, 600
SetBuffer BackBuffer()


Global canvas = CreateImage(GraphicsWidth(), GraphicsHeight())
Global squares = LoadImage("squares.png")


Repeat
	SetBuffer ImageBuffer(canvas)
	Cls
	DrawSquares()
	
	SetBuffer BackBuffer()
	DrawImage(canvas, 0, 0)
	
	Flip
	
Until KeyHit(1)
End




Function DrawSquares()
	Local column, row
	
	
	
	For row = 0 To 4
		For column = 0 To 4
			DrawImage(squares, ImageWidth(squares) * column, ImageHeight(squares) * row)
			
		Next
		
	Next
	
End Function



[edit] I just went back to change something, I hope this works. ;) [/edit]
[edit] I also forgot to mention, the image I used is a 100x100 pixel 4-coloured square. [/edit]


Rooster(Posted 2015) [#25]
Oh! Now i see. Now what I was trying to say back there was that the bigger image replicated the issue better (same pateran of flickering, and working at a lower frame rate than the other example I gave), not that the flickering was reduced.

Sorry for the confusion.


steve_ancell(Posted 2015) [#26]
OKies, no problem, I'm sure you'll get there in the end. ;)


steve_ancell(Posted 2015) [#27]
Do any of the Blitz3D examples produce a flicker on the operating system that you're using?.


Rooster(Posted 2015) [#28]
Never mind my last post steve (I was working on that when you posted the code.), because it looks like your code stopped the problem. :D
It even works when I increased the For/Next loops up to 0 to 20.
So I think this case is closed. :) If not I'll be back here(given my luck).

Many thanks to everyone for helping me with this!


steve_ancell(Posted 2015) [#29]
OKies Rooster, no worries. ;)