0

I'am building an OpenGL-application using Qt 5.11.2. When adding a tessellation shader the following error occurs:

QOpenGLShader::compile(Tessellation Control): 0(2) : error C0204: version directive must be first statement and may not be repeated

*** Problematic Tessellation Control shader source code ***
#define lowp
#define mediump
#define highp
#line 1
´╗┐#version 400
#line 1
layout (vertices = 4) out;

I'm working on Windows 10 with Geforce GTX 1050/PCIe/SSE2 GPU.

I've found similar reports, but none of the answers worked for me: unable to compile GLSL shaders on Qt 5.3 after Nvidia driver update

Serious rendering issues with OpenGL 4.1 and Qt 5

The shader looks like this:

#version 400
layout (vertices = 4) out;

uniform float animationFrame;
in vec3 v_vertex[];

out vec3 tc_vertex[];

void main()
{...}

To add the shader I use the following code:

addShader(QOpenGLShader::Vertex, "data/cube.vert", *m_program);
addShader(QOpenGLShader::Fragment, "data/cube.frag", *m_program);
addShader(QOpenGLShader::TessellationControl, "data/cube.tcs", *m_program);
addShader(QOpenGLShader::TessellationEvaluation, "data/cube.tes", *m_program);
addShader(QOpenGLShader::Geometry, "data/cube.geom", *m_program);

Obviously the first lines inserted by Qt produce the error. Any ideas how to fix this problem?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
HerthaBSC
  • 139
  • 9
  • 3
    What is the `´╗┐` in `´╗┐#version 400`? Copy/paste error? Passing a `std::string` where a `const char*` is expected? May be, you should also show the code how you load the shader text in C++. – Scheff's Cat Jan 18 '19 at 07:52
  • Couldn't you drop the `#version 400` completely? I found [SO: Qt5 OpenGL GLSL version error](https://stackoverflow.com/a/33482388/7478597) which reflects what I was already thinking. – Scheff's Cat Jan 18 '19 at 07:57
  • I added the code I use for shader loading. I also thought about an copy/paste error, but the ```´╗┐``` is still shown in the error message after retyping the line. – HerthaBSC Jan 18 '19 at 07:58
  • 1
    Concerning the `´╗┐`: It might be an artefact from text editor where you wrote your shader codes in e.g. a BOM if your text editor used UTF-8 encoding. Shader code should be stored in ASCII without any BOM or such things... (But it's just a guess. You could use a hex-dump to check whether I was right.) – Scheff's Cat Jan 18 '19 at 08:00
  • @HerthaBSC: That's not shader loading code. That's the code which tells something else to load the shader. – Nicol Bolas Jan 18 '19 at 14:41
  • @Scheff The problem was indeed caused by the editor. Thank you for the hint! – HerthaBSC Jan 19 '19 at 20:32

3 Answers3

-1

I have the same problem, my errors shows like this:

QOpenGLShader::compile(Fragment): 0(2) : error C0204: version directive must be first statement and may not be repeated

*** Problematic Fragment shader source code ***
#ifdef GL_KHR_blend_equation_advanced
#extension GL_ARB_fragment_coord_conventions : enable
#extension GL_KHR_blend_equation_advanced : enable
#endif
#define lowp
#define mediump
#define highp
#line 1
???#version 330 core
out vec4 FragColor;

void main(void)
{
    FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}

***

as you can see, there are ??? in the messages, while you have ´╗┐

when I changed from "utf-8 with BOM" to "utf-8", it works~

miyan
  • 11
  • 3
-1

I have the error like this:

???#version 330 core

I use visual code to change the file encoding from "utf-8 with BOM" to "utf-8". Then it works.

-1

I guess the answer is "version directive must be first statement and may not be repeated"

So, put your version directive to the first line - before all defines and the same. Just checked it - that is it. When I put directive "#version 330 core" in the fourth line of code - the same error "version directive must be first statement and may not be repeated" occured; So the right way is to put this directive to the first line as it should be:

1 #version 330 core
2 in highp vec3 vert;
3 in highp vec3 vertNormal;

Where 1,2,3 - line's numbers.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 22 '23 at 15:29