Sign in to follow this  
troxtril

[SOLVED] strange shader problem

Recommended Posts

hey, I have problem with shaders. in a nutshell, I can't sample a cube texture if I set program to 0 after I draw the primitive with my shader. the render loop is like the following:
/* vbo, shaders and textures initialized above */

/* first pass with first shader. no cube maps. */
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, my_2d_tex1);
glUniform1i(glGetUniformLocation(shader1, "tex1"), 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, my_2d_tex2);
glUniform1i(glGetUniformLocation(shader1, "tex2"), 1);

 /* Other uniforms updated here */

glUseProgram(shader1);
glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, (const GLvoid*) 0);

/* second pass with second shader cube texture sampling */
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, my_2d_tex3);
glUniform1i(glGetUniformLocation(shader2, "tex1"), 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_CUBE_MAP, my_cube_tex);
glUniform1i(glGetUniformLocation(shader2, "cubetex"), 1);

 /* Other uniforms updated here */

glUseProgram(shader2);
glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_SHORT, (const GLvoid*) 0);

/* now I want to disable shaders for some reason. if I put this line, the 
second shader won't work although first shader works fine. it just won't put a
single face on the scene with no error. IF I REMOVE THIS LINE OR REMOVE THE
LINE WITH textureCube() FUNCTION IN SECOND SHADER, SECOND SHADER WORKS JUST
FINE. */
glUseProgram(0);

/* other stuff and buffer swapping below */







can anyone help? [Edited by - troxtril on July 22, 2009 2:22:02 PM]

Share this post


Link to post
Share on other sites
Yes, that's simple. call

glUseProgram(shader2);
glUniform1i(glGetUniformLocation(shader2, "tex1"), 0);
glUniform1i(glGetUniformLocation(shader2, "cubetex"), 1);

the right shader must be bound when you call glUniform.
Even better,
glUseProgram(shader2);
if(glGetUniformLocation(shader2, "tex1")!=-1)
glUniform1i(glGetUniformLocation(shader2, "tex1"), 0);
if(glGetUniformLocation(shader2, "cubetex")!=-1)
glUniform1i(glGetUniformLocation(shader2, "cubetex"), 1);

http://www.opengl.org/wiki/GLSL_:_common_mistakes#glUniform_doesn.27t_work

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