Sign in to follow this  
FreJa

strange glsl behavior (texturing)

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this