c++qtopenglglreadpixels

reading pixel data from framebuffer


Im writing an interface in qt using opengl and I have a QGLWidget that has some vertices drawn to the screen.

Im trying to change the pixel data to make the image brighter however glreadpixels is giving very bizarre results

im reading the pixels into a 3-dimensional array so as to see the position and RGB values.

here is some of my code

GLuint pixels[w][h][3];
glReadPixels( 0, 0, w, h, GL_RGB, GL_INT, pixels)

for(int i = 0; i < w; i++)
     for(int j = 0; j < h; j++)
         cout << pixels[i][j][0] << " ";
         cout << pixels[i][j][1] << " ";
         cout << pixels[i][j][2] << " ";

right now my goal is only to see pixel data printed out, but the output I get in the terminal is almost all 0's however when I do see something other than 0 its very large much larger like 4294967295.

I know that color values range from 0-255 so im not really sure what is going on.


Solution

  • If you are storing each component as a separate element in your array then the array should be of type GLubyte (range 0-255). Also, the type requested should be GL_UNSIGNED_BYTE:

    GLubyte pixels[w][h][3];
    glReadPixels( 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    
    for(int i = 0; i < w; i++)
    {
         for(int j = 0; j < h; j++)
         {
             cout << +pixels[i][j][0] << " ";
             cout << +pixels[i][j][1] << " ";
             cout << +pixels[i][j][2] << " ";
         }
    }