OpenGL Shader Compilation Errors: unexpected $undefined at token “

前端 未结 4 1054
萌比男神i
萌比男神i 2020-12-30 07:03

I saw this question and it really shedded some light. Despite this, I can\'t seem to figure out how I\'m \"improperly\" loading my shader, because this has executed

相关标签:
4条回答
  • 2020-12-30 07:33

    I got this error because I cut, and paste some shader code from a website. I assume the difference in LF/CR was causing the problem. Removing the pasted text with the same code manually typed in worked.

    0 讨论(0)
  • 2020-12-30 07:35

    My guess: I've seen the glLoadMatrix() calls in your code which basically means you're using an outdated (pre-3.1) GL API and do not initialize the GL3.1 Core Profile context correctly.

    This leads to the situation where your context does not support the GLSL1.50+ and the "location" attributes (thus the error from shader compiler).

    Try changing the initialization of GL and then check the glBindAttribLocation calls. Avoid using the glLoadMatrix stuff - use shader uniforms instead.

    Look at opengl.org's site: http://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C%2B%2B/Win) for a GL 3.1 context creation sample. It is a little different from GL2.0-

    0 讨论(0)
  • 2020-12-30 07:40

    That error message means that the shader compiler is seeing a garbage character (something other than a printable ASCII character, a space, a tab, or a newline) on the first line of the shader. Which most likely means that the string you're passing to glShaderSource is garbage -- probably a dangling pointer that once pointed at your shader code but no longer does due to something getting destructed.

    edit

    I see from your link you have code that looks like:

    s.Source = shader.toStdString().c_str();
    

    That will set s.Source pointing at the internal buffer of a temporary std::string object that will be destroyed shortly after this line, leaving s.Source a dangling pointer...

    0 讨论(0)
  • 2020-12-30 07:40

    This is probably not related to your current problem, but will be one soon enough :

    verts[ i ] = new float[ size ];
    verts[ i ] = const_cast< float* >( glm::value_ptr( iVertices.next() ) );
    

    The memory allocated in the first line is leaked, moreover, when you call delete a few lines after, you're deleting the value given by new but the casted one. Is that what you mean ?

    0 讨论(0)
提交回复
热议问题