GLB Main Loop

Previous topic - Next topic

coder14

The main loop in GLB is usually made up of a while/wend, or some other type of loop with a goto->start format. Is this the only way to set up the main loop? Another thing, whenever another window hovers over my GLB app, the screen contents get wiped off. How does GLB handle re-draws? Thanks in advance!


matchy

Look up these in the help file!  ;)

Code (glbasic) Select

WHILE a#$ = < <= > >= <> b#$
...
WEND

REPEAT
...
UNTIL expression

FOR counter# = start# TO end# |STEP steps#|
...
NEXT

AUTOPAUSE mode#

ALLOWESCAPE a#


coder14

Quote from: matchy on 2012-Mar-24
Look up these in the help file!  ;)

Code (glbasic) Select

WHILE a#$ = < <= > >= <> b#$
...
WEND

REPEAT
...
UNTIL expression

FOR counter# = start# TO end# |STEP steps#|
...
NEXT

AUTOPAUSE mode#

ALLOWESCAPE a#


Ok, must be a loop. What about the redraw thing?

Ian Price

I can't say I've ever seen other Windows apps wiping the screen of an un-focused GLB program.

What happens to your GLB screen when it regains focus?

Do you have any screenshots of the GLB screen being "wiped"? Is it the whole screen or just portions? Or do you mean that the GLB screen just turns black?
I came. I saw. I played.

coder14

#4
Quote from: Ian Price on 2012-Mar-24
I can't say I've ever seen other Windows apps wiping the screen of an un-focused GLB program.

What happens to your GLB screen when it regains focus?

Do you have any screenshots of the GLB screen being "wiped"? Is it the whole screen or just portions? Or do you mean that the GLB screen just turns black?

Ah yes! Even the Hello World! example can demonstrate this.

Code (glbasic) Select
PRINT "Hello GLBasic World !", 0, 100;
SHOWSCREEN
KEYWAIT


I changed the MOUSEWAIT to KEYWAIT to free up the mouse. If the app window is moved out of the screen area or another app goes over it, the screen gets wiped off.

[EDIT] Even minimizing the window will wipe the screen off.

MrTAToad

That would indicate an application#s message pump isn't working or is too slow to receive input and thus can't update the screen).

Alternatively you aren't updating the display every loop...

coder14

Quote from: MrTAToad on 2012-Mar-24
That would indicate an application#s message pump isn't working or is too slow to receive input and thus can't update the screen).

Alternatively you aren't updating the display every loop...

So what should I do? MOUSEWAIT & KEYWAIT are not loops, so we have to put SHOWSCREEN in the main loop? Will that take up a lot of CPU resource?

quangdx

The way I use GLBasic is to set up a main loop and refresh the screen each loop.
Depending on what you set the FPS to, it will lock to that if possible.

Code (glbasic) Select

GLOBAL ProgramExit

WHILE ProgramExit=0
IF INKEY$()<>"" THEN ProgramExit=1
PRINT "Hello GLBasic World !", 100,100;
SHOWSCREEN
WEND
Asobi tech - the science of play.
Spare time indiegame developer.

coder14

Quote from: quangdx on 2012-Mar-24
The way I use GLBasic is to set up a main loop and refresh the screen each loop.
Depending on what you set the FPS to, it will lock to that if possible.

Code (glbasic) Select

GLOBAL ProgramExit

WHILE ProgramExit=0
IF INKEY$()<>"" THEN ProgramExit=1
PRINT "Hello GLBasic World !", 100,100;
SHOWSCREEN
WEND


I like your way. But it only works if the window has focus, otherwise it gets wiped off by any hovering window. And even when it has focus it gets a little warped if I drag it out of the screen area until I release the mouse button. How do I set the FPS?

quangdx

Quote from: coder14 on 2012-Mar-24
I like your way. But it only works if the window has focus, otherwise it gets wiped off by any hovering window. And even when it has focus it gets a little warped if I drag it out of the screen area until I release the mouse button. How do I set the FPS?

If you want the window to keep updated when it has lost focus, then you got to set AUTOPAUSE FALS.
You set FPS by setting it in the Project Options, or in the code with LIMITFPS i%

Code (glbasic) Select

AUTOPAUSE FALSE
LIMITFPS 30

GLOBAL ProgramExit

WHILE ProgramExit=0
IF INKEY$()<>"" THEN ProgramExit=1
PRINT "Hello GLBasic World !", 0, 100;
SHOWSCREEN
WEND
Asobi tech - the science of play.
Spare time indiegame developer.

coder14

Quote from: quangdx on 2012-Mar-24
Quote from: coder14 on 2012-Mar-24
I like your way. But it only works if the window has focus, otherwise it gets wiped off by any hovering window. And even when it has focus it gets a little warped if I drag it out of the screen area until I release the mouse button. How do I set the FPS?

If you want the window to keep updated when it has lost focus, then you got to set AUTOPAUSE FALS.
You set FPS by setting it in the Project Options, or in the code with LIMITFPS i%

Code (glbasic) Select

AUTOPAUSE FALSE
LIMITFPS 30

GLOBAL ProgramExit

WHILE ProgramExit=0
IF INKEY$()<>"" THEN ProgramExit=1
PRINT "Hello GLBasic World !", 0, 100;
SHOWSCREEN
WEND


Bingo! That did the trick. Dragging the window out of screen area still warps the drawing until the mouse button is released, but I can live with that. Thanks for your help.