Board index » cppbuilder » Flicker-free graphics: double buffering I presume?

Flicker-free graphics: double buffering I presume?

Hello All,

I am developing a performance sensitive graph component for BCB4, using C++
not Object Pascal.  That said, I continue to have problems with flickering
on repaints during resizes and so forth.  Now I have heard before of a
mechanism called "double buffering that eliminates this problem, but I don't
know what it is or how to implement it.  My graph component is inherited
from TGraphicControl.  If someone can point me to a tutorial, I'd really
appreciate it.

Thanks,
-Mike Powers

 

Re:Flicker-free graphics: double buffering I presume?


Hi Mike!
Check out Harold Howe's FAQ:
http://www.bcbdev.com/faqs/faq34.htm

"Michael A. Powers" <mapow...@email.com> wrote in message
news:8u7546$ngq7@bornews.borland.com...

Quote
> Hello All,

> I am developing a performance sensitive graph component for BCB4, using
C++
> not Object Pascal.  That said, I continue to have problems with flickering
> on repaints during resizes and so forth.  Now I have heard before of a
> mechanism called "double buffering that eliminates this problem, but I
don't
> know what it is or how to implement it.  My graph component is inherited
> from TGraphicControl.  If someone can point me to a tutorial, I'd really
> appreciate it.

> Thanks,
> -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


There is a property DoubleBuffered. Set this to true and the TWinControl (or
derivative) will be drawn to an in-memory bitmap first.

Andr

"Michael A. Powers" <mapow...@email.com> wrote in message
news:8u7546$ngq7@bornews.borland.com...

Quote
> Hello All,

> I am developing a performance sensitive graph component for BCB4, using
C++
> not Object Pascal.  That said, I continue to have problems with flickering
> on repaints during resizes and so forth.  Now I have heard before of a
> mechanism called "double buffering that eliminates this problem, but I
don't
> know what it is or how to implement it.  My graph component is inherited
> from TGraphicControl.  If someone can point me to a tutorial, I'd really
> appreciate it.

> Thanks,
> -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


Quote
Andr Jager <aja...@scintillating.nl> wrote in message

news:3a073144$2_1@dnews...
Quote
> There is a property DoubleBuffered. Set this to true and the TWinControl
(or
> derivative) will be drawn to an in-memory bitmap first.

