Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QOpenGLShader::link: Vertex info error: must write to gl_Position



  • I am having a problem when I link my shader program. This is the function that throws the error:

    GLuint shaderProgram::createShaderProgram(const char *fileName) {
        // Creamos el shader program y almacenamos su identificador
        if (handler) {
            shaderP = new QOpenGLShaderProgram();
            handler = shaderP->create();
            if (!handler) {
                fprintf(stderr, "Cannot create shader program: %s.\n", fileName);
                return 0;
            }
        }
        // Cargamos y compilamos cada uno de los shader objects que componen este
        // shader program
        char fileNameComplete[256];
        strcpy_s(fileNameComplete, fileName);
        strcat_s(fileNameComplete, "-vert.glsl");
        QOpenGLShader* vertex = new QOpenGLShader(QOpenGLShader::Vertex);
        GLuint vertexShaderObject = compileShader(fileNameComplete, QOpenGLShader::Vertex,vertex);
        if (vertexShaderObject == 0) {
            return 0;
        }
        strcpy_s(fileNameComplete, fileName);
        strcat_s(fileNameComplete, "-frag.glsl");
        QOpenGLShader* fragment = new QOpenGLShader(QOpenGLShader::Fragment);
        GLuint fragmentShaderObject = compileShader(fileNameComplete, QOpenGLShader::Fragment, fragment);
        if (fragmentShaderObject == 0) {
            return 0;
        }
        // Asociamos los shader objects compilados sin errores al shader program
        shaderP->addShader(vertex);
        shaderP->addShader(fragment);
    
        // Enlazamos el shader program y comprobamos si hay errores
        handler = shaderP->link(); //The error is thrown here
        if(!handler)
        {
            QString error = shaderP->log();
            std::cout<< error.toStdString()<<std::endl;
            return 0;
        }
        else {
            linked = true;
        }
        return handler;
    }
    

    It says : (0) : error C5145: must write to gl_Position.
    But gl_Position is an OpenGL variable that I can't manage. I have used these shaders in other Visual Studio with C++ programming and they work well.

    These are the shaders:

    vertex:

    #version 400
    
    layout (location = 0) in vec3 vPosition;
    
    uniform mat4 mvpMatrix;
    uniform vec3 vColor;
    uniform float pointSize;
    out vec4 destinationColor;
    
    void main()
    {
    	gl_PointSize = pointSize;
    	destinationColor = vec4(vColor, 1.0);
    	gl_Position = mvpMatrix * vec4(vPosition, 1.0);
    }
    
    

    fragment:

    #version 400
    
    in vec4 destinationColor;
    
    out vec4 fColor;
    
    void main()
    {
    	vec2 coord = gl_PointCoord-vec2(0.5);
    	if(length(coord) > 0.5)
    	{
    		discard;
    	}
    	fColor = destinationColor;
    }
    

Log in to reply