How to transfer a bitmap to the stencil buffer

hi,
i have a problem :wink:
i want to make a dynamic mask which is based on a black and white bitmap.
for performance reasons i thought about using the stencil buffer for it, but I don’t get the point how to copy the bitmap to the stencil buffer.
any ideas, otherwise i’ll stick to blending

Check the docs on glDrawPixels.

"GL_STENCIL_INDEX:
Each pixel is a single value, a stencil index.
The glDrawPixels function converts it to fixed-point format, with an unspecified number of bits to the right of the binary point, regardless of the memory data type. Floating-point values convert to true fixed-point values. The glDrawPixels function converts signed and unsigned integer data with all fraction bits set to zero. Bitmap data converts to either 0.0 or 1.0. "
and so on…

thx for the hint, but i’m still not succeeding, that’s what i do right now

glRasterPos2i(0,0); // thought i would need that but it even makes it worse
glDrawPixels ( TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_STENCIL_INDEX,
GL_SHORT , (GLvoid *) TextureImage[0]->data );

the texture file is a 16 bit bmp.

anyway i am not too sure if stencil buffer is the best way to do dynamic masking.

still ideas how to find the holy grail of masking ?

I played around with the data types and sometimes something is masked out but not like the masking texture looks like and it is quite slow i think to copy a fullscreen mask to the stencil buffer.

help appreciated

You check GL_STENCIL_BITS to see how deep the stencil buffer is. The values in the bmp might be directly copied, instead of converted into 1’s and 0’s. A 16-bit bmp probably contains a palette, or might be 565RGB or something similar(in which case you get 0’s and 65535’s).

[This message has been edited by chemdog (edited 02-17-2004).]

Are you using glOrtho instead of glFrustum. Otherwise it can mess things up, atleast when using ReadPixels so I guess it would be the same with DrawPixels.

thx to you all, I got it to run in principle but it is much too slow because I write to the stencil buffer every frame (have to do this because I have a dynamic mask).
glDrawPixels seems to be awful slow.
have to find a faster solution ;-(

And what about just using alpha testing, so you are done with a RGBA textured quad ? It may or may not be faster.