Hello!
I try to understand the following texture mapping shader :
Code :/* vertex shader */ varying vec4 v_color; varying vec2 v_texCoord; void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; v_color = gl_Color; v_texCoord = vec2(gl_MultiTexCoord0); }
and
Code :/* fragment shader */ varying vec4 v_color; varying vec2 v_texCoord; uniform sampler2D tex0; void main() { gl_FragColor = texture2D(tex0, v_texCoord) * v_color; }
I don't understand the meaning of the v_texCoord vertor. When we send data to opengl we associate to each vertex a texture coordinate with glTexCoord. This mean that during rasterisation, texture mapping depend of the three texture coordinates associated with the three vertices. So how the fragment shader can access the texture with only one coordinate that come from the vertex shader ?
Seems that I don't really understand how the shaders works... For me, the following code :
Code :v_texCoord = vec2(gl_MultiTexCoord0);
Send to the fragment shader the texture coordinate of the last vertex that pass through the vertex shader ....




many thanks to you for your clarification ! I will try to use GL3.1 as main opengl version and provide compatibility for older GL version as far I found the motivation.