I am working on a project using OpenGL 4.0 shaders.
I need to send a call to glShaderSource () with an array of char arrays, which is the source of the shader.
Shader compilation does not work with the following errors:
(0) : error C0206: invalid token "<null atom>" in version line (0) : error C0000: syntax error, unexpected $end at token "<EOF>"
Here's my (hello world) shader - right from the OpenGL 4.0 shaded language cookbook
#version 400 in vec3 VertexPosition; in vec3 VertexColor; out vec3 Color; void main() { Color = VertexColor; gl_Position = vec4( VertexColor, 1.0 ); }
And here is my code to read the shader file in my C ++ code and compile the shader at runtime:
const int nMaxLineSize = 1024; char sLineBuffer[nMaxLineSize]; ifstream stream; vector<string> vsLines; GLchar** ppSrc; GLint* pnSrcLineLen; int nNumLines; stream.open( m_sShaderFile.c_str(), std::ios::in ); while( (stream.good()) && (stream.getline(sLineBuffer, nMaxLineSize)) ) { if( strlen(sLineBuffer) > 0 ) vsLines.push_back( string(sLineBuffer) ); } stream.close(); nNumLines = vsLines.size(); pnSrcLineLen = new GLint[nNumLines]; ppSrc = new GLchar*[nNumLines]; for( int n = 0; n < nNumLines; n ++ ) { string & sLine = vsLines.at(n); int nLineLen = sLine.length(); char * pNext = new char[nLineLen+1]; memcpy( (void*)pNext, sLine.c_str(), nLineLen ); pNext[nLineLen] = '\0'; ppSrc[n] = pNext; pnSrcLineLen[n] = nLineLen+1; } vsLines.clear();
C ++ code executes as expected, but shader compilation fails. Can anyone determine what I can do wrong?
I have a feeling that this may be somehow connected with the characters of the end of the line, but since this is my first attempt to create a shader, I'm stuck!
I read other SO answers on shader compilation, but they seem to relate to Java / other languages, not C ++. If this helps, I'm on a win32 platform.
user206705
source share