Get Pixels buffer of Desktop QtOpenGL
-
Hello,
I'm currently developing a Windows application.
I would like to convert the current screen of the computer into a pixel framebuffer and be able to send it into the network in order to simulate a mirroring.I am currently using :
QScreen *screen = QGuiApplication::primaryScreen(); QWindow *window = windowHandle() screen = window->screen(); originalPixmap = screen->grabWindow(0);
I noticed that is not very efficient, it takes a lot of CPU. And if I want to sent this huge packet into network it would take a while.
I'm looking for the same method but with OpenGL.But how can I do this with QtOpenGL ?
I saw this function that can be useful but I don't know how to use it for this purpose :QOpenGLFunctions::glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels)
Or is there any solution that can be faster ?
Thank you very much for your help.
-
Hi and welcome to devnet,
Are you trying to re-implement something like VNC ?
-
Hello SGaist,
Thank you for your answer.
Yes I'm trying to do something similar. -
Then you should rather use one of the available libraries that already implement the protocol. Currently you are likely trying to grab Full HD frames maybe even 4k to send over the network. You already saw that it's pretty harsh.
One thing that is not clear is: do you want to do it for the whole desktop or only for your application ? In the second case, Qt 5 has a VNC backend since 5.8.0.
-
@SGaist
The goal is to reimplement these protocols.
I would like to know then how do these protocols works.
Maybe I can compress the FULL HD image after I did take the screenshot.
For me, a loop of screenshot is not very efficient, it should have a better way to do it.
I'm looking an other method to do it without using a lot of CPU, maybe a library like QTOpenGL can do this.
Does this library (QTOpenGL) can take picture from a PID or something like that ? -
No it can't and it's outside of its scope.
IIRC ffmpeg might be of help.