Sign in Join

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

Mailing lists / lazarus / 2014-06

copy from Topenglcontext

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Anton Kavalenka
to Andrea Mauri
Andrea Mauri wrote 12 lines
Dear all, Is it possible to copy the content of OpenGLContext to the clipboard? How can be done? Andrea -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

At least in windows:

function TGLFormA.GetGlBitmap:TBitmap;
var cDC:HDC;
     bm:HBitMap;
begin
    Result:=TBitmap.create;
    cDC:=GetDC(glPanel.handle);
bm:=Windows.CreateCompatibleBitmap(cDC,glPanel.Width,glPanel.height);
    ReleaseDc(glPanel.handle,cDC);
    Result.handle:=bm;
BitBlt(Result.Canvas.handle,0,0,glPanel.Width,glPanel.height,glPanel.DC,0,0,SRCCOPY);
end;
procedure TGLFormA.CopyToClipboard;
var img:TBitmap;
begin
   img:=GetGLBitmap;
   try
   Clipboard.Assign(img);
   finally
     img.Free;
   end;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140613/1a4d7b76/attachment.html>

Reply by email

Michalis Kamburelis
to Andrea Mauri: Is it possible to copy the content of OpenGLContext to the clipboard? How can be done?…
Andrea Mauri wrote 5 lines
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

Reply by email

Corpsman
to Michalis Kamburelis

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;
Michalis Kamburelis wrote 26 lines
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 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.

Reply by email

Andrea Mauri
to Corpsman

Many thanks.It works as expected.
Il 15/giu/2014 10:08 "Corpsman" ha scritto:

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140617/017f94ae/attachment.html>

Reply by email

Andrea Mauri
to Andrea Mauri

Dear Corpsman,

I slightly modified your routine since I noticed that the copied image was copied as in a mirror (I don't know hot to exlpain it better). I modified the line:
TempIntfImg.Colors[i, j] := CurColor;
in
TempIntfImg.Colors[i, result.height - 1 - j] := CurColor;

2014-06-17 16:12 GMT+02:00 Andrea Mauri :

Show quoted text 91 lines
Many thanks.It works as expected. Il 15/giu/2014 10:08 "Corpsman" 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 >> >> 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 > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140618/edae40ac/attachment.html>

Reply by email