PDA

View Full Version : backbuffer



anubis79
06-11-2003, 05:34 PM
So, ok here is my code. Everybody copy it and run project and see the flickering please. Why does it flicker? How can I avoid flickering ? Does backbuffer work or what is the problem?
Please add DXDraw, DXTimer and DXInput to your form and make DXTimer1.Interval := 0 and DXTimer1.Enabled := False;

************************************************** **********
var
Form1: TForm1;
MySurface: TDirectDrawSurface; // my image's surface
LeftRight, PointX, PointY: word;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
DXDraw1.Options := DXDraw1.Options + [DoFullScreen];
DXDraw1.Display.Width := 1024;
DXDraw1.Display.Height := 768;
DXDraw1.Width := 800;
DXDraw1.Height := 600;
end;

procedure TForm1.DXDraw1Initialize(Sender: TObject);
begin
MySurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
MySurface.LoadFromFile(extractfilepath(paramstr(0) )+'your favourite 100 * 75 bmp file');
DXTimer1.Enabled := True;
end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
DXInput1.Update;
if isleft in DXInput1.States then
Dec(LeftRight, 1);
if isRight in DXInput1.States then
Inc(LeftRight, 1);
PointX := Form1.ClientOrigin.X + DXDraw1.Left + LeftRight;
PointY := Form1.ClientOrigin.Y + DXDraw1.Top;
DXDraw1.Primary.StretchDraw(Rect(PointX, PointY, PointX + DXDraw1.Width, PointY + DXDraw1.Height), MySurface.ClientRect, MySurface,False);
end;

procedure TForm1.DXDraw1Finalize(Sender: TObject);
begin
MySurface.Free;
end;
end.

************************************************** **********


Note: Hi, I'm Poseidon and I'm sending this message from my friend's computer and I've used anubis79 nickname and a new topic. Sorry...

[edit by BlueCat - [ pascal ] tags are so useful :) ]

Traveler
07-11-2003, 08:01 AM
I'm not sure what the problem is, but everything seems to work okay for me. No flickering whatsoever http://www.gameprogrammer.net/pics/outside/dunno.gif

poseidon
07-11-2003, 08:59 AM
Do you use DoFlip option, Traveler? If you use I should say yes it isn't flicker. But I can't use this option because I use some buttons and panels in my project in full_screen mode and If I make DoFlip everything without DXDraw1 and it's image are disappeared. I know it's DoFlip option's behaviour.

Traveler
07-11-2003, 09:24 AM
Activating or deactivating doFlip doesn't change much. There's still no flickering. The only way I get a flicker is when I add DXDraw1.flip to the onTimer event.

But why use DXDraw1.Primary.StretchDraw and not DXDraw1.Surface.StretchDraw?

poseidon
07-11-2003, 11:01 AM
I don't prefer to use DXDraw1.Surface and it's methods. Especially DXDraw1.Flip is slower than drawing directly to the primary surface. Do you agree? :D
But when I talked with you, I realized that my DXDraw.Width is 800 and if I draw my image in it there is no flicker, but if some part of my image is drawn anywhere on the screen(on the primary) where this point isn't in DXDraw's limits and this part of image can't be seen by the user it is flicker like crazy. So, I'd like to ask you: When you said there is no flicker, were you drawing your image on DXDraw completely (where you drawing it in the DXDraw's limits)? And your answer is yes, can we say primary's backbuffer is only valid for DXDraw's limits?

Note: If this isn't clear, I can give you an example.

Traveler
07-11-2003, 12:06 PM
Primary.draw indeed does appears to be much faster than surface.draw.
I have however no experience using it, so I can't really tell if there are any side effects or do's or dont's.

As for the example. I have used a clean setup, straight from the component palette. No options modified and all code came from your messsage. So as far as I can tell, it's should be the same as yours.

poseidon
07-11-2003, 01:30 PM
Now, I'm thinking may be a difference between your and my DirectX version or your video card and my video card. Can you tell me yours and configurations traveler?

Also, Are there anybody like Traveler who say there is no flicker. Please everybody tell me your's result if you try the code. Does this matter result from my computer? What is your opinion?

Traveler
07-11-2003, 03:51 PM
I do not think it has something to do with the gpu or DirectX. But anyway, i'm currently running at DirectX 8 with a radeon 7500.

poseidon
07-11-2003, 05:06 PM
Thank you all your replies Traveler.