GLSL - Weird syntax error “<”

后端 未结 1 1648
挽巷
挽巷 2020-12-11 08:58

I\'m trying to use a shader but it keeps telling me this error on both fragment and vertex shader:

error(#132) Syntax error: \"<\" parse error

相关标签:
1条回答
  • 2020-12-11 09:15

    Your error and the lack of a < token in your shader sources suggests that glShaderSource is reading into trailing garbage at the end of the strings.

    This sounds like a subtle problem known to the seasoned developers but that can stump the newbies. glShaderSource either expects zero terminated strings and a NULL pointer for the length array or you're passing an array with lengths so that the strings don't need to be 0 terminated. Technically std::string::c_str should give access to a zero terminated string, but it seems in your case it doesn't.

    Anyway the simple solution is to provide a length array, so that glShaderSource doesn't read into trailing garbage:

    // Do a quick switch so we can do a double pointer below
    const char *vvshader = vshader.c_str();
    const char *ffshader = fshader.c_str();
    const GLint lenvshader = vshader.length();
    const GLint lenfshader = fshader.length();
    
    // Now this assigns the shader text file to each shader pointer
    glShaderSource(VertexShader, 1, &vvshader, &lenvshader);
    glShaderSource(FragmentShader, 1, &ffshader, &lenfshader);
    
    0 讨论(0)
提交回复
热议问题