[Solved] QGLShader: Unable to open file "vert.vert"



  • 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"



  • 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.



  • 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.



  • Obviously, main.cpp is located not in compiler destination folder, so for the compiled app the path is incorrect



  • 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.



  • No ,it is not.All the files are under one project folder



  • So what does ... do?
    @
    QFileInfo info("vert.vert");
    qDebug() << info.absoluteFilePath();
    @



  • 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?


  • Moderators

    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...



  • [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.



  • 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.



  • Many thanks to all.Being Qt NOOB I knew nothing about resources :) .Now it works just fine.



  • No worries. Everybody starts at the beginning. At least you know about resources now and for the future. Happy hacking!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.