Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>and some of the textures have an alpha color which should be invisible.</p> </blockquote> <p>This is actually called a <em>keying color</em>.</p> <p>The alpha channel is an additional channel, adding to the "normal" RGB channels. When alpha blending is used, one uses the alpha channel value as opacity.</p> <blockquote> <p>I can figure this out just by looking at it. The problem is, how do I find this value in the file?</p> </blockquote> <p>If a color key is used, one uses either some specific color, used for all images, or stores the keying value separately, loading it with the image file. Another common technique is to use the value of the upper left pixels as keying color.</p> <blockquote> <p>How do I accommodate for the fact a color needs to be removed from the texture when rendered?</p> </blockquote> <p>By preparing the image data with a color key generated alpha channel:</p> <pre><code>for(i = 0; i &lt; pixelcount; i++) { if( source[i].r == key.r &amp;&amp; source[i].g == key.g &amp;&amp; source[i].b == key.b ) { dest[i].r = dest[i].g = dest[i].b = dest[i].a = 0; continue; } dest[i].r = source[i].r; dest[i].g = source[i].g; dest[i].b = source[i].b; dest[i].a = 255; } </code></pre> <p><strong>Update</strong>: <em>In the case of color key generated alpha channel, one can use <strong>alpha testing</strong> instead of blending. The nice thing with alpha testing is, that it doesn't requires to depth sort the geometry prior to drawing.</em></p> <pre><code>glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.5); </code></pre> <p>The ideal way would be to use a image file format with alpha channel support (PNG, TGA, OpenEXR, …), and not using BMPs (actually the BMP file format would allow for a 4th channel, and in fact I once wrote my own BMP loader with alpha channel support, and a Photoshop export plugin, many years ago).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload