Solved

Double Buffering

Posted on 2000-02-28
9
693 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
Comment Utility
'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
Comment Utility
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
Comment Utility
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 47

Expert Comment

by:dbrunton
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Expert Comment

by:Alisher_N
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks everyone!
I'll give it a go........
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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