• Advertisement
Sign in to follow this  

[SOLVED] strange shader problem

This topic is 3108 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

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
Advertisement
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
ah great. that solved. thanks.. I thought this way because you already give the program handle in glGetUniformLocation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement