0

I'm getting the following error when I try link my fragment shader,

QGLShader::compile(Fragment): 0(4) : error C0000: syntax error, unexpected '.', expecting "::" at token "."

I'm just trying to implement a simple fragment shader that sets colour to be green.

The code for my vertex shader (which is working) file name shader.vert

#version 430

in layout(location=0) vec2 position;

void main()
{
    gl_Position = vec4(position, 0.0, 1.0);
}

The code for my fragment shader shader.frag

#version 430

out vec4 finalColour;

void main()
{
    finalColour = vec4(0.0, 1.0, 0.0, 1.0);
}

The code that links the QGLShaderProgram mProgram

//Add Shaders
if (!mProgram.addShaderFromSourceFile(QGLShader::Vertex, "shader.vert")) {
    error_msg("Vertex shader load failed");
}
if (!mProgram.addShaderFromSourceCode(QGLShader::Fragment, "testShader.frag")) {
    error_msg("Fragment shader load failed");
}
if (!mProgram.link()) {
    error_msg("Cannot link shaders");
}
mProgram.bind()
Sahar Rabinoviz
  • 1,799
  • 1
  • 14
  • 26

1 Answers1

1

The second parameter of addShaderFromSourceCode(, code)

you must provide the content of file not the name of file itself here you can put this code in a function and use it to load the file

Read whole ASCII file into C++ std::string

Community
  • 1
  • 1
mofed8461
  • 36
  • 8
  • For the second parameter it is asking for a filename, you can look at the specs, [QGLShaderProgram::addShaderFromSourceFile](http://doc.qt.io/qt-4.8/qglshaderprogram.html#addShaderFromSourceFile). Also shader.vert is loading fine. fragment shader is not though. – Sahar Rabinoviz May 11 '16 at 22:03
  • you are loading the vertex shader from file and fragment shader from code .. change the name of the function .. from addShaderFromSourceCode to addShaderFromSourceFile – mofed8461 May 11 '16 at 22:11