(Silly) Flip question

BlitzMax Forums/BlitzMax Beginners Area/(Silly) Flip question

Pierrou(Posted 2010) [#1]
Hi!

I am working on some sort of educational game, so the interface I wrote is quite basic, as well as the display (using Max2D, in Windowed Mode) and until now my limited skills allowed me to get what I wanted. In that game, the graphics are updated when something happens, which may be a big mistake, I don't know, but which is working perfectly until now on any Windows PC I could test it.

That was for the Windows version of the game. Yesterday I got my hands on a Mac and tried to compile the game to see what happens.

The game is more or less working, which is somewhat magic in itself (thanks Blitz) but the Flip command doesn't seem to act the same way on Windows and on Mac. On Windows, when I use Drawimage something, then Flip, then drawimage something else, then flip again, what I get is 2 layers, the second being displayed on top of the first one. On Mac, the same code leads to some ugly flickering as if the images were swapped all the time. I guess I could fix it by cleaning the code and using flip in a better way, but can someone explain why do those two computers act so differently?

Sorry if the question is silly or simply too vague, and thanks very much in advance,
Pierre


Czar Flavius(Posted 2010) [#2]
Hi.

You probably have some kind of main game loop? If you could post it here, it would help pin-point the problem.

:)


Pierrou(Posted 2010) [#3]
I do but showing it would be like to receive you at home with old pizza boxes and dirty clothes all over the floor. :)

I guess I can fix it with some work but I would still be wondering why I had to change it to get it to work...

Thank you for your answer, I will try to post some readable code later.


Sledge(Posted 2010) [#4]
I guess I could fix it by cleaning the code and using flip in a better way
It's not a silly question at all but do fix it, not to use Flip in a better way but to use it in the 'proper' way. Draw everything that needs to be drawn, flip, clear the new backbuffer and repeat...

but can someone explain why do those two computers act so differently?
You're not guaranteed that the backbuffer will be left intact after a flip. Different drivers manage things differently -- try enough different Windows systems and you'll probably find similar behaviour to the Mac eventually.


Pierrou(Posted 2010) [#5]
I think I get it. So getting a Mac version that works should make the Windows version better too. Let's go back to work :(
Thank you very much!

EDIT : ...Tell me if I'm getting it right : Flip is meant to update the whole display at a time. Everything I want to see on the screen must be drawn before flipping...?


Sledge(Posted 2010) [#6]
Flip is meant to update the whole display at a time. Everything I want to see on the screen must be drawn before flipping...?

Yep -- that's it in a nutshell.


Pierrou(Posted 2010) [#7]
That's what I will do then. Thanks again!


xlsior(Posted 2010) [#8]
The issue is that *some* video cards / drivers clear the backbuffer automatically, and others don't. Some use 2, 3 or even 4 backbuffers, which means if you keep flipping without redrawing your background may go back three or four frames in time.

The OpenGL specifications state that you can make no assumptions on the state of the backbuffer -- you're going to have to redraw the entire screen each frame to make sure that it works on -all- computers.

You're going to run into a host of problems otherwise: if may work flawless on one computer, but a different graphics cards or even different driver version can cause chaos on another PC.


Czar Flavius(Posted 2010) [#9]
Your main game loop should look something like this:

While (Not KeyDown(KEY_ESCAPE)) And (Not AppTerminate())
    '...some code here to control timing if desired...

    UpdateLogic()

    Cls
    DrawStuff()
    Flip

    Delay 1 'gives better multitasking performance, as a slight pause lets the OS know you've completed your work
Wend



Pierrou(Posted 2010) [#10]
Thanks a lot for the tips. I hope displaying all that stuff everytime won't get too slow (it was OK speedwise until now without wondering too much about optimization). @ Czar Flavius : I should have done it that way from the beginning but was too lazy to change my bad habits. :(


Pierrou(Posted 2010) [#11]
Hello
Me again!

I think I understand everything above and can't do anything but agree with it but here's something strange, at least for me.

I had written another game before, for French speech and language therapists (that's my daily job, and as you can see I'm far from being able to become a professional developer :) ). It was a commercial game, a few hundreds or maybe more (!) copies have been sold and to my knowledge none of the buyers complained about it, although it was coded even more badly than the new piece of soft I'm working on. At the time (last year) I compiled a MacPPC and a MacIntel version on a friend's Mac, both seemed to work OK with no display issue. When I compile THE VERY SAME CODE on my own Mac, today, the display is messy and flickering as it is on my new game whereas the game compiled a few months ago on my friend's Mac still works perfectly well... I tried to compile it with various Blitzmax versions from version 1.30 on but it didn't seem to change anything.

Does someone have a clue? Now I know I coded it all in a very amateurish and bad way, but until now it seemed to work on any PC/Mac... And it still does when I run last year's executables...

Thanks in advance,


_Skully(Posted 2010) [#12]
on MAC you need to use Flip True otherwise you get tearing... i recall a previous conversation about this.


Pierrou(Posted 2010) [#13]
Thank you! I'll try to remember that (at the moment it does'nt seem to change anything however)


Calibrator(Posted 2010) [#14]
Pierrou,

I can't help you with the subject at hand (learning BMax myself...) but:

I had written another game before, for French speech and language therapists (that's my daily job, and as you can see I'm far from being able to become a professional developer :) ). It was a commercial game, a few hundreds or maybe more (!) copies have been sold

You are a professional developer in *my* book!


Pierrou(Posted 2010) [#15]
:)

Indeed I've earned some money and had to pay some taxes out of that. But when I'm over with this half bad new project I'm working on I promise I'll do things in a cleaner way, I might gain some time eventually that way.


Pierrou(Posted 2010) [#16]
Do you think there is a chance that the trouble I'm in has something to do with the version of XCode installed on the computer (it's the only difference I can see apart from the machines themselves, between last year's compilation and this year's compilation) or not?


xlsior(Posted 2010) [#17]
Try recompiling the modules?
At least that way everything has consistently be compiled against the same version of xcode, and you're not mixing & matching things.


Pierrou(Posted 2010) [#18]
I'm talking about two (probably) different issues in this topic, which might eventually become confusing. In the latest posts I mentioned the very strange fact that the same code compiled with the same version of Blitzmax on two different machines lead to different resultats, one perfect and one 100% messy. I'm talking about my first piece of soft.

I can't remember which version of XCode was used last year to compile the version of the first game that's still working, since it was on a friend's computer and XCode DVD. For myself I'm using XCode 3.2.4. And I've recompiled the modules at least 10 times since saturday to try to get MaxGUI working in release mode but that's a third problem I mentioned in the MaxGUI section of the forum :)

Thanks!

(anyway the best thing to do now whatever the explaination of it all is to correct my errors even though they didn't seem to cause trouble until this week)