Just like to say. I program in opengl, and I never have to worry about
flickering with dubble buffering
And if this dosent make much sence its probley cause im drunk lol.
But really... I think opengl would make killer 2d app's too if someone could
make a class libary for it.
I mean think, how many of your wonderfull vcl components never ever flicker,
can be updated more then 1 time per
ms.  and support rotation, easy zooming (yes, zooming, not just scaleing,
but zooming in and out and rescaleing font, size, and graphic textures all
at once) plus antialiasing..
Sure its not pratical, But I just love opengl, eveything else just seems
{*word*99}py to me now.
Anyhow... just a drunken rant. probley not a good idea to use opengl for it.
but anyhow, for something on topic
double buffering is like this
1 area (pointer 1) of ram holds a pointer to what part of the ram is to be
drawed
2 (area 1 and area 1) other area's hold the visable part of the screen
area 1 is displayed
area 2 is writen to (ie, some text or texture or vcl object drawn to it)
pointer 1 is set to area 2 (and area 2 is displayed)
area 1 gets writen too
pointer 1 is set to area 1
(repeat)
Most app's use single buffering
Ie
Area 1 displayed
object 1 drawn to area 1
Sometimes, a screen refresh will happen befor object 1 is drawn fully, or at
all, thats what gives "flicker"
Double buffering draws "behind the screen" and then switchs a pointer
telling the next update to draw the other 1/2 of the buffer insted of the
1st half
You may think "dosent this mean we only have 1/2 the res?"
Wrong, it means you use double the draw buffer, but thats all, refreshs may
be *slightly* delayed, but it isent much
(in laymens terms, its like trying to draw a picture "as" someone is takeing
the picture, while double buffering is like drawing while the guy photo's
the last one you drew, sure it makes a delay on what photo he can take, but
a few ms isent bad :)
(btw, a normal tpicture takes 3/4 of a ms to move 1 axis or so, so unless
your useing about 100+ objects at a time, double buffering is only a plus..
unless your targeting systems with vary low video ram, but then you can just
made a if to see if it supports double buffering or not
Aww man, now im sober. this sucks. im gonna stop typeing now
Quote

> Andr

> "Michael A. Powers" <mapow...@email.com> wrote in message
> news:8u7546$ngq7@bornews.borland.com...
> > Hello All,

> > I am developing a performance sensitive graph component for BCB4, using
> C++
> > not Object Pascal.  That said, I continue to have problems with
flickering
> > on repaints during resizes and so forth.  Now I have heard before of a
> > mechanism called "double buffering that eliminates this problem, but I
> don't
> > know what it is or how to implement it.  My graph component is inherited
> > from TGraphicControl.  If someone can point me to a tutorial, I'd really
> > appreciate it.

> > Thanks,
> > -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


I think OpenGL is the way to go as well but for many applications it is to
much work.

Andr

Quote
"Black Moon" <Black_mo...@hotmail.com> wrote in message

news:8u7pdr$47@bornews.inprise.com...
Quote

> Andr Jager <aja...@scintillating.nl> wrote in message
> news:3a073144$2_1@dnews...
> > There is a property DoubleBuffered. Set this to true and the TWinControl
> (or
> > derivative) will be drawn to an in-memory bitmap first.
> Just like to say. I program in opengl, and I never have to worry about
> flickering with dubble buffering
> And if this dosent make much sence its probley cause im drunk lol.
> But really... I think opengl would make killer 2d app's too if someone
could
> make a class libary for it.
> I mean think, how many of your wonderfull vcl components never ever
flicker,
> can be updated more then 1 time per
> ms.  and support rotation, easy zooming (yes, zooming, not just scaleing,
> but zooming in and out and rescaleing font, size, and graphic textures all
> at once) plus antialiasing..
> Sure its not pratical, But I just love opengl, eveything else just seems
> {*word*99}py to me now.
> Anyhow... just a drunken rant. probley not a good idea to use opengl for
it.
> but anyhow, for something on topic
> double buffering is like this
> 1 area (pointer 1) of ram holds a pointer to what part of the ram is to be
> drawed
> 2 (area 1 and area 1) other area's hold the visable part of the screen
> area 1 is displayed
> area 2 is writen to (ie, some text or texture or vcl object drawn to it)
> pointer 1 is set to area 2 (and area 2 is displayed)
> area 1 gets writen too
> pointer 1 is set to area 1
> (repeat)
> Most app's use single buffering
> Ie
> Area 1 displayed
> object 1 drawn to area 1
> Sometimes, a screen refresh will happen befor object 1 is drawn fully, or
at
> all, thats what gives "flicker"
> Double buffering draws "behind the screen" and then switchs a pointer
> telling the next update to draw the other 1/2 of the buffer insted of the
> 1st half
> You may think "dosent this mean we only have 1/2 the res?"
> Wrong, it means you use double the draw buffer, but thats all, refreshs
may
> be *slightly* delayed, but it isent much
> (in laymens terms, its like trying to draw a picture "as" someone is
takeing
> the picture, while double buffering is like drawing while the guy photo's
> the last one you drew, sure it makes a delay on what photo he can take,
but
> a few ms isent bad :)
> (btw, a normal tpicture takes 3/4 of a ms to move 1 axis or so, so unless
> your useing about 100+ objects at a time, double buffering is only a
plus..
> unless your targeting systems with vary low video ram, but then you can
just
> made a if to see if it supports double buffering or not
> Aww man, now im sober. this sucks. im gonna stop typeing now

> > Andr

> > "Michael A. Powers" <mapow...@email.com> wrote in message
> > news:8u7546$ngq7@bornews.borland.com...
> > > Hello All,

> > > I am developing a performance sensitive graph component for BCB4,
using
> > C++
> > > not Object Pascal.  That said, I continue to have problems with
> flickering
> > > on repaints during resizes and so forth.  Now I have heard before of a
> > > mechanism called "double buffering that eliminates this problem, but I
> > don't
> > > know what it is or how to implement it.  My graph component is
inherited
> > > from TGraphicControl.  If someone can point me to a tutorial, I'd
really
> > > appreciate it.

> > > Thanks,
> > > -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


There are some very nice free encapsulations of OpenGL for the VCL
already.

Try TGLScene

http://perso.infonie.fr/revolution/GLScene/features.htm

among the first, and there is a commercial product from SignSoft
(www.signsoft.de)

Quote
"Andr Jager" wrote:

> I think OpenGL is the way to go as well but for many applications it is to
> much work.

> Andr

> "Black Moon" <Black_mo...@hotmail.com> wrote in message
> news:8u7pdr$47@bornews.inprise.com...

> > Andr Jager <aja...@scintillating.nl> wrote in message
> > news:3a073144$2_1@dnews...
> > > There is a property DoubleBuffered. Set this to true and the TWinControl
> > (or
> > > derivative) will be drawn to an in-memory bitmap first.
> > Just like to say. I program in opengl, and I never have to worry about
> > flickering with dubble buffering
> > And if this dosent make much sence its probley cause im drunk lol.
> > But really... I think opengl would make killer 2d app's too if someone
> could
> > make a class libary for it.
> > I mean think, how many of your wonderfull vcl components never ever
> flicker,
> > can be updated more then 1 time per
> > ms.  and support rotation, easy zooming (yes, zooming, not just scaleing,
> > but zooming in and out and rescaleing font, size, and graphic textures all
> > at once) plus antialiasing..
> > Sure its not pratical, But I just love opengl, eveything else just seems
> > {*word*99}py to me now.
> > Anyhow... just a drunken rant. probley not a good idea to use opengl for
> it.
> > but anyhow, for something on topic
> > double buffering is like this
> > 1 area (pointer 1) of ram holds a pointer to what part of the ram is to be
> > drawed
> > 2 (area 1 and area 1) other area's hold the visable part of the screen
> > area 1 is displayed
> > area 2 is writen to (ie, some text or texture or vcl object drawn to it)
> > pointer 1 is set to area 2 (and area 2 is displayed)
> > area 1 gets writen too
> > pointer 1 is set to area 1
> > (repeat)
> > Most app's use single buffering
> > Ie
> > Area 1 displayed
> > object 1 drawn to area 1
> > Sometimes, a screen refresh will happen befor object 1 is drawn fully, or
> at
> > all, thats what gives "flicker"
> > Double buffering draws "behind the screen" and then switchs a pointer
> > telling the next update to draw the other 1/2 of the buffer insted of the
> > 1st half
> > You may think "dosent this mean we only have 1/2 the res?"
> > Wrong, it means you use double the draw buffer, but thats all, refreshs
> may
> > be *slightly* delayed, but it isent much
> > (in laymens terms, its like trying to draw a picture "as" someone is
> takeing
> > the picture, while double buffering is like drawing while the guy photo's
> > the last one you drew, sure it makes a delay on what photo he can take,
> but
> > a few ms isent bad :)
> > (btw, a normal tpicture takes 3/4 of a ms to move 1 axis or so, so unless
> > your useing about 100+ objects at a time, double buffering is only a
> plus..
> > unless your targeting systems with vary low video ram, but then you can
> just
> > made a if to see if it supports double buffering or not
> > Aww man, now im sober. this sucks. im gonna stop typeing now

> > > Andr

> > > "Michael A. Powers" <mapow...@email.com> wrote in message
> > > news:8u7546$ngq7@bornews.borland.com...
> > > > Hello All,

> > > > I am developing a performance sensitive graph component for BCB4,
> using
> > > C++
> > > > not Object Pascal.  That said, I continue to have problems with
> > flickering
> > > > on repaints during resizes and so forth.  Now I have heard before of a
> > > > mechanism called "double buffering that eliminates this problem, but I
> > > don't
> > > > know what it is or how to implement it.  My graph component is
> inherited
> > > > from TGraphicControl.  If someone can point me to a tutorial, I'd
> really
> > > > appreciate it.

> > > > Thanks,
> > > > -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


True, but apparently *only* for Delphi. Heres an excerpt from the GLScene
FAQ at the url below:

CPP Builder : does not compile !
GLScene uses a lot of Delphi features that CPPB currently does not support,
among these are abstract class functions and array properties were reported.
As I (Eric Grange) don't have CPPB, and since compatibility would require a
lot of work and some lost functionnality, sorry, but CPPB support is not
planned.
Pray that Borland will add full Delphi support in upcoming versions...
- Lew

Quote
"patrick martin" <patrickmmar...@freenet.co.uk> wrote in message

news:3A0866C9.401EEC73@freenet.co.uk...
Quote
> There are some very nice free encapsulations of OpenGL for the VCL
> already.

> Try TGLScene

> http://perso.infonie.fr/revolution/GLScene/features.htm

> among the first, and there is a commercial product from SignSoft
> (www.signsoft.de)

> "Andr Jager" wrote:

> > I think OpenGL is the way to go as well but for many applications it is
to
> > much work.

> > Andr

> > "Black Moon" <Black_mo...@hotmail.com> wrote in message
> > news:8u7pdr$47@bornews.inprise.com...

> > > Andr Jager <aja...@scintillating.nl> wrote in message
> > > news:3a073144$2_1@dnews...
> > > > There is a property DoubleBuffered. Set this to true and the
TWinControl
> > > (or
> > > > derivative) will be drawn to an in-memory bitmap first.
> > > Just like to say. I program in opengl, and I never have to worry about
> > > flickering with dubble buffering
> > > And if this dosent make much sence its probley cause im drunk lol.
> > > But really... I think opengl would make killer 2d app's too if someone
> > could
> > > make a class libary for it.
> > > I mean think, how many of your wonderfull vcl components never ever
> > flicker,
> > > can be updated more then 1 time per
> > > ms.  and support rotation, easy zooming (yes, zooming, not just
scaleing,
> > > but zooming in and out and rescaleing font, size, and graphic textures
all
> > > at once) plus antialiasing..
> > > Sure its not pratical, But I just love opengl, eveything else just
seems
> > > {*word*99}py to me now.
> > > Anyhow... just a drunken rant. probley not a good idea to use opengl
for
> > it.
> > > but anyhow, for something on topic
> > > double buffering is like this
> > > 1 area (pointer 1) of ram holds a pointer to what part of the ram is
to be
> > > drawed
> > > 2 (area 1 and area 1) other area's hold the visable part of the screen
> > > area 1 is displayed
> > > area 2 is writen to (ie, some text or texture or vcl object drawn to
it)
> > > pointer 1 is set to area 2 (and area 2 is displayed)
> > > area 1 gets writen too
> > > pointer 1 is set to area 1
> > > (repeat)
> > > Most app's use single buffering
> > > Ie
> > > Area 1 displayed
> > > object 1 drawn to area 1
> > > Sometimes, a screen refresh will happen befor object 1 is drawn fully,
or
> > at
> > > all, thats what gives "flicker"
> > > Double buffering draws "behind the screen" and then switchs a pointer
> > > telling the next update to draw the other 1/2 of the buffer insted of
the
> > > 1st half
> > > You may think "dosent this mean we only have 1/2 the res?"
> > > Wrong, it means you use double the draw buffer, but thats all,
refreshs
> > may
> > > be *slightly* delayed, but it isent much
> > > (in laymens terms, its like trying to draw a picture "as" someone is
> > takeing
> > > the picture, while double buffering is like drawing while the guy
photo's
> > > the last one you drew, sure it makes a delay on what photo he can
take,
> > but
> > > a few ms isent bad :)
> > > (btw, a normal tpicture takes 3/4 of a ms to move 1 axis or so, so
unless
> > > your useing about 100+ objects at a time, double buffering is only a
> > plus..
> > > unless your targeting systems with vary low video ram, but then you
can
> > just
> > > made a if to see if it supports double buffering or not
> > > Aww man, now im sober. this sucks. im gonna stop typeing now

> > > > Andr

> > > > "Michael A. Powers" <mapow...@email.com> wrote in message
> > > > news:8u7546$ngq7@bornews.borland.com...
> > > > > Hello All,

> > > > > I am developing a performance sensitive graph component for BCB4,
> > using
> > > > C++
> > > > > not Object Pascal.  That said, I continue to have problems with
> > > flickering
> > > > > on repaints during resizes and so forth.  Now I have heard before
of a
> > > > > mechanism called "double buffering that eliminates this problem,
but I
> > > > don't
> > > > > know what it is or how to implement it.  My graph component is
> > inherited
> > > > > from TGraphicControl.  If someone can point me to a tutorial, I'd
> > really
> > > > > appreciate it.

> > > > > Thanks,
> > > > > -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


Thanks, but my component is derived from TGraphicControl and not TWinControl
so I can't use that.

-Mike

Quote
"Andr Jager" <aja...@scintillating.nl> wrote in message

news:3a073144$2_1@dnews...
Quote
> There is a property DoubleBuffered. Set this to true and the TWinControl
(or
> derivative) will be drawn to an in-memory bitmap first.

> Andr

> "Michael A. Powers" <mapow...@email.com> wrote in message
> news:8u7546$ngq7@bornews.borland.com...
> > Hello All,

> > I am developing a performance sensitive graph component for BCB4, using
> C++
> > not Object Pascal.  That said, I continue to have problems with
flickering
> > on repaints during resizes and so forth.  Now I have heard before of a
> > mechanism called "double buffering that eliminates this problem, but I
> don't
> > know what it is or how to implement it.  My graph component is inherited
> > from TGraphicControl.  If someone can point me to a tutorial, I'd really
> > appreciate it.

> > Thanks,
> > -Mike Powers

Re:Flicker-free graphics: double buffering I presume?


Quote
> I am developing a performance sensitive graph component for BCB4, using
C++
> not Object Pascal.  That said, I continue to have problems with flickering
> on repaints during resizes and so forth.  Now I have heard before of a
> mechanism called "double buffering that eliminates this problem, but I
don't
> know what it is or how to implement it.  My graph component is inherited
> from TGraphicControl.  If someone can point me to a tutorial, I'd really
> appreciate it.

Are you rendering to a canvas in the background and then swapping it in?

You can get a lot of flicker because windows sends an "erase background"
message. If you get rid of this you just draw over the previous image
without it getting set to the Form colour (assuming your image is fully
opaque).

Class view... New method... to the component class and add the window
handler WM_ERASEBKGND Just as a blank function eg. OnEraseBack(int) {} and
this will eat the message, doing nothing.

Hope this helps.... More info on vcl.components.writing if you need it.

Other Threads