multiple GLSL shaders (images!)

Started by
2 comments, last by MattHughes 15 years, 11 months ago
Hello, I'm starting to understand the basics of GLSL and have been toying around with it all afternoon. What I don't understand is how to specify which shader is being used on a certain object. For example, I have this colorful vertex shader: I also have this mediocre toon fragment shader: What would I do if I want the monkey to render with the toon shader, and the human with the colorful shader? Every tutorial that I've found has assumed that I want a shader to apply to the entire scene.
Advertisement
You've got to render the two objects using two separate draw calls (which usually means the two objects will be in different vertex/index buffers).

Before each draw call you set up the appropriate shader.
When you will render an object, the call sequence might look something like

for all objects;
glBindTexture(...) //Texture
glUseProgram(...) //Shader
glUniform4fv(....) //Uniforms
glBindBuffer(...) //VBO
glVertexPointer(...) //VBO offsets
glBindBuffer(...) //IBO
glDrawRangeElements(....)
repeat;
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Perfect. Thanks so much.

This topic is closed to new replies.

Advertisement