Cross platform graphics lazarus / 13-General ---------------------------------------------------------------------- jbreits · 2007-02-07 21:40 I'm trying to use the AggPas library to do some graphics stuff.  The files and examples all compile fine within FPC and Lazarus (if {$mode delphi} is on).  However, the AggPas example projects are not anything close to how I would write an application in Lazarus.  I was hoping to encapsulate some or all of the AggPas code into a component that would be much more user friendly to us Lazarus users. However, I have some questions about what I can do as far as keeping it platform neutral. In one of the examples showing how to integrate the AggPas code with a Delphi form there is some code like this: Code: [Select] var   mem_dc      : HDC;   buf         : pointer;   bmp,   temp        : HBitmap;    bmp_info    : TBitmapInfo;   ....   mem_dc:=CreateCompatibleDC(Canvas.Handle);   bmp_info.bmiHeader.biSize  :=sizeof(TBITMAPINFOHEADER );   bmp_info.bmiHeader.biWidth :=Width;   bmp_info.bmiHeader.biHeight:=Height;   bmp_info.bmiHeader.biPlanes:=1;   bmp_info.bmiHeader.biBitCount     :=32;   bmp_info.bmiHeader.biCompression  :=BI_RGB;   bmp_info.bmiHeader.biSizeImage    :=0;   bmp_info.bmiHeader.biXPelsPerMeter:=0;   bmp_info.bmiHeader.biYPelsPerMeter:=0;   bmp_info.bmiHeader.biClrUsed      :=0;   bmp_info.bmiHeader.biClrImportant :=0;   buf:=NIL;   bmp:=CreateDIBSection (mem_dc, bmp_info, DIB_RGB_COLORS, buf, 0, 0);   temp:=SelectObject(mem_dc ,bmp ); It then goes on to use the Agg redering code as normal.  It copmiles and runs fine on my XP machine, but I'm wondering how much of this is platform specific.  Can HDC and CreateCompatibleDC be used, or are they specific to Windows? The Developing With Graphics page seems to show that DCs can be used. What about CreateDIBSection and SelectObject?  Those look like WinAPI calls to me. Any thoughts? JBreits[/url] ---------------------------------------------------------------------- felipemdc · 2007-02-08 15:46 Quote from: "jbreits"It copmiles and runs fine on my XP machine, but I'm wondering how much of this is platform specific.  Can HDC and CreateCompatibleDC be used, or are they specific to Windows? CreateCompatibleDC, CreateDIBSection and SelectObject are Windows API calls. To make integrating Delphi code easier, lazarus provides cross- platform implementations of several winapi functions, including CreateCompatibleDC and SelectObject, but not CreateDIBSection AFAIK That implementation is a simple call to a winapi on windows, and on gtk, qt, etc, it's implemented using the native api. Nevertheless, it's not a perfect implementation, and IMHO you should avoid using this, and instead use LCL components, which would be TCanvas, TBitmap, TFont, TBrush, etc, for drawing. It's easy to see if your code is cross-platform, just don't use the Windows unit, which only exists on windows. If you need winapi functions add the LclIntf unit instead. Of course you can write platform specific code that is enclosed by a IFDEF Windows ---------------------------------------------------------------------- jbreits · 2007-02-08 22:09 Thanks for the reply.  I was able change the code so now I am using just Lazarus stuff (Winows not in the uses).  The AGGPAS library will render everything to a simple memory location (I used an array).  But I now need to get that array onto a TCanvas quickly.  It works fine to loop through each pixel and do Canvas.Pixels[x,y] := MyColor;  But this is really really slow. Is there anyway to copy the entire array of values into the canvas's pixels?  Or better yet, is there a way I could get a pointer to the canvas's pixels array so I could have AGGPAS render directly to that? Thanks, JBreits ---------------------------------------------------------------------- OnixJr · 2007-02-09 03:42 Quotelazarus provides cross-platform implementations of several winapi functions sekel: where are this "cross-plataform implementations"? in some unit in special? thx... ---------------------------------------------------------------------- theo · 2007-02-09 10:55 Quote from: "jbreits" Is there anyway to copy the entire array of values into the canvas's pixels?  Or better yet, is there a way I could get a pointer to the canvas's pixels array so I could have AGGPAS render directly to that? I've done somthing in this area. http://www.theo.ch/lazarus/op1.zip Hope it helps a bit. Or read here: http://wiki.lazarus.freepascal.org/Developing_with_Graphics ---------------------------------------------------------------------- felipemdc · 2007-02-09 14:17 Quote from: "OnixJr"sekel: where are this "cross-plataform implementations"? in some unit in special? Two units: LCLIntf and LCLType those units will call the widgetset specific code, which for gtk is on: lazarus/lcl/interfaces/gtk/gtkwinapi.inc and several other units, like gtkwinapih.inc And similarly for win32, qt, etc, etc