I’m doing a Lighthouse3d GLSL tutorial and have encountered a slight problem I’m hoping someone can help me with. I’ve gotten through most of it with no problems but now I have no color on my object in the point light section. I’ve triple checked to make sure I have the code right but still no luck. I did try adding a uniform vec4 variable called myColor to the fragment shader and found when I multiplied it by the color in the gl_FragColor line that it was still black but when I add it to the variable color it changes the color, because of this I imagine that my color variable ends up having a value of 0. 0. 0. 0. Also the tutorial tells me that I can use gl_Position = ftransform();

rather than gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; but this came up with an error so I just keep using the latter. Is this a TD thing or am I doing something wrong?

Any help would be totally appreciated

the shaders and file are below.

thanks

Keith

//vertex shader

varying vec4 diffuse,ambient,ambientGlobal;

varying vec3 normal,lightDir,halfVector;

varying float dist;

void main()

{

```
vec4 ecPos;
vec3 aux;
//first transform the normal into eye space and normalize the result
normal = normalize(gl_NormalMatrix*gl_Normal);
//compute the light's direction
ecPos = gl_ModelViewMatrix * gl_Vertex;
aux = vec3(gl_LightSource[0].position-ecPos);
lightDir = normalize(aux);
dist = length(aux);
// Normalize the halfVector to pass it to the fragment shader
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
// Compute the diffuse, ambient, and globalAmbient terms
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
//the ambient terms have been separated since one of them suffers attenuation
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
```

}

//fragment shader

varying vec4 diffuse,ambient,ambientGlobal;

varying vec3 normal,lightDir,halfVector;

varying float dist;

void main()

{

```
vec3 n,halfV,viewV,ldir;
float NdotL,NdotHV;
vec4 color = ambientGlobal;
float att;
// a fragment shader can't write a varying variable, hence we need
// a new variable to store the normalized interpolated normal
n = normalize(normal);
// compute the dot product between normal and light direction
NdotL = max(dot(n,lightDir),0.0);
if (NdotL > 0.0)
{
att = 1.0 / (gl_LightSource[0].constantAttenuation +
gl_LightSource[0].linearAttenuation * dist +
gl_LightSource[0].quadraticAttenuation * dist * dist);
color += att * (diffuse * NdotL + ambient);
halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
pow(NdotHV, gl_FrontMaterial.shininess);
}
gl_FragColor = color;
```

}

Lighthouse tutorial.toe (8.02 KB)