3

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.

BKreger
  • 89
  • 1
  • 1
  • 11

1 Answers1

4

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] << " ";
     }
}
samgak
  • 23,944
  • 4
  • 60
  • 82
  • When I try that I only get what I assume is symbols representing ascii text – BKreger Apr 24 '15 at 06:19
  • put the unary plus operator in front to convert to a number – samgak Apr 24 '15 at 06:22
  • Now im seeing it! so i guess now im a little stumped, how would I go about changing these values? when I try and just directly change them I get a coredump – BKreger Apr 24 '15 at 06:45
  • You can use glDrawPixels: https://www.opengl.org/sdk/docs/man2/xhtml/glDrawPixels.xml However this is kind of fighting against the way OpenGL works because you are effectively doing software rendering. Can you change the widget rendering to make it render brighter in the first place? – samgak Apr 24 '15 at 06:51
  • I really wouldnt know where to start considering this is built off of another project for a gui course im taking, I thought that glDrawPixels just writes the information back to the buffer from memory? im looking to alter the pixel data before pushing it back – BKreger Apr 24 '15 at 07:03
  • You should be able to modify the contents of your pixels[][][] array before writing it back with glDrawPixels. I don't know why you're getting a core dump, an index out of bounds maybe? – samgak Apr 24 '15 at 07:05
  • I was calling glDrawPixels with GL_UNSIGNED_INT, I know that glFLush is supposed to push the framebuffer back to the viewport but im not getting any changes :P – BKreger Apr 24 '15 at 07:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76136/discussion-between-bkreger-and-samgak). – BKreger Apr 24 '15 at 07:08