Sampling an alpha texture with texture2D

I want to use an 8-bit texture as a mask. I upload the texture in GL_ALPHA format. How should I sample it? texture2D() returns a vec4 - does every component of the vec4 contain the sampled value, or only the last (.a) component?

Only the alpha component. This is how the texture formats get expanded to vec4:

GL_ALPHA            (0, 0, 0, A)                    
GL_RGB              (R, G, B, 1)
GL_RGBA             (R, G, B, A)
GL_LUMINANCE        (L, L, L, 1)
GL_LUMINANCE_ALPHA  (L, L, L, A)

Just what I was looking for, thanks.

PS: Is this documented in the spec at all? I had a look but couldn’t find it?

Yes, it’s table 3.12 in the full spec.

Full spec you say…

:oops: I’ve been using the difference spec for all this time! Thank you, I think you’ve probably saved me from months more of frustration. I no longer have to flick between the desktop OpenGL 2.0 spec and the ES 2.0 diff spec! :smiley:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.