PDA

View Full Version : Sampling an alpha texture with texture2D



TomCooksey
04-16-2009, 04:52 AM
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?

Xmas
04-16-2009, 06:46 AM
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)

TomCooksey
04-16-2009, 07:10 AM
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?

Xmas
04-16-2009, 07:38 AM
Yes, it's table 3.12 in the full spec.

TomCooksey
04-16-2009, 11:41 PM
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! :D