Page 1 of 1

How to use glReadPixels with CanvasGadget ?

Posted: Thu Jun 24, 2021 6:55 pm
by luce80
I'd like to use glReadPizels to draw the contents of the gl framebuffer to a CanvasGadget. I have tried DraingBuffer(), CanvasOutput() and DrawImage() in various combinations ;) but with no luck. Any suggestions ? This does not work:

Code: Select all

CanvasGadget(#Canvas,20,20,500,200)
CreateImage(#Image, GadgetWidth(#Canvas), GadgetHeight(#Canvas), 24)

Code: Select all

If StartDrawing(CanvasOutput(#Canvas))
	;buf = DrawingBuffer()
	;glReadPixels (0, 0, GadgetWidth(#Canvas), GadgetHeight(#Canvas), #GL_BGR, #GL_UNSIGNED_BYTE, buf)
	;glReadPixels (0, 0, GadgetWidth(#Canvas), GadgetHeight(#Canvas), #GL_BGR, #GL_UNSIGNED_BYTE, GetGadgetAttribute(#Canvas, #PB_Canvas_Image))
	glReadPixels (0, 0, GadgetWidth(#Canvas), GadgetHeight(#Canvas), #GL_BGR, #GL_UNSIGNED_BYTE, ImageID(#Image))
	DrawImage(ImageID(#Image),0,0)
	StopDrawing()
EndIf
P.S. I can successfully show the contents of the frame buffer on the window's background with eglSwapBuffers().

Re: How to use glReadPixels with CanvasGadget ?

Posted: Thu Jun 24, 2021 7:34 pm
by Keya
are there other alternatives? my brief search in these forums for glReadPixels shows not many using it, but a lot of people saying how slow glReadPixels is

[Solved] Re: How to use glReadPixels with CanvasGadget ?

Posted: Sat Jun 26, 2021 1:56 pm
by luce80
I got it !

Code: Select all

CanvasGadget(#Canvas,20,20,500,200)
CreateImage(#Image, GadgetWidth(#Canvas), GadgetHeight(#Canvas), 32) ; <<-- Note that 32 bits are necessary

Code: Select all

If StartDrawing(ImageOutput(#Image))
	; Note the use of #GL_BGRA
	glReadPixels (0, 0, GadgetWidth(#Canvas), GadgetHeight(#Canvas), #GL_BGRA, #GL_UNSIGNED_BYTE, DrawingBuffer())
	StopDrawing()
EndIf
If StartDrawing(CanvasOutput(#Canvas))
	DrawImage(ImageID(#Image),0,0)
	StopDrawing()
EndIf
If anyone knows of a more "direct" solution please let me (and all others) know.

Re: How to use glReadPixels with CanvasGadget ?

Posted: Sun Sep 03, 2023 10:44 pm
by rotacak
Is possible to capture screenshots also from different OpenGL application (second exe file)?