Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fast drawing?

Status
Not open for further replies.

vetko

Programmer
Jan 14, 2007
4
RO
Hello!
I`m trying to write a physical simulation in Delphi 6. I`m simulating charges (electrons) moving in a 2D space. So I`ve used a TImage and I`m drawing on it. (I use the DoubleBuffered:=true property of the form). But I`ve found that it`s quite slow, because sometimes I have to draw a lot of things: circles as electrons, and lines (arrows) for the electric field, sometimes 50x50 or more.
I would like to ask if there is any other faster method. (ex. OpenGL or DirectX would be faster in 2D drawing?)
Thanks.
 
I would look into directx.
I use DelphiX for such Apps.

you can find it here :
I only goes to D5, but can be recompiled into later versions (I use it in D2006)

//Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
I tried UnDelphix but it doesn`t seems much faster:(
I don`t know if i`m doing it well, i`m drawing on the g2.surface.canvas is that right?
Here is my drawing code:

g2.Surface.fill(RGB(255,255,255));

for i:=1 to chargecount do begin
if charge.q<0 then
g2.Surface.Canvas.Brush.color:=clblue else
g2.Surface.Canvas.Brush.color:=clred;
g2.Surface.Canvas.Ellipse(round(charge.x-charge.rad),charge(tolt.y-tolt.rad),charge(tolt.x+charge.rad),charge(tolt.y+charge.rad));
end;

if not(run) then exit;
//***LINES OF FORCE***
if (loff.Checked) and (toltcount>0) then begin
xxx:=g2.surface.Width div resolution.Position;
yyy:=g2.surface.Height div resolution.Position;
res:=resolution.Position;
for i:=1 to xxx do for j:=1 to yyy do
begin
(COUNTING......)
g2.surface.Canvas.MoveTo(round(xx),round(yy));
if proba.Checked then g2.surface.Canvas.Ellipse(round(xx-2),round(yy-2),round(xx+2),round(yy+2));

if abs(ffx)>abs(ffy)
then g2.surface.Canvas.LineTo(round(xx+sign(ffx)*res/2 ),round(yy+ sign(ffy)*abs(ffy/ffx)*(res/2))) else
g2.surface.Canvas.LineTo(round(xx+sign(ffx)* abs(ffx/ffy)*(res/2)),round(yy+sign(ffy)*res/2 ))

end;
end;

g2.Surface.Canvas.Release;
g2.Flip;
 
I`ve seen on the internet the Graphics32 for Delphi, would that be a better choice?
 
Hi,
I'm pretty much a newbie, but, anyway, here's my try...
First of all: for any type of graphics-messing try to use directx or opengl, these stuff were made for graphics, drawing etc.
But, if you want to solve your problem quickly and without additional learning (I would need to do some learning), you can try to draw on form's canvas - it's much faster in my opinion, but it doesn't repaint, unless you put all your drawing code in OnPaint event of your form.
But, the solution I prefer is to use socalled manual doublebuffering:
create a BMP image file and draw on BMP's canvas, and then put BMP on your form. Put a timer to update bitmap on your form properly.
Something like this:
Code:
...
var
bmp:TBitmap;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
...
  bmp:=TBitmap.Create;
  bmp.Height:=Form1.ClientHeight;
  bmp.Width:=Form1.ClientWidth;
...
end;
...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Interval:=25;//for instance
  //do your drawing here, for example, or somewhere else
  Canvas.Draw(0,0,bmp);
end;
...
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  bmp.Free;
end;

end.
From my experience, this is very fast, I hope fast enough for you.
But, as I said I'm just a newbie and I haven't done too much drawing so far...
 
I would try some optimized double buffering instead...
What should I use? Delphix? Graphics32?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top