PDA

View Full Version : Multiple Shaders



xerzi
06-12-2011, 03:01 PM
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).

Alfonse Reinheart
06-12-2011, 03:02 PM
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.

mhagain
06-12-2011, 04:27 PM
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.

xerzi
06-12-2011, 07:20 PM
Already thanks guys, it turned out to be something else.