Multiple Shaders

I need to be able to use more than one shader but I’m not entire sure how to do this.


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(myshader);// "myshader" being the linked program

// draw a model here using "glDrawElements"

glClear(GL_DEPTH_BUFFER_BIT);
glUseProgram(0);

glEnable(GL_TRIANGLES);
 glColor3f(1, 1, 1); glVertex3f(1, 0, 0);
 glColor3f(1, 1, 1); glVertex3f(0, 1, 0);
 glColor3f(1, 1, 1); glVertex3f(0, 0, 1);
glEnd();

The problem with is that everything uses the default shader glUseProgram(0).

Of course it does; that’s what you told it to do. If you want to use the other shader, then you call glUseProgram with that other shader as a parameter.

I think these lines are the ones that the OP is referring to:

glUseProgram(myshader);// "myshader" being the linked program

// draw a model here using "glDrawElements"

If I’ve read it right, actual drawing of the model has been omitted for clarity and brevity, and the problem is that despite this glUseProgram call the default (0) shader is still being used.

If this is the case, maybe try checking the output of your compilation to make sure that there are no errors, and also check that “myshader” doesn’t have a value of 0.

Already thanks guys, it turned out to be something else.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.