• Advertisement
Sign in to follow this  

strange glsl behavior (texturing)

This topic is 3381 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:
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?


Share this post

Link to post
Share on other sites
Original post by V-man
Are you checking to make sure the shader compiled correctly?

Have you tried a debugger?

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
Sign in to follow this  

  • Advertisement