PDA

View Full Version : Stencil Read -> RGB Write query



pocketmoon
01-04-2003, 04:38 PM
Hi Folks

A quick test http://www.opengl.org/discussion_boards/ubb/smile.gif

unsigned char pStencil[4096];
unsigned char pStencil2[4096];

//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
glDrawPixels(64,64,GL_RED,GL_UNSIGNED_BYTE, &pStencil);

//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)

TIA

Rob

Bob
01-05-2003, 02:25 AM
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.

pocketmoon
01-05-2003, 02:52 AM
does lighting, fogging etc effect drawpixels ??

Bob
01-05-2003, 03:55 AM
glDrawPixels generates fragments that are passed through the pipe as just like fragment generated by primitives.

pbrown
01-06-2003, 09:48 PM
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.

pocketmoon
01-07-2003, 11:04 AM
thanks chaps