Results 1 to 4 of 4

Thread: Texturing a png so alpha channel part is transparent?

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Texturing a png so alpha channel part is transparent?

    Hello I have a PNG with an alpha channel I would like it so the transparent parts of the image
    are transparent when I texture to a quad. Right now they just show up as white. Considering the results I'm getting I'm guessing its not as easy as giving the WebGL API a png with an alpha channel. If anyone knows how to do this I would love to hear how you did it.

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: Texturing a png so alpha channel part is transparent?

    Did you remember to enable blending?

    gl.enable ( gl.BLEND ) ;

    Does your shader copy the alpha channel of the texture into the alpha channel of the output?

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Re: Texturing a png so alpha channel part is transparent?

    Thanks for the reply. I do not have blend enabled. I will do that.

    My shader looks like this:

    #ifdef GL_ES
    precision highp float;
    #endif
    varying vec2 vTextureCoord;
    uniform sampler2D uSampler;
    void main(void)
    {
    gl_FragColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
    }

    Is what I'm doing here copying the alpha channel to the output?

  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    15

    Re: Texturing a png so alpha channel part is transparent?

    Using the above shader and adding these two lines of code got parts of my sprite to be transparent exactly as I wanted.

    gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
    gl.enable(gl.BLEND);

    That was suprisingly easy!

Similar Threads

  1. Drawing masked sprites (textured quad with alpha channel)
    By lucafr in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 02-07-2012, 09:39 AM
  2. The question about alpha-channel
    By Liberty_2000 in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 09-28-2004, 11:42 AM

Posting Permissions

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