A quick test
unsigned char pStencil;
unsigned char pStencil2;
//Seems to work ok (viewing the contents of pStencil afterwards)
glReadPixels( 0, 0, 64, 64, GL_STENCIL_INDEX , GL_UNSIGNED_BYTE, &pStencil);
glColorMask(1, 0, 0, 0); // Only update red
//and read 'em back again
glReadPixels( 0, 0, 64, 64, GL_RED , GL_UNSIGNED_BYTE, &pStencil2);
The question: What should a stencil buffer value of 128 (as read back into pStencil) get readback into pStencil2 as (from Red)
128 in gives me 16 out. I’m not changing any the pixel transfer or maps so I tought the range should be expaned
128 ( pStencil ) -> 0.5 ( Red) -> 128 (pStencil2)
I would expect the red component to be 0.5 (or 128 if you’re reding it as unsigned chars), as you said, but that assumes every operation that affects a fragments color is disabled, like lighting, texturing and fogging. Make sure they are disabled.
does lighting, fogging etc effect drawpixels ??
glDrawPixels generates fragments that are passed through the pipe as just like fragment generated by primitives.
You can think of DrawPixels as drawing a bunch of rectangles. The position, color, texture coordinate, and so on are taken from the transformed current raster position (RasterPos). PixelZoom specifies the size of each rectangle (1.0,1.0) means 1x1 like a normal primitive.
The DrawPixels data replaces the appropriate attribute for all fragments. Color DrawPixels commands replace the color – the fragment depth comes from the raster position. DEPTH_COMPONENT DrawPixels commands replace the depth value, color comes from the current raster position.
All the normal per-fragment rasterization operations apply, including texturing and fog. All the normal fragment operations also apply (scissor, alpha test, stencil test, depth test, blending, even dithering!).
Interestingly, you would use a DEPTH_COMPONENT DrawPixels call to modify the depth buffer. But in the default state, it would appear to be a rectangle with the raster position’s color. You actually have to enable DEPTH_TEST (with the func set to ALWAYS) to write to the depth buffer. And if you don’t want to write to the color buffer at the same time, you need to call ColorMask to disable such writes.
STENCIL_INDEX DrawPixels commands are special – these just load the stencil buffer.
In your example, make sure you have operations like blending disabled.