// In our vertex shader, we need to add a new varying variable. // I am going to call this texCoord, and it is a vec2: // varying vec2 texCoord; // I then need to assign some values to this variable. But first // I will explain what this variable will do. This variable will // hold the texture coordinates for the current vertex. The // texture coordinates for the teapot which is a predefined GLUT // shape are already assigned in OpenGL by GLUT. So to read them // in, we use the line: // texCoord = gl_MultiTexCoord0.xy // gl_MultiTexCoord is generally used to store texture coordinates // but some people like to store variables in this that will // then be used for other means inside the shader. I am going // to stick with using it for texture coordinates as it is // simpler and less confusing. Also note that I am adding .xy // to the end of gl_MultiTexCoord0, this is to call the // first two parts of the variable because texCoord is only // a two part variable and gl_MultiTexCoord can hold 3D textures // which could be called with .xyz. varying vec2 texCoord; varying vec3 Normal; varying vec3 Light; varying vec3 HalfVector; void main(void) { texCoord = gl_MultiTexCoord0.xy Normal = normalize(gl_NormalMatrix * gl_Normal); Light = normalize(gl_LightSource[0].position.xyz); HalfVector = normalize(gl_LightSource[0].halfVector.xyz); gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }