Tex Coord Question FROM new guy

In an example from 3dlabs called “earth”,i knew how to use one texture.

my question is if i want to use 2 or more textures in glsl application,how to bind the texcoord with the correct vertex position ? In the fixed func,i know before glVertex<X><D>(), i should use gltexcoord(X,X).

in fragment shader, i can use the an varying vertex postion,but how can i seperated one from others?

Originally posted by Jedimaster:
[b]In an example from 3dlabs called “earth”,i knew how to use one texture.

my question is if i want to use 2 or more textures in glsl application,how to bind the texcoord with the correct vertex position ? In the fixed func,i know before glVertex<X><D>(), i should use gltexcoord(X,X).

in fragment shader, i can use the an varying vertex postion,but how can i seperated one from others?[/b]
There are predefined varying variables called gl_TexCoord[]
so for the first tex. unit you use gl_TexCoord[0]
for the second gl_TexCoord[1], etc…

If you’re using mixed mode, using fixed function for the vertices and programmable (fragment shader) for the fragments the best option is to use the built ins as described. They will be set as varyings by fixed function and can be accesed with gl_TexCoord[i] in the fragment shader.

If, however, you are using both a fragment and vertex shader you’re better off to declare a varying explicitly that is correctly sized. Here is how you would do two sets of texture coordinates in your vertex shader so your fragment shader can access the interpolated coordinates.

varying vec2 texCoord0;
varying vec2 texCoord1;

void main()
{
   texCoord0 = glMultiTexCoord0.xy;
   texCoord1 = glMultiTexCoord1.xy;
   . . .

Avoid using the built in gl_TexCoord[i] unless you want all four coordinates in your fragment shader interpolated linearly and perspective correction applied or are not using a vertex shader. Normally only the s and t coordinates are desired so a vec2 works best. This should conserve varyings and potentially increase performance.

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