View Full Version : Obtaining RGB values with glReadPixels
04-22-2007, 02:06 PM
Whenever I have the following:
And I put it in a output file, the values in RGBData I believe are incorrect. My image is the following:
And I am trying to obtain the RGB values of the silhouette edges. However, glReadPixels give me wrong values and I am reading from the front buffer. Please help! Thank you!
If all you can say is that you get wrong values, then all I can say is that your code is wrong. Since you haven't given any details at all what the problem really is, that's as specific as I can be.
04-22-2007, 02:59 PM
If you just want the RGB data from the framebuffer then make the following call:
The format parameter of glReadPixels is the format of where the pixel is going, not the source (the framebuffer in this case).
Are you calling glReadPixels before or after you call the swapBuffers() function you're using? If you are swapping before you are reading then the front buffer is where you want to be reading from. If you are swapping after you are reading you want to be reading from the back buffer (or the current draw buffer, that can be found with a glGet* function).
Also, you are having the pixel data returned as unsigned bytes, if you're expecting floating point numbers use GL_FLOAT instead.
Hope something above helps.
04-23-2007, 03:15 AM
Mind that GL_RGB conflicts with the default glPixelStore pack and unpack alignment of 4 if the width is not a multiple of 4!
This includes effects like sheared images or crashes on out of bounds accesses of your allocated destination memory.
You should set the alignment to 1 for GL_RGB.
Same for glTexImage* and esp. for mipmaps where the 2x2 level will always be wrong with tightly packed GL_RGB unsigned bytes and default packing alignments.
04-23-2007, 07:09 AM
Whenever I swap the buffers and then use glReadPixels, I get values that are all white. I'm reading the buffer from GL_FRONT but if I do the swap after, I get the weird values that don't make sense. (Pixels at the right side are not white).
04-23-2007, 05:53 PM
'swap' is not always a real swap, sometimes it is a copy, or discard,... Can you do your readpixels (from back buffer) just after drawing, and before swap ?
Anyway, if it works with rgba and not with rgb, it should be an alignement problem.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.