Question

I have a C++ Open GL application that renders an animation display, and captures the frame-buffer contents using glReadPixels(), which is then stored as a 1D char array.

I can get the buffer contents and save it to a char array, as follow:

char * values = (char *) malloc(width * height * 4 * sizeof(char));
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, values);

I then send these raw data over the network using socket, which is not an issue for me. I have a Qt Desktop Client (which communicates with the OpenGL application using socket)

This client program can successfully receive the raw binary data sent by the Open GL application.

How can I render an image from these binary data in my client application? Does Qt has any built-in function / library to draw an image from binary data (which is generated from glReadPixels)?

Do I need to encode / decode these raw binary data as base64 type prior to send them via sockets? Why or why not?

Was it helpful?

Solution

QImage has a nice constructor that takes an existing buffer, a width, a height and a pixel format. That seems like an excellent place to start.

And if you create the QImage on the server, you can use Qt's built-in streaming to send a QImage to your clients (QDataStreams can wrap just about any IO device, including network sockets), so there's no need to do any encoding and decoding yourself - Qt will take care of everything for you.

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top