Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, look at this answer regarding <a href="https://stackoverflow.com/questions/4012035/opengl-es-iphone-alpha-blending-looks-weird">PNG transparency and premultiplied alpha.</a> Long story short, the pixels in the PNG image that have less than 100% opacity are being premultiplied, so they are in effect getting darker as they get more transparent. Hence the dark artifacts around the edges.</p> <p>Even without PNG and premultiplied transparency, you may still run into the problem if you forget to set your fragment shader's color before applying transparency. </p> <p>A solution to this problem (where you want text to be a light grey color, and everything in the texture map that's not text to be transparent) would be to create a texture map where your text is white and the background is black.</p> <p>This texture map will control the alpha of your fragment. The RGB values of your fragment will be set to your light grey color. </p> <p>For example:</p> <pre><code>// color used for text lowp vec4 textColor = vec4(.82,.82,.82,1.0); gl_FragColor = textColor; // greyscale texture passed in as uniform lowp vec4 alphaMap = texture2D(u_alpha_texture,v_texture); // set the alpha using the texture gl_FragColor.w = alphaMap.x; </code></pre> <p>In cases where your color texture varies, this approach would require two separate texture map images (one for the color, and one for the alpha). Clearly, this is less efficient then dealing with one PNG that has alpha transparency baked-in. However, in my experience it is a good tradeoff (premultiplied pixels can be counter-intuitive to deal with, and the other approaches to loading PNG transparency without pre-multiplication introduce added complexity).</p> <p>An upside to this approach is that you can vary the color of the text independently of the texture map image. For instance if you wanted red text, you could change the textColor value to:</p> <pre><code>lowp vec4 textColor = vec4(1.0,0.0,0.0,1.0); </code></pre> <p>You could even vary the color over time, etc, all independently of the alpha. That's why I find this approach to be flexible. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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