[Solved] QGLShader: Unable to open file "vert.vert"
-
wrote on 17 Oct 2011, 11:24 last edited by
Anyone has idea why my shader program can't read in the vertex shader file ?
I load the file residing in "Other Files" directory :
@
const QString vertexShaderPath="vert.vert";if(!m_shader.addShaderFromSourceFile(QGLShader::Vertex,vertexShaderPath )){ qDebug() << m_shader.log(); }
@
And getting this:QGLShader: Unable to open file "vert.vert"
-
wrote on 17 Oct 2011, 12:14 last edited by
Well, vert.vert is a path relative to the applications' current path (which is most probably not Other Files). So you either use the correct relative path (probably Other Files/vert.vert) or an absolute path or embed vert.vert as a resource.
-
wrote on 17 Oct 2011, 12:21 last edited by
Yes it resides in the "Other Files" but that is not a physical location.So in fact it resides in the same folder with the main.cpp .And somehow it is not loaded.
-
wrote on 17 Oct 2011, 13:18 last edited by
Obviously, main.cpp is located not in compiler destination folder, so for the compiled app the path is incorrect
-
wrote on 17 Oct 2011, 13:33 last edited by
The applications' path may not be main.cpp path (for example when shadow build is used). The easiest way to solve this issue is to include your vert.vert as a resource.
-
wrote on 17 Oct 2011, 13:33 last edited by
No ,it is not.All the files are under one project folder
-
wrote on 17 Oct 2011, 13:37 last edited by
So what does ... do?
@
QFileInfo info("vert.vert");
qDebug() << info.absoluteFilePath();
@ -
wrote on 17 Oct 2011, 13:52 last edited by
Lukas ,thanks for this tip! Now I see that it retrieves the file from the debug directory which is outside the project folder.I guess it is created when I run in debug mode.How can I change it so that it targets the vert.vert file from the project directory?
-
wrote on 17 Oct 2011, 15:21 last edited by
Please don't hack around, trying to get the build system to put stuff all over the place! Consider using a proper deployment configuration (aka. a "make install") instead. The build system is generating binaries and assumes that you do not care what it does. The installation is meant to make the application useful by copying files where they need to go. That will make reusing your application/sources way easier for others: You will have less assumptions about your system coded into the build system.
In Qt Creator you can add deployment steps for that...
-
wrote on 17 Oct 2011, 16:26 last edited by
[quote author="sasmaster" date="1318859574"]Lukas ,thanks for this tip! Now I see that it retrieves the file from the debug directory which is outside the project folder.I guess it is created when I run in debug mode.How can I change it so that it targets the vert.vert file from the project directory?[/quote]
You can change the working directory under Projects -> Run. addShaderFromSourceFile() takes either a relative or absolute path. So you can just use "debug/vert.vert" or "../vert.vert" or whatever.
But as said, the easiest way to deploy small files with your application is embedding them as a resource. No more fragile tinkering with relative paths. If you do not want to embed it take a look at Tobias post.
-
wrote on 17 Oct 2011, 17:33 last edited by
Agreed when using shadow builds the easiest way is to create a resource file and add you shaders to that. Then you can just do ":/vert.vert" from anywhere in your application and not have to worry about relative path issues.
-
wrote on 18 Oct 2011, 08:44 last edited by
Many thanks to all.Being Qt NOOB I knew nothing about resources :) .Now it works just fine.
-
wrote on 18 Oct 2011, 08:49 last edited by
No worries. Everybody starts at the beginning. At least you know about resources now and for the future. Happy hacking!
1/13