Reading pixel data from a framebuffer
I am writing an interface in qt using opengl and I have a QGLWidget that has some vertices drawn on the screen.
I am trying to change the pixel data to make the image brighter, however glreadpixels is giving very bizarre results.
im reading pixels into a 3 dimensional array to see the position and RGB values.
here are some of my codes
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 the pixel data printed out, but the output I get in the terminal is almost all 0, however, when I see something other than 0, its very large, much more than 4294967295.
I know the color values range from 0 to 255, so I'm not sure what's going on.
source to share
If you store each component as a separate item in your array, the array must be of type GLubyte
(range 0-255). In addition, the requested type must 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] << " ";
}
}
source to share