Solved

Double Buffering

Posted on 2000-02-28
9
708 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now