How to load a shader from outside /data path

is a simple question, as the title said:

how can i load a shader from outside the /data path folder? its possible ? when im try to compiled a shader load from another folder (i want one for fragments and another one for vertex s file) this error show:

OpenGL generated error 1282 trying to get the program link status, does your video card support shader programs?

im using ofFile to get the absolutePath. its work fine if the shaders are in the data folder

Hello pxt,

As far as I’m concerned, it works for me using an ofPath :

// path for loading files is starting from bin/data inside your app, 
// so to get a folder called shaders inside your src/ folder :  
 filesystem::path path = filesystem::path("../../src/shader");
    gShader.load(path/"pass.vert", path/"pass.frag", path/"tri.geom");

It works for me using Xcode and Openframeworks 10.1.

Hope this helps,


not for me :frowning:

[ error ] ofShader: setupShaderFromFile(): couldn’t load GL_FRAGMENT_SHADER shader from "/…/…/…/…/…/…/…/src/shaders/gBuffer.glsl"

filesystem::path dirFolderColorShaders = filesystem::path("/.../.../.../.../.../.../.../src/shaders");
    shader.load("gBufferVertex.glsl",  dirFolderColorShaders/"gBuffer.glsl");


I think you are not inputing the path correctly, and you are not using it correctly when loading :slight_smile: :

  1. going one director up in the architecture takes ../ :
    if my shader folder is inside my src folder ( see picture )

, I can use this path :

 filesystem::path path = filesystem::path("../../src/shader");

so you path, assuming that you have a src folder 7 folders up would be :

filesystem::path dirFolderColorShaders = filesystem::path("../../../../../../../src/shaders");

(which also means that you are outside your OF install and one folder up in the hierarchy btw).

  1. the path needs to be set in front of each name, so the vertex shader, and the fragment shader are being pulled from the same location:
    shader.load(dirFolderColorShaders/"gBufferVertex.glsl",  dirFolderColorShaders/"gBuffer.glsl"); 

Also, I guess you should try to check the excellent addon from @hrs on 360 Projection here, and see how he uses the filesystem::path to reference his shaders.

Hope this helps,


1 Like

! i think that problem exist only when i generate a new project, cos with the examples works fine…
i dont know. even i try “/folder/shader” and still not working. but if i do in some of the examples it works!
?? :confused:

EDIT: my mistake. for some reason when copy+paste the shader to another folder the .glsl file its erased.
solve with the help of @pierre_tardif00

1 Like