Multiplatform way to link openGL shader files?

Is there a better way to link shader files than to do String vertexShaderString = so I can more comfortably code the shader?

Yep! A good (sane) way to write shaders is to use separate text files, load them into your code as Strings at runtime, then feed them to your OpenGL programs. Or more concretely:

// Assuming you have some OpenGLShaderProgram object called oglProgram, and a
// vertex shader /path/to/myShader.vert...
bool result = oglProg.addVertexShader(File(/path/to/myShader.vert).loadFileAsString());

You might want to clean this up or break it up into separate lines, but it’ll get the job done.

Also, note the usage of .vert for the vertex shader - I prefer to follow glslang’s specification for the file extensions of shader types.

1 Like

And you are sure that path can be relative? I think File was giving me errors for using a non-full path.

Edit: Oh forgot to mention, multiple programmers are working on this project

Edit: btw im looking for an openGL programmer, see the jobs forum.

You can use a “relative” path as long as you start it with ./ (though the code sample above shows an absolute path…).