Solved

Double Buffering

Posted on 2000-02-28
9
720 Views
Last Modified: 2009-12-16
Hi,
I really want to double buffer a simple (!) animation i have.
is there an easyish way of doing so? i understand the thought behind the process but cannot find any commands.

I initialise graphics mode with:
DetectGraph(x,y);
InitGraph(x,y,'BGI_file_path_name');

i am drawing a shape, then erasing it by drawing over it again in black, then redrawing it in its new position.

HELP!!!

Thanks;
Tom
0
Comment
Question by:Tom2222
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2570483
'double buffer' means you have to use 2 pages when drawing
first is visible, second - not, also one page is active (you can draw on it) and second is inactive (just exists somewhere). Visibility and activity are independent, now this is a rough scheme to use 2 pages:

show visible page
set shadow page as active
1)
erase shadow page
draw your shape on shadow page
set shadow to visible
visible becames shadow page
set it to active
goto 1)

size and availability of second (third, fourth etc) page depends on particular video mode
0
 

Author Comment

by:Tom2222
ID: 2570691
OK, anyone happen to know the Pascal commands to do this? will SetActivePage do this, and SetVisualPage, or am i off on completely the wrong track?
0
 
LVL 12

Expert Comment

by:Hypo
ID: 2570792
If you want to use Borlands Graph unit... "graph.tpu" you can use the procedures SetActivePage and SetVisualPage (see help), But using that will not be doublebuffering... it'll be pageflipping, wich is a better method than Doublebuffering.

Try using these procedures...
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 48

Expert Comment

by:dbrunton
ID: 2571732
Sounds clumsy.

Why can't you use PutImage and GetImage procedures?

Draw background.  Use GetImage to get background where your animation is to go - call this A.  Use PutImage to place your first animation on the screen.  Use PutImage to place A back on the screen.

Move to place where next animation to go.  Use GetImage to get background - call this B.  Use PutImage to place second animation on the screen.  Use PutImage to place B back on the screen.

Etc.

This presumes you are not using full screen.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2572030
to dbrunton:

yes, it works fine, but only until you have complicated scene... if you have a lot of overlapping shapes, significant % of screen to be updated and slow CPU/VGA this way becomes ugly...

everything depends on particular application..

0
 

Author Comment

by:Tom2222
ID: 2572290
Yeah, I'm using fullscreen, and the thing's got about 12 moving, overlapping lines...!
I'd heard of pageflipping, i reckon this may work but i think it's fairly clumsy
so I do:

SetActivePage(1);
  Draw picture
  ...
SetVisualPage(1);
SetActivePage(2);
  Draw background
  ...
SetVisualPage(2);
  Move Picture
  ...

Repeat Process

Sounds no better than just lieaving out the SetActivePaeg, SetVisualPage commands... is it?

Thanks;
Tom
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2572340
what is clumsy here ???
this is major approach in most graphic applications... DOOM, HEXEN, QUAKE etc use pages !
try to make it work and compare how your application works with and without - you will not regret...

0
 
LVL 12

Accepted Solution

by:
Hypo earned 49 total points
ID: 2572472
I agree with Alisher...
Since I don't think you understood how easy and how much faster it is to use Pageflipping, I made a little proggy for you. This one uses a procedure called FLIP to flip pages... The only thing you have to do is to call that procedure eachtime you want to refresh your image/frame to the screen.

I've used one assembler procedure, called retrace... wich helps the program to time the pageflipping with the monitors electronbeam... Try removing it and you'll se the difference. Here's the program... It's a small animation loop using Pageflipping... and it runs very smooth!

Program Animation;

uses Crt,Graph;

const
 Triangle: array[1..4] of PointType = ((X: 50; Y: 100), (X: 100; Y:100),
   (X: 150; Y: 150), (X:  50; Y: 100));

var Gd, Gm, Ap: Integer;
    Xpos : integer;

    STab : Array[0..199] of integer;

Procedure Retrace; assembler;
asm
  MOV DX, $3DA
  @NotVert:
  IN  AL, DX
  AND AL, 8
  JNZ @NotVert
  @IsVert:
  IN  AL, DX
  AND AL, 8
  JZ @IsVert
end;

Procedure Flip;
begin
  SetActivePage(Ap);
  Ap := (Ap + 1) and 1;
  SetVisualPage(Ap);
end;

Function InitializeGraph : boolean;
begin
 Gd := VGA;
 InitGraph(Gd, Gm,'bgi\');
 if GraphResult <> grOk then Halt(1);
 If (Gd = HercMono) or (Gd = EGA) or (Gd = EGA64) or (Gd = VGA) then begin
  InitializeGraph := True;
  Flip;
 end else begin
  OutText('No paging supported.');
  InitializeGraph := False;
 end;
end;

begin
 If InitializeGraph then begin
  For Stab[0] := 1 to 199 do
   Stab[Stab[0]] := round(50*Sin( (Stab[0] * (360/199)*pi) / 180));
  Stab[0] := 0;
  repeat
   Xpos := (Xpos +1) mod 200;
   ClearDevice;
   Circle(Xpos+50,100,50);
   Circle(250-Xpos,100,50);
   DrawPoly(SizeOf(Triangle) div Sizeof(PointType), Triangle);
   Triangle[1].Y := 50+Stab[Xpos] div 2;
   Triangle[1].X := 100-Stab[Xpos] div 2;
   Triangle[2].Y := 100+Stab[Xpos];
   Triangle[2].X := 100-Stab[Xpos];
   Triangle[3].X := 150+Stab[Xpos];
   Triangle[4] := Triangle[1];
   Line(60-Stab[Xpos],50,60+Stab[Xpos],10);
   Retrace;
   Flip;
  until keypressed;
 end;
 Readkey;
 CloseGraph;
end.
0
 

Author Comment

by:Tom2222
ID: 2572739
Thanks everyone!
I'll give it a go........
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question