Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: How to transfer a bitmap to the stencil buffer

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Austria
    Posts
    3

    How to transfer a bitmap to the stencil buffer

    hi,
    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

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: How to transfer a bitmap to the stencil buffer

    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...

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Austria
    Posts
    3

    Re: How to transfer a bitmap to the stencil buffer

    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

  4. #4
    Intern Contributor
    Join Date
    Feb 2004
    Posts
    98

    Re: How to transfer a bitmap to the stencil buffer

    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).]

  5. #5
    Junior Member Newbie
    Join Date
    May 2001
    Location
    sthlm
    Posts
    13

    Re: How to transfer a bitmap to the stencil buffer

    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.

  6. #6
    Junior Member Newbie
    Join Date
    Feb 2004
    Location
    Austria
    Posts
    3

    Re: How to transfer a bitmap to the stencil buffer

    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 ;-(

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: How to transfer a bitmap to the stencil buffer

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •