Windows API of Delphi VCL?

Started by
2 comments, last by AnthonyTW 21 years, 9 months ago
I have never made a game before so before I go off and do something unwanted with it, I''d like to know if calling WinAPI functions is faster (or more efficient) than using Delphi''s VCL component, TCanvas. I haven''t built the engine yet so any other advice would be very helpful.
-- Hi. :)-- http://www.rpginfinity.com
Advertisement
The limiting factor in speed will most definitely be the GDI, not any wrapper (TCanvas) around its functions. Do not worry about that aspect - if you want to worry about speed then you'd use another API entirely, such as OpenGL, SDL or DirectGraphics (Draw/3D). As for size: if you code entirely in API functions (avoiding the VCL) then you'll have a much smaller exe. On the other hand, your productivity will be totally shot. If you plan on making a good game then you'd want to go that way, but if you're just learning then don't worry about it. Use the easy way just now - you can always make another, better game later .

Consider how much simpler life is, btw, if you mix API and TCanvas code. TCanvas is quite literally a wrapper class around DCs, so you could do this:

      var  Canv: TCanvas;  Bmp: TBitmap;begin  Canv := TCanvas.Create;  try    Canv.Handle := GetDC(0); // assign any HDC to the canvas    Canv.FillRect(Rect(0,0,300,300));    Bmp := TBitmap.Create;    try      if FileExists('c:\windows\setup.bmp') then        Bmp.LoadFromFile('c:\windows\setup.bmp');      Canv.StretchDraw(Rect(10, 10, 290, 290), bmp);    finally      Bmp.Free;    end;  finally    ReleaseDC(0, Canv.Handle);    Canv.Free;  end;end;      

That's much nicer than playing around with StretchBlt, LoadImage, et al. You can assign any HDC to your TCanvas and use it with great ease. This means that you could use the API to create your window and dip into the VCL to draw where you want.

Consider using a better graphics API than the GDI, however. There are components for DirectX (see the 'DelphiX' and 'UnDelphiX' wrappers over at Turbo) and headers for DX (and many other APIs) over at the Delphi-JEDI project. You can also look at OpenGL via GLScene or SDL (over at Delphi-JEDI again, somewhere, I believe).

Using any of those APIs will give you far more performance than worrying about GDI/Wrappers of GDI. You can also use much better graphics libraries too, such as FastLib, Graphics32, Graphics64 (no relation) or DIBUltra.

My advice: get a game under your belt the easy way and *then* worry about doing it quickly . Incidentally, DelphiX is reputed to be easy to use (I've not used it myself) and will most definitely be much faster. It's visual too.

[edited by - Alimonster on June 28, 2002 9:33:02 PM]
Use the canvas of a bitmap then blit it to primary.
That''s fast.
In my SW-renderer i get 108fps 800*640*16 using the above method. CPU speed is a factor here.

______________________________Only dead fish go with the main-stream.
The reason I was asking in the first place is because I have a really crappy PC, which is why I wanted to make sure I wouldn''t be playing at 1 frame per minute. And DelphiX isn''t bad, but there''s absolutely no documentation on it, other than a few tutorials scattered here and there. Thanks for the help.
-- Hi. :)-- http://www.rpginfinity.com

This topic is closed to new replies.

Advertisement