简体   繁体   English

语法错误:令牌意外$ end <EOF> “GLSL与任何着色器

[英]syntax error: unexpected $end at token “<EOF>” GLSL with any shader

I've seen other similar questions, and I now that it's usually due to wrong shader loading code, but I've tried with lots of different ways to load them, and I always get this error. 我已经看到了其他类似的问题,我现在通常是由于错误的着色器加载代码,但我尝试了很多不同的方法加载它们,我总是得到这个错误。 Here is the loading code I'm currently using (for the Vertex shader, i do the same for the fragment shader): 这是我正在使用的加载代码(对于Vertex着色器,我对片段着色器执行相同操作):

GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
std::string VertexShaderCode;
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
if(VertexShaderStream.is_open()){
    std::string Line = "";
    while(getline(VertexShaderStream, Line))
        VertexShaderCode += "\n" + Line;
    VertexShaderStream.close();
}
GLint Result = GL_FALSE;
int InfoLogLength;


// Compile Vertex Shader
printf("Compiling shader : %s\n", vertex_file_path);
char const * VertexSourcePointer = VertexShaderCode.c_str();
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);

// Check Vertex Shader
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> VertexShaderErrorMessage(InfoLogLength);
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

I've also tried this: 我也试过这个:

    GLuint VertexShaderID = glCreateShader(GL_FRAGMENT_SHADER);
    std::ifstream shaderFile(vertex_file_path);
    //Error out here.
    stringstream shaderData;
    shaderData << shaderFile.rdbuf();  //Loads the entire string into a string stream.
    shaderFile.close();
    const std::string &VertexShaderCode = shaderData.str(); //Get the string stream as a std::string.
    GLint Result = GL_FALSE;
    int InfoLogLength;
    printf("Compiling shader : %s\n", vertex_file_path);
    char const * VertexSourcePointer = VertexShaderCode.c_str();
    glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
    glCompileShader(VertexShaderID);

    // Check Vertex Shader
    glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    std::vector<char> VertexShaderErrorMessage(InfoLogLength);
    glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
    fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

And this is the linking code: 这是链接代码:

// Link the program
fprintf(stdout, "Linking program\n");
GLuint ProgramID = glCreateProgram();
glAttachShader(ProgramID, VertexShaderID);
glAttachShader(ProgramID, FragmentShaderID);
glLinkProgram(ProgramID);

// Check the program
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<char> ProgramErrorMessage( max(InfoLogLength, int(1)) );
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
fprintf(stdout, "%s\n", &ProgramErrorMessage[0]);

I have also tried passing (GLint *)VertexShaderCode.size() instead of NULL to the length parameter of glShaderSource(), but I get the same errors. 我也尝试将(GLint *)VertexShaderCode.size()而不是NULL传递给glShaderSource()的长度参数,但是我得到了相同的错误。 I get those errors both when compiling and when linking 我在编译和链接时都会遇到这些错误

In case it helps, I'm using Opengl 3.3, GLEW, GLFW, Visual c++ 2010, and windows 7 64 bits 如果它有帮助,我使用的是Opengl 3.3,GLEW,GLFW,Visual c ++ 2010和Windows 7 64位

How did you pass the length parameter to glShaderSource. 你是如何将length参数传递给glShaderSource的。 The typecast you performed should trigger you a thick fat warning. 您执行的类型转换应该会触发厚厚的警告。 The proper way would have been to put the result of size() into a variable. 正确的方法是将size()的结果放入变量中。 And then you give the pointer to that variable to glShaderSource. 然后你将指向该变量的指针提供给glShaderSource。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到“错误编译:0:1(1): 错误:语法错误,意外的 $end” C++、GLSL、着色器文件 - Receiving a "Error compiling: 0:1(1): error: syntax error, unexpected $end" C++, GLSL, shader files 无法编译顶点着色器:令牌处意外的$ end <EOF> ” - Cannot Compile Vertex Shader: Unexpected $end at token “<EOF>” &#39;错误 C0000:语法错误,意外的 $end 在令牌处”<EOF> &quot;&#39; 并且不确定如何进行 - 'Error C0000: syntax error, unexpected $end at token "<EOF>"' and unsure how to proceed 获取0:1(1):错误:语法错误,尝试编译着色器时出现意外的$ end - Get 0:1(1): error: syntax error, unexpected $end when trying to compile shader GLSL编译器错误错误C0000:语法错误,意外的标识符,标记处应为“ ::” - GLSL Compiler Error error C0000: syntax error, unexpected identifier, expecting “::” at token <var> GLSL ES顶点着色器错误 - GLSL ES Vertex shader error Cmake奇怪的错误:语法错误意外的令牌(&#39; - Cmake Strange Error: Syntax Error Unexpected Token (' 意外标记&#39;newline&#39;附近的语法错误 - syntax error near unexpected token `newline' qmake语法错误在意外的令牌换行符附近 - qmake syntax error near unexpected token newline 在GLSL 1.30上编译片段着色器时出错 - Error compiling fragment shader on GLSL 1.30
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM