View Full Version : Transparency within textures
06-14-2001, 11:56 PM
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 ?
06-15-2001, 01:00 AM
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.
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.