Solved

Double Buffering

Posted on 2000-02-28
9
774 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
LVL 49

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
Article by: Justin
In light of the WannaCry ransomware attack that affected millions of Windows machines, you might wonder if your Mac needs protecting. Yes, it does and here is how to do it.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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