Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGLShader::link: Vertex info error: must write to gl_Position
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JesusM
    wrote on last edited by
    #1

    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;
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved