[Lazarus] Get TOpenGLControl as Bitmap

Andrea Mauri andrea.mauri.75 at gmail.com
Thu Oct 15 12:19:05 CEST 2015


See subject "copy from Topenglcontext" in lazarus mailing list 
(http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-June/087414.html).
I got the proper answer from corpsman at web.de

Actually I use the following code, it works:

Var
   dim: Array[0..3] Of Integer;
   c: Array Of Array[0..3] Of Byte;
   z, i, j: integer;
   TempIntfImg: TLazIntfImage;
   ImgHandle, ImgMaskHandle: HBitmap;
   CurColor: TFPColor;
Begin
   // Reading the framebuffer resolution
   glGetIntegerv(GL_VIEWPORT, @dim[0]);
   // Create the bitmap
   result := TBitmap.create;
   result.pixelformat := pf24bit;
   result.width := dim[2];
   result.height := dim[3];
   TempIntfImg := TLazIntfImage.Create(0, 0);
   TempIntfImg.LoadFromBitmap(result.Handle, result.MaskHandle);
   setlength(c, dim[2] * dim[3]);
   // Reading of the framebuffer in a temporary memory
   glReadPixels(dim[0], dim[1], dim[2], dim[3], GL_RGBA, 
GL_UNSIGNED_BYTE, @c[0, 0]);
   // Rewriting the temporary memory in the TBitmap
   z := 0;
   For j := 0 To result.height - 1 Do
     For i := 0 To result.width - 1 Do Begin
       CurColor.red := c[z][0] * 256;
       CurColor.green := c[z][1] * 256;
       CurColor.blue := c[z][2] * 256;
       TempIntfImg.Colors[i, result.height - 1 - j] := CurColor;
       inc(z);
     End;
   TempIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, false);
   result.Handle := ImgHandle;
   result.MaskHandle := ImgMaskHandle;
   TempIntfImg.free;
end;

Il 15/10/2015 11:59, Aradeonas ha scritto:
> Hi,
> This question is probably for Mattias.
> Is there any way to get what I draw on TOpenGLControl as a bitmap 
> result like an screenshot from this component?
> I want it to make a blur effected of it and then paint it again on the 
> control so I get a blurred view of whatever is in control.
> Regards,
> Ara
> -- 
> http://www.fastmail.com - Send your email first class
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus





More information about the Lazarus mailing list