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 3 of 3

Thread: Transparency within textures

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2001
    Location
    France
    Posts
    19

    Transparency within textures

    I'm trying to implement the well known method to create realistic trees with "holes" in them (i.e. the spaces between leaves are not textured, but transparent).

    I'm wondering what is the best way to achieve this. I would use TGA files. Is it a good idea ? Some people mention PNG ... But use of this format requires some extra libraries (e.g. libpng,zlib), which is not the case as far as TGA is concerned. What are the pros and cons ? Anyway, is there any piece of code available somewhere about this ?

    Regards.

  2. #2
    Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Dunblane, Scotland
    Posts
    333

    Re: Transparency within textures

    What you need is a format that supports an alpha channel and TGA support this. They are also very easy to read, for a tutorial look a NeHe's website.
    Reality is for idiots only the best over come it!

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: Transparency within textures

    Hi,

    just 2 days ago, I implemented the same thing for my "Engine". Itīs pretty simple.

    I think you know how to load BMPs. When you do this you have one array with 3 bytes per pixel, where you or a windows function stores the data in. After this just allocate a second array with 4 bytes per pixel. Now you just test in the first array every three bytes, if this is a special color. For example I test if the first byte is 255 (completely red) the second 0 (no green) and the third 255 (completely blue), which is the value of violet. If it is I know I want this pixel to be transparent. Then I copy these pixels into my second, 4 byte per pixel array but also set the value of the 4th byte. If the color was 255,0,255 I set the 4th byte 0 else 255. After all I generate my texture as RGBA and thatīs it. Donīt forget to enable blending. Also you seem to have to sort the polys back to front when drawing, else you get just black where it should be transparent.

    Good luck.
    GLIM - Immediate Mode Emulation for GL3

Posting Permissions

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