user11498510
user11498510

Reputation:

How to flip data from frame buffer

I am attaching a PBO to the Opengl framebuffer and than use glMapBuffer() to get access to the data.

I am passing the data to a Bluefish card for SDI Output.

The issue is that the resultant output appears inverted.

How can i invert y axis of the data being pointed by PBO pointer.

glReadBuffer(GL_FRONT);
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[writeIndex]);
// copy from framebuffer to PBO asynchronously. it will be ready in the NEXT frame
glReadPixels(0, 0, SCR_WIDTH, SCR_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
// now read other PBO which should be already in CPU memory
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo[readIndex]);
// map buffer so we can access it
void* downsampleData = (unsigned char *)glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY);

This is how i am trying to flip data after advised by Nicol and i get the desired result.

 unsigned char OriginalData[width * height * 4];
 unsigned char FlippedData[width * height * 4];
 memcpy( OriginalData , downsampleData , sizeof( OriginalData) );  // copy data from the pointer.

 for( int i = sizeof( OriginalData) - 1; i >= 0 ; i-- )
 {
    Flippeddata[k] = OriginalData[sizeof( OriginalData) - 1 - 1];
 }

Upvotes: 3

Views: 1232

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473447

You can't. OpenGL always considers the first row to be the bottom row of the image data for any image operation (sending/receiving pixel blocks, fetching texture samples/image data in a shader, etc). So if you want to invert the data you get, you will have to do that manually by copying the data around.

Upvotes: 2

Related Questions