[RESOLVED] ofShader not loading .frag or .vert files

Hey,

I’m trying to follow the Introducing Shaders chapter in ofBook. However, at the very first example 01_simpleColorQuad, using shader.load(“shadersGL3/shader”); I am unable to load the files shadersGL3/shader.vert and shadersGL3/shader.frag. The following error appears:

Looking for answers through the forums I tried using setUpShaderFromFile() directly but the vert and frag files still would not load.

I was able to get the shader to work by reading it in as a string as suggested on the setUpShaderFromSource() documentation page.

http://openframeworks.cc/documentation/gl/ofShader/#show_setupShaderFromSource

The code is just the same as the example that comes with oF 0.9.3 but here it is anyway:

main.cpp:

#include “ofMain.h”
#include “ofApp.h”

//========================================================================
int main( ){

ofGLWindowSettings settings;
settings.setGLVersion(3, 2);
settings.width = 1024;
settings.height = 768;
ofCreateWindow(settings);

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());

}

void ofApp::setup(){

#ifdef TARGET_OPENGLES
shader.load(“shadersES2/shader”);
#else
if(ofIsGLProgrammableRenderer()){
shader.load(“shadersGL3/shader”);
}else{
shader.load(“shadersGL2/shader”);
}
#endif

}

void ofApp::draw(){
ofSetColor(255);

shader.begin();

ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());

shader.end();

}

Is there something really simple that I’m not doing here?

I’m using a mid 2012 macbook pro with the Nvidia gpu enabled. IDE is Xcode. openFrameworks version 0.9.3

Many thanks

Hi there!

It appears that you are not pointing to the right directory/file. Can you check that?

Hey thanks for the response!

Here’s the file path for the frag and vert files:

/Users/bryandunphy/OF_ROOT/of_v0.9.3_osx_release/examples/shader/01_simpleColorQuad/bin/data/shadersGL3/shader.vert

/Users/bryandunphy/OF_ROOT/of_v0.9.3_osx_release/examples/shader/01_simpleColorQuad/bin/data/shadersGL3/shader.frag

I thought it might have been a problem with:

if(ofIsGLProgrammableRenderer())

but the code seems to be accessing the shader.load(“shadersGL3/shader”) call ok.

I also tried placing the load() call outside the #ifdef statement to no avail.

Can you see a problem with the file path?

Cheers!

Ok so I’ve spent a few more hours today trying to find out why shader.load() is not loading the shader files but can’t seem to figure out what’s going wrong. I had a look at the ofShader source files and everything seems to be ok. The correct filenames are being passed down through load() to setUpShaderFromFile(). However, ofBufferFromFile() does not seem to be able to find anything:

bool ofShader::setupShaderFromFile(GLenum type, string filename) {
ofBuffer buffer = ofBufferFromFile(filename);
// we need to make absolutely sure to have an absolute path here, so that any #includes
// within the shader files have a root directory to traverse from.
string absoluteFilePath = ofFilePath::getAbsolutePath(filename, true);
string sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false);
if(buffer.size()) {
return setupShaderFromSource(type, buffer.getText(), sourceDirectoryPath);
} else {
ofLogError(“ofShader”) << “setupShaderFromFile(): couldn’t load " << nameForType(type) << " shader " << " from “” << filename << “””;
return false;
}
}

Here ‘filename’ contains the correct name (ie shader.vert or shader.frag). This does suggest that I am making a mistake regarding where I am keeping my .vert and .frag files. However I currently have them in bin>data where the documentation for ofShader::load() advises.

If anyone has experienced anything like this I would be very grateful for any help. It’s probably something really obvious but I’m failing to see what it is.

Many thanks

Hi!

Sorry you are having trouble.
Just to confirm you are trying to run the 01_simpleColorQuad example from the 0.9.3 release?

I just tried and it run without error for me.

What are your system specs?
OS version, Machine, GPU etc

Also if you run the OF/examples/gl/glInfoExample and hit spacebar do you think you could paste the results to a gist?

Here is mine:

Thanks!
Theo

That’s weird. Have you tried to clean up everything and rebuild?

Hi Theo,

Apologies for the delayed response. Yes that is correct. I am trying to run 01_simpleColorQuad from oF 0.9.3. My system specs are as follows:

Also here is the gist of glInfoExample:

Many thanks for your help

Yeah it seems very strange. I’ve alternately tried placing the .vert and .frag files from each of the shadersGL2 and shadersGL3 folders, that come with the example, on their own in both the data and bin directories. I’ve also tried using absolute paths to the files using load() and setupShaderFromFile().

The only method that has worked is if I feed in the contents of the vert and frag files through a string and use setupShaderFromSource().

After all this I have also returned the code and file structure to the original example and have closed down Xcode and all that and then tried to rebuild it and run it but still not working.

It doesn’t seem related to system hardware specs. Not you you have more than enough, but you can run the shader from source setup.

I think it’s something related to file/folder permissions. Can you try to check that?

Ok so I’ve just gone through each of the vert and frag files and used chmod to set the permissions like so:
-rwxrwxrwx

Same with the bin and data folders. Still the same error. Unable to load.

can you add in ofShader.cpp after:

string sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false);

this line;

ofLogNotice() << "absolute path to shader  " << sourceDirectoryPath << endl;
ofLogNotice() << "exists? " << ofFile(sourceDirectoryPath).exists() << endl;

and post the results. also from the root folder of your project do

ls -la bin/data/shaders

Hi Arturo,

Here’s the output from the ofShader log:

And here’s a screenshot from the terminal command:

sorry can you change it to:

ofLogNotice() << "absolute path to shader  " << absoluteFilePath << endl;
ofLogNotice() << "exists? " << ofFile(absoluteFilePath).exists() << endl;

Yeah no problem. There are different results depending on whether I run it in release or debug mode.

Release:

Debug:

that’s really strange, can you try:

ofLogNotice() << "absolute path to shader  " << absoluteFilePath << endl;
ofLogNotice() << "exists? " << ofFile(absoluteFilePath).exists() << endl;
ofLogNotice() << "absolute path to OF  " << ofToDataPath(".",true) << endl;
ofLogNotice() << "filename " << filename << endl;

Hi,

sorry for the intrusion,
This happens even if you try to build a new project?
try creating a new project in your “apps/myApps” where you try to call a shader.

ofShader shader;

void ofApp::setup(){
     shader.load("glsl");
}

void ofApp::draw(){
     shader.begin();

     shader.end();
}

in bin/data/ create this files:

glsl.frag

void main(){
     gl_FragColor = vec4(1,0,0,1);
}

glsl.vert

void main(){
       gl_Position = ftransform();
}

Here you go…

Debug:

Release:

Hi kashim,

Thanks for your input. Yes I just tried what you suggested and the same thing is happening. Here’s what is appearing in the output terminal…

Run in debug mode:

Run in release mode:

Hi,

you can print the result of the command “df”
and the command “pwd” in this case starting from your project folder.

then you can also print a “pwd” starting from the folder where the binary is generated?

good day!

And a good day to you too!

Here’s the screenshots you requested:

df

pwd from project folder

pwd from bin