ofShader::load vs ofShader::setupShaderFromFile

When I try to substitute the line



shader.setupShaderFromFile(GL_FRAGMENT_SHADER, "shadersGL3/shader.frag");
shader.setupShaderFromFile(GL_VERTEX_SHADER, "shadersGL3/shader.vert");

the program tends to not work anymore. Why does that always happen? I want to use this because then I can reuse the same standard pass vertex shader and only change the fragment shaders for post processing effects. The above code sample is from the simpleTexture tutorial on github, which I tested, and it also doesn’t work. Any ideas?

Hi there!

Since you are using GL3, you should also do:


Before linkProgram(). Alternately, you can also do:

shader.load("vertex.vert", "frag_#.frag");

So that you can still share the same vertex shader.

You could also check the vboMeshDrawInstancedExample example, where it uses a shared_ptr. It’s a simple, but nice way to use/play with shaders.

1 Like

Great, that solves the problem.

That example looks quite useful, and it’s well commented too, thanks!