News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Single and Double buffering Issue [Screen]

Started by Bub, February 19, 2006, 01:22:43 PM

Previous topic - Next topic

Bub

; PROJECT : Project1
; AUTHOR  : Mark Garrett
; CREATED : 19.2.2006
; EDITED  : 19.2.2006
; ---------------------------------------------------------------------



OpenScreen 1024,768,16,2

Ink RGB(24,165,183)
SetCursor 10,10: Print "press left mouse button"
Wait 1
mxsa = 0: mysa = 0

Do
if SpaceKey() = 1 Then Exit
mx = MouseX(): my = MouseY()
If MouseButton() = 1 Then dotline(mxsa,mysa,mx,my):mxsa = mx: mysa = my


Loop


Function dotline(x1,y1,x2,y2)


x1# = x1: y1# = y1:x2# = x2: y2# = y2
If x1#> x2# Then xspan# = (x1# - x2#): Goto getyspan
xspan# = (x2# - x1#)

getyspan:
If y1#> y2# Then yspan# = (y1# - y2#): Goto whichspanbiggest
yspan# = (y2# - y1#)

whichspanbiggest:
If xspan# > yspan# Then Goto dox

doy:
If y1# > y2# Then y1# = y2: y2# = y1: x1# = x2: x2# = x1
addx# = (xspan# / yspan#)
If x1# > x2# Then addx# = (0 - addx#)

doy1: Dot x1#,y1#
Inc y1#: x1# = (x1# + addx#): If y1# >= y2# Then Goto done
Goto doy1
`-----------------------------------------------------------------------------
dox:
If x1# > x2# Then x1# = x2: x2# = x1: y1# = y2: y2# = y1
addy# = (yspan# / xspan#)
If y1# > y2# Then addy# = (0 - addy#)

dox1: Dot x1#,y1#
Inc x1#: y1# = (y1# + addy#): If x1# >= x2# Then Goto done
Goto dox1





done:
Sync
ExitFunction
EndFunction

kevin

#1
It's works, but does NOT buffer the screen correctly.   Successive lines will be drawn to either copy the screen buffer (there are two of them !) and thus will flicker !!

Bub

Yes,

But have you noticed it works fine in windowed screen?

kevin

#3
erm, of course it does, they don't operate the same way.   Please read the following the link, it describes the difference between Full Screen and Window modes.

   Any ideas? (Double Buffering Problems)

Bub

#4
Well, that's all nice and I'm sure it works, but shouldn't that be built into the compiler itself so the user doesn't have to do all that?

After all, the user just wants to do his programing, he doesn't want to compensate for what is lacking in the compiler itself.

And, if the compiler gives a choice to put in full screen, then the full-screen should work too, just like the windowed screen does.

However, I'm not complaining, that's cool.



Or, could you just give me some lines of code that I can insert at the top of all my programs?

Bub

#5
Oh, but it sounds easy, if I want to put a dot in full-screen mode, I simply do like this:



Dot 10,20: sync: dot 10,20:sync



and then it'll work, right?



And then to draw a line I simply do like this:

Line 12,80,60,90: sync :Line 12,80,60,90:sync

kevin


kevin

#7
These types of logically problems can not trapped through the compiler alone.  As how the buffer swapping occurs is dictated by the video driver/hardware in full screen mode and not PlayBASIC as you're implying.  The only across the board solution would be triple the screen, which is really not a option.

 However this is only an issue in situations like what what your trying to do( I.e stock pile pixels directly to screen).   If your just drawing dots, then each dot needs to be drawn to both copies of the screen when in full screen mode.



OpenScreen 800,600,32,2
 Do
    Mx=mouseX()
    My=mousey()
; draw dot the current Back buffer of the screen
     dot mx,my
; swap the back buffer and the front buffer over  (now the user is seeing this dot .)
    Sync

; check for full screen mode
     if GetScreenType()=2
       ; now draw  the previous dot onto the new back buffer
           Dot mx,my
   endif
  loop  


 Another approach if that your drawing a lot of cumulative pixels/lines/images etc is to create an image the size of the screen and direct your rendering to that.  This image becomes the picture the canvas..

 Now since the images are not double buffered,  whatever you draw to it will stock pile onto it.  It will also keep the screen and picture your drawing separate from each other. So the interface will not be of your picture.

Here's a bit of larger example of how to do that.

Silly Paint