[Lazarus] copy from Topenglcontext

Andrea Mauri andrea.mauri.75 at gmail.com
Tue Jun 17 16:12:47 CEST 2014


Many thanks.It works as expected.
Il 15/giu/2014 10:08 "Corpsman" <corpsman at web.de> ha scritto:

> My Version uses glReadPixels, result is TBitmap, this can easily be
> atteched to the cliboard.
>
> Function OpenGLScreenshot: TBitmap;
> 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
>   // Auslesen der Framebuffer Auflösung
>   glGetIntegerv(GL_VIEWPORT, @dim[0]);
>   // Erstellen des Bitmaps
>   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]);
>   // Auslesen des Framebuffers in einen temporären Speicher
>   glReadPixels(dim[0], dim[1], dim[2], dim[3], GL_RGBA, GL_UNSIGNED_BYTE,
> @c[0, 0]);
>   // Umschreiben des Temporären Speichers in das 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;
>       // c[z][3] wäre der Alphakanal, aber den Braucht man ja hier nicht
> ...
>       TempIntfImg.Colors[i, j] := CurColor;
>       inc(z);
>     End;
>   TempIntfImg.CreateBitmaps(ImgHandle, ImgMaskHandle, false);
>   result.Handle := ImgHandle;
>   result.MaskHandle := ImgMaskHandle;
>   TempIntfImg.free;
> End;
>
>
> On 06/14/2014 12:13 PM, Michalis Kamburelis wrote:
>
>> Andrea Mauri wrote:
>>
>>> Dear all,
>>>
>>> Is it possible to copy the content of OpenGLContext to the clipboard?
>>> How can be done?
>>>
>>>  You could also copy the contents of OpenGL context (created by
>> TOpenGLContext or any other similar control) using glReadPixels, and
>> then convert the resulting bytes into a TBitmap instance. Then you can
>> copy TBitmap contents to clipboard like Anton shows, using
>> Clipboard.Assign (see
>> http://wiki.lazarus.freepascal.org/Clipboard#Load_from_clipboard ).
>>
>> Using glReadPixels and then converting the result will be
>> cross-platform, as opposed to Anton's solution using
>> Windows.CreateCompatibleBitmap .
>>
>> Michalis
>>
>>
>> --
>> _______________________________________________
>> Lazarus mailing list
>> Lazarus at lists.lazarus.freepascal.org
>> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>>
>>
>
> --
>
> Auf meiner Homepage www.Corpsman.de ist immer was los, ständig wird sie
> aktualisiert und erweitert. Da ist für jeden was dabei.
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140617/017f94ae/attachment-0003.html>


More information about the Lazarus mailing list