Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What are the differences between gl_TexCoord[0].s, gl_TexCoord[0].t gl_TexCoord[0].p and gl_TexCoord[0].x, gl_TexCoord[0].y gl_TexCoord[0].z ?

I understand that gl_TexCoord[0].x, gl_TexCoord[0].y gl_TexCoord[0].z are pixel coordinates?

But what do gl_TexCoord[0].s, gl_TexCoord[0].t gl_TexCoord[0].p mean and where must I use them?

share|improve this question

The difference is only semantic. Any GLSL vector can be accessed using x/y/z/w, r/g/b/a or s/t/p/q. Typical use is:

  • xyzw for space coordinates
  • rgba for colours
  • stpq for texture coordinates
  • if none of the above applies, any flavour can be used, but when it could be confusing, var[0]/var[1]/var[2]/var[3] can be used instead.

You can mix them in expressions: foo.x = bar.q, or even foo.xy = +;. The major restriction is that swizzling can only be done using letters of the same group, ie. foo.xya is invalid because it mixes xy from xyzw and a from rgba.

share|improve this answer
I'm not familiar with the stpq notation for texture coordinates (have always seen uv instead). I'm guessing p would be used for 3D textures, but in what situation would q be used? Edit: Nevermind I just found my answer. That would be, with TextureCubeArrays. – David Gouveia Dec 13 '11 at 14:18
@DavidGouveia: No, actually. The different texturing functions have different meanings. For example, accessing a sampler2DShadow with texture means that the p coordinate is the comparison value. Accessing a sampler2DShadow with textureProj means that the p coordinate is the comparison value, and the q coordinate is divided into the other three (before comparison, so p is actually comparison * q). They don't have any intrinsic meaning; the meaning changes depending on how they are used. – Nicol Bolas Dec 13 '11 at 17:59
@Nicol Thanks for clearing that up. I've actually only used HLSL before and even there only ever really needed the basic tex2D and texCube intrinsics. I was unaware of the multitude of existing texturing functions. (Unrelated: Is that your real name, or just the dragon from MTG?) – David Gouveia Dec 13 '11 at 18:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.