View Full Version : How to transfer a bitmap to the stencil buffer
02-17-2004, 05:49 AM
i have a problem ;-)
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
02-17-2004, 06:12 AM
Check the docs on glDrawPixels.
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...
02-17-2004, 07:37 AM
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->sizeX, TextureImage->sizeY, GL_STENCIL_INDEX,
GL_SHORT , (GLvoid *) TextureImage->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.
02-17-2004, 06:19 PM
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).]
02-19-2004, 02:44 AM
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.
02-19-2004, 03:58 AM
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 ;-(
02-19-2004, 04:34 AM
And what about just using alpha testing, so you are done with a RGBA textured quad ? It may or may not be faster.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.