strange glsl behavior (texturing)

Started by
2 comments, last by FreJa 15 years, 4 months ago
Hi, I'm using a simple shader in my app that implements per-pixel lighting and texturing. Here's the frag shader:

varying vec3 N;
varying vec3 v;
uniform sampler2D tex;

void main (void)
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v); 
vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 R = normalize(-reflect(L,N)); 

//calculate Ambient Term:
vec4 Iamb = gl_FrontLightProduct[0].ambient;

//calculate Diffuse Term:
vec4 Idiff = texture2D(tex, vec2(gl_TexCoord[0])) * gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);

// calculate Specular Term:
vec4 Ispec = gl_FrontLightProduct[0].specular 
                  * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
// write Total Color:
gl_FragColor = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec; 

}
Before drawing the object, I'm doing:

_shader->begin()
glBindTexture(GL_TEXTURE_2D, _texture->getId());
...


And it works! Shouldn't GLSL complain because I'm not sending the tex uniform?? And even if it doesn't complain... wy does it work? Edit: actually, setting the uniform gives me gl error #1282 (invalid operation) :( Thanks! [Edited by - FreJa on December 17, 2008 1:42:45 PM]
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Advertisement
I noticed I was using glUniform1f to pass the sampler, which was wrong. HOWEVER! the error persists when just after glUseProgram(0) is used.

Any help?

Thanks!
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."
Are you checking to make sure the shader compiled correctly?

Have you tried a debugger?
http://www.opengl.org/wiki/index.php/Debugging_Tools
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
Are you checking to make sure the shader compiled correctly?

Have you tried a debugger?
http://www.opengl.org/wiki/index.php/Debugging_Tools


Yes, I'm using Mac OS's OpenGL Shader Builder and everything is compiled and linked correcly. Also, the "API" I'm using to load the shaders are checking for those errors
"Through me the road to the city of desolation,Through me the road to sorrows diuturnal,Through me the road among the lost creation."

This topic is closed to new replies.

Advertisement