i think u have to select the buffer before using Readpixels(). bcoz the default buffer settings for the buffer are not working for me. if u done so … r u able to see any out put? otherwise first check weather u r making current RC (usually will be over looked if rendering routine and glReadPixels routine r different) ; sorry i confused u! but i also got the same problem but it is solved now. and use this code for pixel 4 byte packing before read pixels
Using glColor4ub I have encoded information
with each triangle. How the glReadPixels with GL_RGBA always return 0 0 0 255. (r,g,b,a).
My encoding starts at 0 0 0 0, 0 0 0 1…
0 0 0 255, 0 0 1 0 and so on. I check the encoding and it is fine. However, when I read back I get always 0 0 0 255.
Thanks indra. I posted right as you were posting. I solved the previous problem, but now I seem to be unable to extract the information from the color buffer. Thanks to both of you.
Originally posted by kingindra:
i think u have to select the buffer before using Readpixels().
Not for the stencil or depth buffer, there’s only one each.
more over using that glFinish(); is important ! otherwise GL might not complete the drawing instructions before u use glReadPixels();
Sorry, this is not true. glReadPixels is synchronous.
If you have an implementation where this is not working, update your driver and/or report a bug to the vendor.
You should almost never need to call glFinish in a standard OpenGL program, except for benchmarking or synchronization with other graphics drawing.
Originally posted by maximian:
The problem is with glReadPixels and color buffer.
Using glColor4ub I have encoded information
with each triangle. How the glReadPixels with GL_RGBA always return 0 0 0 255. (r,g,b,a).
My encoding starts at 0 0 0 0, 0 0 0 1…
0 0 0 255, 0 0 1 0 and so on. I check the encoding and it is fine. However, when I read back I get always 0 0 0 255.
[/b]
Same checks as above plus some tips:
Do you have a destination alpha buffer in your pixelformat?
glGetIntegerv(GL_ALPHA_BITS, &a); What’s a?
If there is no destination alpha, OpenGL returns 1.0 for the alpha which is 255 in unsigned byte format.
You method will not work in in highcolor.
If you have encodings per triangle make sure you use flat shading and no lighting.
This time check glReadBuffer(), front or back?
Do not rely on the back buffer contents if you have called SwapBuffers. Pixelformats which support PFD_SWAP_EXCHANGE have undefined back buffer contents after.
Do not glReadPixels from areas which are overlapped by other windows. The result is undefined.