From PBO to texture => the texture is flipped!

Hi,

I am succesfully rendering video using pixel buffer object (PBO) streaming. However, when the bitmap data is transferred from PBO to TEXture, the bitmap in the texture appears flipped ! (upside-down, left-to-right) … which complicates things later on.

Is such behaviour to be expected?

Below some excerpts from my code. Help appreciated!

Regards,

Sampsa

VERTICES:


  vertices =std::array<GLfloat,20>{
    //Positions          Texture Coords
    //Shader class references:
    //"position"        "texcoord"
    0.0f,  0.0f, 0.0f,   0.0f, 0.0f, // bottom left
    0.0f,  1.0f, 0.0f,   0.0f, 1.0f, // top left 
    1.0f,  1.0f, 0.0f,   1.0f, 1.0f, // top right
    1.0f,  0.0f, 0.0f,   1.0f, 0.0f  // bottom right
  };
  vertices_size=sizeof(GLfloat)*vertices.size();
  
  indices =std::array<GLuint,6>{
    0, 1, 2, // First Triangle
    2, 3, 0  // Second Triangle
  };

RESERVE PBO:


  glGenBuffers(1, &index);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, index);
  glBufferData(GL_PIXEL_UNPACK_BUFFER, size, 0, GL_DYNAMIC_DRAW); // reserve n_payload bytes to index/handle pbo_id
  
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); // unbind (not mandatory)
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, index); // rebind (not mandatory)
  
  payload = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
  
  glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); // release pointer to mapping buffer ** MANDATORY **
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); // unbind ** MANDATORY **

RESERVE TEX:


  glEnable(GL_TEXTURE_2D);
  glGenTextures(1, &index);
  
  glBindTexture(GL_TEXTURE_2D, index);
  
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  
  glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, format, GL_UNSIGNED_BYTE, 0); // no upload, just reserve 
  glBindTexture(GL_TEXTURE_2D, 0); // unbind

PBO => TEX


  format             =GL_RED;
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER, index);
  glBindTexture(GL_TEXTURE_2D, index);
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, 0); // copy from pbo to texture

Is such behaviour to be expected?

This happens because OpenGL expects the 0.0 coordinate on the y-axis to be on the bottom side of the image, but images usually have 0.0 at the top of the y-axis.
OpenGL expects the first pixel to be located in the bottom-left corner, which means that textures will be flipped…
It seems that way. Hope this helps.
Cheers