Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-18-2008, 08:40 AM
Marky3 Marky3 is offline
Member
 
Join Date: Feb 2005
Posts: 65
Default creating off screen buffer for graphics routines

My current way of implementing graphic routines has given me relatively poor quality results and I have endeavoured to research alternative methods that could improve upon the graphic routines that I have written. It seems that creating an off-screen buffer is the way forward. The advice I was given was:-

'You should use an off-screen buffer, where you do your painting stuff. Once the painting is done, flash the buffer onto the screen. Next time you get a Paint call, skip the rendering to the buffer if it isn't needed.'

However I have absolutely no idea how to implement this and have failed to find any good resources about this topic on the internet. Can anyone help?


Mark Green
Reply With Quote
  #2  
Old 09-18-2008, 12:10 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default RE: creating off screen buffer for graphics routines

Fast/easy way is to double the form buffer by using this code at the "OnCreate" event of the form:

[DELPHI]procedure TForm1.FormCreate(Sender: TObject);
begin
self.DoubleBuffered := True;
end;[/DELPHI]

Regards,
Abdulaziz Jasser
Reply With Quote
  #3  
Old 09-19-2008, 02:40 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: creating off screen buffer for graphics routines

[pre]
Suppose you have a TPaintBox with the OnPaint event set to draw
something that takes a little while.

Without buffering it would look something like this:

procedure TForm1.PaintBox1OnPaint(Sender: TObject);
begin
with TPaintBox(Sender).Canvas do begin
//do your drawing to the canvas...

end;
end;

Every time the paintbox needs to paint itself the OnPaint event gets
called and all of your drawing must be done.

With buffering:

private
FBmp : TBitmap;
procedure MyDrawing;

...

procedure TForm1.OnCreate();
begin
FBmp := TBitmap.Create;
FBmp.PixelFormat := pf24bit;

...

MyDrawing;
end;

procedure TForm1.OnDestroy();
begin
FBmp.Free;
end;

procedure TForm1.PaintBox1OnPaint(Sender: TObject);
begin
PaintBox1.Canvas.Draw(0, 0, FBmp);
end;

procedure TForm1.MyDrawing;
begin
//size the bitmap
FBmp.Width := PaintBox1.ClientWidth;
FBmp.Height := PaintBox1.ClientHeight;

with FBmp.Canvas do begin
//do your drawing to the canvas...

end;

//update the paintbox
PaintBox1OnPaint(nil);
end;

Every time the paintbox needs to paint itself the OnPaint event gets
called and it just draws the buffer (FBmp). The buffer is only
redrawn when needed.

[/pre]
[pre]
"There is a theory which states that if ever anybody discovers
exactly what the Universe is for and why it is here, it will
instantly disappear and be replaced by something even more
bizarre and inexplicable. There is another theory which states
that this has already happened."
-- Douglas Adams
[/pre]

Chris
Reply With Quote
  #4  
Old 09-27-2008, 10:39 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default RE: creating off screen buffer for graphics routines

Marky3,

Was my reply to you helpful? If so, please accept.

Regards,
Abdulaziz Jasser
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:42 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.