I am using render to texture and I want to read data back to CPU side of the program. I am using PBO to do this. However, if I save content of texture to the file, data are vertically flipped (upside down). Is this a normal behavior, or I have something incorrect?

PBO init:

glGenBuffers(1, pboID);

glBindBuffer(GL_PIXEL_PACK_BUFFER, pboID);
glBufferData(GL_PIXEL_PACK_BUFFER, texture->info.rawDataSize, 0, GL_DYNAMIC_READ);

glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

PBO readback:

glBindFramebuffer(GL_FRAMEBUFFER, texture->GetRenderTarget()->GetFrameBufferID());


glReadPixels(0, 0, texture->info.width, texture->info.height, texture->info.glFormat, GL_UNSIGNED_BYTE, 0);

void * textureData = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);

//save tetxure data to file

//unlock PBO and FrameBuffer

I know that texture coordinates are "flipped" in comparison to DirectX, so during rendering on the screen, I am flipping the y-coordinate as well (y = y - 1). But how to download texture data "non-flipped"?


1 Answer 1



glReadPixels and glReadnPixels return pixel data from the frame buffer, starting with the pixel whose lower left corner is at location (x, y), into client memory starting at location data.

(My emphasis)

So yes, in OpenGL it is perfectly normal and expected behaviour for the bottom-left to be the origin.

Note that when specifying textures, since both glTexImage/glTexStorage and texture coord specification use bottom-left-is-origin, in most use cases they actually cancel each other out and you can use the same texcoords as in Direct3D.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .