Shaders loaded from a file won't compile in armv7



  • It works while building for the desktop, but as soon as I compile this little snippet to load shaders from a file with armv7 it somehow can't retrieve the file and just return an empty string
    Here's how i'm handling the routine which loads my shaders:

    void MainWindow::initShaders(const GLchar *vertexPath, const GLchar *fragmentPath, GLuint& Program)
    {
        std::string vertexCode;
        std::string fragmentCode;
        std::ifstream vShaderFile;
        std::ifstream fShaderFile;
    
        vShaderFile.exceptions(std::ifstream::badbit);
        fShaderFile.exceptions(std::ifstream::badbit);
        try
        {
            vShaderFile.open(vertexPath);
            fShaderFile.open(fragmentPath);
            std::stringstream vShaderStream, fShaderStream;
    
            vShaderStream << vShaderFile.rdbuf();
            fShaderStream << fShaderFile.rdbuf();
    
            vShaderFile.close();
            fShaderFile.close();
            // Convert stream into string, returns an empty one if compiling with armv7
            vertexCode = vShaderStream.str();
            fragmentCode = fShaderStream.str();
        }
    //...
    //linking & compiling
    //...
    }
    

    I'm pretty new to android development and i'm not sure if something's missing
    jdk, ant, android sdk & ndk are properly set up and the few opengl samples I tried to run work fine, but my shaders need to be directly written as const GLchar* inside the program to compile


  • Lifetime Qt Champion

    Hi,

    Where are your shaders located ?

    By the way, why not make use of QOpenGLShader ?



  • The shaders are in the project file, saved as text files with .vert & .frag extensions. It goes fine while building for the desktop but It fails on armv7 somehow

    I haven't looked at that helper class and It would be better if I understand now what's the problem to hopefully not get stuck again for future similiar operations


  • Lifetime Qt Champion

    Then you should use the Qt resource system to embed the shader in your application. You current shader files are accessible on your host. When you start your application on your device, they won't be there.



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