Re: fast drawing in delphi
- From: Hans-Peter Diettrich <DrDiettrich@xxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 05:05:35 +0100
Maldona8 schrieb:
DoDi, did you mean, to create a monochrome bitmapcolor,
directly in memory and then forcing copy bitmap regions to screen?
I have 100x100 hexagons in the image. Each hexagon has a individual
indepently of any other hexagon colors, neighbors, etc.
Not a direct copy to the screen, that will cause flicker. Instead allocate a buffer bitmap, and BitBlt the monochrome hexagon bitmap into it, for each of your 100*100 hexagons. Finally copy the completed bitmap to the screen (canvas). Enabling double buffered display will make the display persistent, until you replace it by another copy of your buffer bitmap. Otherwise you'll have to copy all or part of your buffer to the screen, in the OnDraw event handler of the control or form. All that will work without DirectX!
Is DirectX the fastest technology for screen drawing?
Only if you use the features of the graphics hardware. In your case this (most probably) would mean to define a basic hexagon, resident in the graphics memory(!), so that the copies are created inside the memory on the graphics card. I have no concrete idea, how DirectX might be used in your specific case, only some general ideas and hearsay :-(
SO, does it means
1) to use DIB or WMF or EMF to draw something
(100x100 hexagons for example) in a bitmap in RAM memory
2) play the Bitmap memory into Screen memory through VideoCard ASM instructions or DirectX
After a review of TBitmap and TCanvas I'd suggest the following: 1) Create a hexagon Bitmap with a single hexagon, one for every color. 2) Create a buffer Bitmap for your 100x100 hexagons. 3) Copy the hexagon bitmaps to the buffer bitmap, 100*100 times. 4) Copy the buffer bitmap to the canvas of your form or control.
Use your existing code for constructing the hexagon bitmaps, varying the Pen.Color. You can use bitmap.Canvas.Draw for all copy operations. Play with the CopyMode property (cmSrcPaint?).
Put (4) into the OnDraw event handler of your form or control, and disable double buffering. Make sure that the handler code does nothing, as long as no buffer bitmap has been created! (or see my code snippet below)
You may proceed in the following steps: 0) Only paint e.g. 10*10 hexagons, until the code works as it should. 1) Paint polygons directly to the canvas, in the OnDraw handler. 2) ...using previously created hexagon bitmaps instead of polygons. 3) ...paint to a buffer bitmap, copy that bitmap in the OnDraw handler. Now it should paint as fast as possible, even without DirectX or ASM. 4) Paint the total 100*100 hexagons.
Bonne chançe :-) DoDi
P.S.: Just tested step 1, using an TImage: it takes about 1 second to prepare all the 10000 polygons, on my 3 GHz system, using D4. No OnDraw handler required, the buffer bitmap resides in the TImage.
It takes a bit longer, but looks nice, when a Image1.Refresh is inserted after every 100 hexagons :-)
Code snippet:
//create new sample procedure TForm1.Button1Click(Sender: TObject); begin //dimension the bitmap - at least once Image1.Picture.Bitmap.Width := Image1.Width; Image1.Picture.Bitmap.Height := Image1.Height; //now draw on the bitmap PaintHex(Image1.Picture.Canvas); //your task... //Image1.Refresh; //not required? end;
//draw single hexagon - simplest version (LineTo on the bitmap canvas) procedure TForm1.HexPaint(c: TCanvas; x, y: integer; clr: TColor); begin c.Pen.Color := clr; c.MoveTo(x+dx*2, y+dy); c.LineTo(x+dx*6, y+dy); ... end; .
- Follow-Ups:
- Re: fast drawing in delphi
- From: Maldona8
- Re: fast drawing in delphi
- References:
- fast drawing in delphi
- From: Maldona8
- Re: fast drawing in delphi
- From: Hans-Peter Diettrich
- Re: fast drawing in delphi
- From: Maldona8
- fast drawing in delphi
- Prev by Date: Re: fast drawing in delphi
- Next by Date: Re: fast drawing in delphi
- Previous by thread: Re: fast drawing in delphi
- Next by thread: Re: fast drawing in delphi
- Index(es):