Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 855
  • Last Modified:

Double Buffering

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
Tom2222
Asked:
Tom2222
  • 3
  • 3
  • 2
  • +1
1 Solution
 
Alisher_NCommented:
'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
 
Tom2222Author Commented:
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
 
HypoCommented:
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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
dbruntonCommented:
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
 
Alisher_NCommented:
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
 
Tom2222Author Commented:
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
 
Alisher_NCommented:
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
 
HypoCommented:
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
 
Tom2222Author Commented:
Thanks everyone!
I'll give it a go........
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now