How to use glReadPixels with CanvasGadget ?

Everything related to 3D programming
luce80
New User
New User
Posts: 5
Joined: Tue Jun 01, 2021 5:20 pm

How to use glReadPixels with CanvasGadget ?

Post 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().
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: How to use glReadPixels with CanvasGadget ?

Post 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
luce80
New User
New User
Posts: 5
Joined: Tue Jun 01, 2021 5:20 pm

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

Post 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.
rotacak
User
User
Posts: 77
Joined: Tue Feb 14, 2006 2:00 pm

Re: How to use glReadPixels with CanvasGadget ?

Post by rotacak »

Is possible to capture screenshots also from different OpenGL application (second exe file)?
Post Reply