Dear all,
Is it possible to copy the content of OpenGLContext to the clipboard? How can be done?
Andrea

Mailing lists / lazarus / 2014-06
6 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Dear all,
Is it possible to copy the content of OpenGLContext to the clipboard? How can be done?
Andrea
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>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
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;Many thanks.It works as expected.
Il 15/giu/2014 10:08 "Corpsman" ha scritto:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140617/017f94ae/attachment.html>
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 :
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140618/edae40ac/attachment.html>