Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Aug 22, 2019 10:44 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Double Buffering
PostPosted: Thu Mar 19, 2009 11:51 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
I have noticed a new "DoubleBuffer" canvas property in 2009 R1. I don't know if it was there in an earlier version.

Has anyone tried using this property.

Can someone maybe give me an example using it?

Is there any advantage in using it as opposed a traditional double buffering with the canvas?


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Fri Mar 20, 2009 9:18 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
ccfman2004 wrote:
Can someone maybe give me an example using it?


draw in paint event and call refresh to update.

ccfman2004 wrote:
Is there any advantage in using it as opposed a traditional double buffering with the canvas?

[/quote]

Not really except you may save time.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Mar 25, 2009 9:30 pm 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
I tried using the DoubleBuffer property on my Windows XP box - no difference regardless of whether DoubleBuffer=true or DoubleBuffer=false. Some example code would be really nice... :)

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Mar 25, 2009 9:41 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
I learn by example.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Mar 25, 2009 9:47 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quote:
draw in paint event and call refresh to update.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Mar 25, 2009 9:50 pm 
Offline
User avatar

Joined: Thu Mar 05, 2009 1:03 pm
Posts: 1786
Location: USA
Thanks, Tim! I will try that tomorrow morning... :D

_________________
With great power comes great responsibility.
Learn something new every day, and the rest will take care of itself.
Life is a journey, not a destination. Enjoy the trip! :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 1:23 am 
Offline

Joined: Wed Feb 27, 2008 9:17 pm
Posts: 17
I discovered that I can use the new doublebuffer setting to draw to a canvas outside of the paint event. I'm still double-buffering manually, but as long as I draw the background in the paint event, I can draw other images on top of it smoothly from a regular method, without any flicker in Windows and Mac. I much prefer this to having to draw in the paint event all the time. I don't know how efficient this is, but I like it better this way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 1:43 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Just be aware that anything you draw outside the Paint event is transient. It can be erased at any time. If you're animating something from a timer, then draw directly to the canvas. Any one image is only there temporarily anyway, and you're constantly refreshing the content. But it would be a shame to suddenly have half your graph of business revenues suddenly disappear (the part that shows a profit, of course) just because another window temporarily obscured it.

Or does double buffering finally resolve this issue?

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 11:08 am 
Offline

Joined: Wed Feb 27, 2008 9:17 pm
Posts: 17
That does appear to be the case in Windows (I get a horrible flicker when drawing in the paint event), but using the doublebuffer in Mac does not create that problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 12:00 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
brettmb wrote:
That does appear to be the case in Windows (I get a horrible flicker when drawing in the paint event), but using the doublebuffer in Mac does not create that problem.


Mac OS X automatically Double Buffers graphics where Windows does not.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 12:08 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Make sure you turn off EraseBackground.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 12:13 pm 
Offline

Joined: Wed Feb 27, 2008 9:17 pm
Posts: 17
It is off. Every time a container outside of the canvas perimeter is changed BEFORE I refresh the canvas, I get the flicker. Again, only in Windows - Windows is always a problem.


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 1:25 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
If you have controls on top of the canvas, you will always have flicker on Windows (XP and earlier). Mac solves the problem by buffering the entire window, not just the canvas. I believe Vista and 7 do the same.

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 1:37 pm 
Offline

Joined: Wed Feb 27, 2008 9:17 pm
Posts: 17
They are not on top of the canvas. They are outside of it. I moved the updates to the containers after the canvas refresh. It fixed most of the problems. I just don't get Windows functionality some times. :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Double Buffering
PostPosted: Wed Apr 15, 2009 11:45 pm 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
Here is my list of tips for drawing in REALbasic:

1) Turn on Double Buffering
2) Turn off EraseBackground
3) Only draw using the paint event. As much as we programmers like to say "Canvas, display this now" using the backdrop property - it's wrong. Instead, when you want the canvas to forcefully update, use the refresh method. The backdrop property is only useful from the window editor, when you want to display a static/non-changing graphic.
4) Whenever you call refresh, don't ignore it's optional parameter EraseBackground. It defaults to true, so even if you set the EraseBackground property to false, calling Canvas.Refresh() will still erase the background and cause flicker. Use Canvas.Refresh(False) or even better, Canvas.Refresh(Canvas.EraseBackground) to respect the erase background property.

Step 1 is not required if you are already double buffering yourself. For example, if your code looks like:
dim buffer as picture = newpicture(g.width,g.height,32)
// do some work to buffer
g.drawpicture(buffer,0,0)
Then you're already double buffering and don't need to enable the property. If you are doing more than one drawing command to the G parameter in the Paint event, then turn on double buffering. Double buffering (in any form) will nuke your translucency, so a good first command when drawing is to fill the area with FillColor.

All of this is not relevant on the Mac, since the window server automatically double buffers. But it is still good practice, since you never know if you'll take your code to Windows.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group