title: Qt QFile and OpenGL ES 2.0 Vertex Shader Unexpected End of File
body: <p>I have working Open GL code that had the shader source in the Qt source code as const char* variables. This worked great and compiled fine. Now I want to move the shaders to their own files stored as qresources. When I read the shaders in using QFile, the fragment shader compiles but not the vertex shader. I cannot seem to figure out why. I'd appreciate any help - please see the code below.</p>
  
  <p>Error:</p>
  
  <pre><code>Vertex Shader failed to compile! 
  Error in vertex shader compilation!
  Info log: Compile failed.
  ERROR: Unexpected end of source found
  ERROR: 1 compilation errors. No code generated.
  
  
  Fragment Shader successfully compiled! 
  Linking was unsuccessful... 
  </code></pre>
  
  <p>Working Code:</p>
  
  <pre><code>    // Compile Shaders
      const char* VertexShaderSource = "\
              attribute highp   vec4  inVertex;\
              attribute mediump vec2  inTexCoord;\
              varying mediump vec2  TexCoord;\
              void main()\
              {\
                  gl_Position = inVertex;\
                  TexCoord = inTexCoord;\
              }";
  
      const char* FragmentShaderSource = "\
                     #ifdef GL_IMG_texture_stream2\n \
                     #extension GL_IMG_texture_stream2 : enable \n \
                     #endif \n \
                         varying mediump vec2 TexCoord; \
                         uniform samplerStreamIMG sTexture; \
                         uniform sampler2D table1; \
                         uniform sampler2D table2; \
                         uniform sampler2D table3; \
                         uniform sampler2D palette; \
                         void main(void) \
                         {    \
                         highp vec4 texVal = textureStreamIMG( sTexture, TexCoord ); \
                         highp vec4 tb1Val = texture2D( table1, TexCoord ); \
                         highp vec4 tb2Val = texture2D( table2, TexCoord ); \
                         highp vec4 tb3Val = texture2D( table3, TexCoord ); \
                         highp float index = ( texVal.g * 255.0 ) * 256.0 + texVal.b * 255.0; \
                         highp float x = ( mod(index,256.0) ) / 256.0; \
                         highp float y = ( index / 256.0 ) / 256.0; \
                         highp vec4 palValue = texture2D( palette, vec2(x, y) ); \
                         gl_FragColor = vec4(palValue.a,palValue.r,palValue.g,palValue.b); \
                         }";
  </code></pre>
  
  <p>Broken Code:</p>
  
  <pre><code>// Compile Shaders
  QFile vSh(":/vertex.vsh");
  bool vSuccess = vSh.open(QIODevice::ReadOnly);
  qDebug() &lt;&lt; "Success opening Vertex Shader: " &lt;&lt; vSuccess;
  QTextStream vIn(&amp;vSh);
  QString vOut;
  while (!vIn.atEnd())
  {
      vOut.append(QString("%1%2").arg(vIn.readLine()).arg("\n"));
  }
  qDebug() &lt;&lt; vOut;
  const char* VertexShaderSource = vOut.toStdString().c_str();
  
  QFile fSh(":/fragment.fsh");
  bool fSuccess = fSh.open(QIODevice::ReadOnly);
  qDebug() &lt;&lt; "Success opening Fragment Shader: " &lt;&lt; fSuccess;
  QTextStream fIn(&amp;fSh);
  QString fOut;
  while (!fIn.atEnd())
  {
      fOut.append(QString("%1%2").arg(fIn.readLine()).arg("\n"));
  }
  qDebug() &lt;&lt; fOut;
  const char* FragmentShaderSource = fOut.toStdString().c_str();
  
  // Create vertex and fragment shaders
  GLuint vertexShaderObject = glCreateShader(GL_VERTEX_SHADER);
  GLuint fragmentShaderObject = glCreateShader(GL_FRAGMENT_SHADER);
  const GLchar *vSrc = VertexShaderSource;
  const GLchar *fSrc = FragmentShaderSource;
  glShaderSource(vertexShaderObject, 1, &amp;vSrc, NULL);
  glShaderSource(fragmentShaderObject, 1, &amp;fSrc, NULL);
  glCompileShader(vertexShaderObject);
  glCompileShader(fragmentShaderObject);
  GLint compiled;
  glGetShaderiv(vertexShaderObject, GL_COMPILE_STATUS, &amp;compiled);
  if (compiled)
  {
      qDebug() &lt;&lt; "Vertext Shader successfully compiled!";
  }
  else {
  
      qDebug() &lt;&lt; "Vertex Shader failed to compile!";
      GLchar infoLog[2048];
      glGetShaderInfoLog(vertexShaderObject, 2048, NULL, infoLog);
      fprintf(stderr, "Error in vertex shader compilation!\n");
      fprintf(stderr, "Info log: %s\n", infoLog);
  
  }
  ...
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Success opening Vertex Shader:  true 
  "attribute highp   vec4  inVertex;
  attribute mediump vec2  inTexCoord;
  varying mediump vec2  TexCoord;
  void main()
  {
                  gl_Position = inVertex;
                  TexCoord = inTexCoord;
  }
  " 
  Success opening Fragment Shader:  true 
  "#ifdef GL_IMG_texture_stream2
  #extension GL_IMG_texture_stream2 : enable
  #endif
  varying mediump vec2 TexCoord;
  uniform samplerStreamIMG sTexture;
  uniform sampler2D table1;
  uniform sampler2D table2;
  uniform sampler2D table3;
  uniform sampler2D palette;
  void main(void)
  {
          highp vec4 texVal = textureStreamIMG( sTexture, TexCoord );
          highp vec4 tb1Val = texture2D( table1, TexCoord );
          highp vec4 tb2Val = texture2D( table2, TexCoord );
          highp vec4 tb3Val = texture2D( table3, TexCoord );
          highp float index = ( texVal.g * 255.0 ) * 256.0 + texVal.b * 255.0;
          highp float x = ( mod(index,256.0) ) / 256.0;
          highp float y = ( index / 256.0 ) / 256.0;
          highp vec4 palValue = texture2D( palette, vec2(x, y) );
          gl_FragColor = vec4(palValue.a,palValue.r,palValue.g,palValue.b);
  }
  " 
  Vertex Shader failed to compile! 
  Error in vertex shader compilation!
  Info log: Compile failed.
  ERROR: Unexpected end of source found
  ERROR: 1 compilation errors. No code generated.
  
  
  Fragment Shader successfully compiled! 
  Linking was unsuccessful... 
  </code></pre>