Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-10

Get TOpenGLControl as Bitmap

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aradeonas

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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151015/0e0e20c6/attachment.html>

Reply by email

Andrea Mauri
to Aradeonas

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

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:

Show quoted text 17 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mattias Gaertner
to Aradeonas: This question is probably for Mattias. Is there any way to get what I draw on…
Show quoted text 5 lines
[...] 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.

Taking a bitmap shot was answered by Aradeonas.
But you cannot simply paint onto an opengl control. You need OpenGL for that. It would be much faster to do the blur entirely with OpenGL.

Mattias

Reply by email

Reimar Grabowski
to Aradeonas
Im using BGRABitmap and it work great with OpenGL but I needed to get the bitmap, do the blur and made texture and again paint it with OpenGL. Is there any better other way?

Yes.
Render your scene to a texture.
Render a full screen quad textured with your scene texture using a blur shader (or two shaders (a horizontal and a vertical one) as it's faster). For details google "opengl gaussian blur" or "opengl post-processing".

R.

Reply by email

Andrea Mauri
to Aradeonas

glGetIntegerv uses GL unit

Il 15/10/2015 13:49, Aradeonas ha scritto:

Show quoted text 7 lines
@AndreaMauri what unit it needs to run? For example what unit it needs for glGetIntegerv? Regards, Ara

Reply by email

Aradeonas
to Reimar Grabowski: On Thu, 15 Oct 2015 03:39:10 -0700 Yes. Render your scene to a texture. Render a full…
Show quoted text 6 lines
Yes. Render your scene to a texture. Render a full screen quad textured with your scene texture using a blur shader (or two shaders (a horizontal and a vertical one) as it's faster). For details google "opengl gaussian blur" or "opengl post-processing". R.

It looks good. Is there any implementation of it in Delphi or FreePascal? Im not so familiar with OpenGL and Im using it with BGRABitmap helps.

Regards, Ara

http://www.fastmail.com - Same, same, but different... -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20151015/2dc79d11/attachment-0001.html>

Reply by email