vendredi 6 mars 2015

glShaderSource, 0:1(1): error: syntax error, unexpected $end


I've seen tons of similiar questions, but no matter what I try, I can't get OpenGL to load my shader source. My first thought was, the pointer data might go out of scope, which was right. So i saved the string in a variable, but OpenGL still gives me an Error.



/**
* Load shaders
*/
void GraphicsCore::loadShaders() {
// Create the main program
GLuint prog = glCreateProgram();

// Vertex shader
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
std::string vsSource = Utilities::fileToString("main.vert");
const GLchar* v = vsSource.c_str();
glShaderSource(vs,1,(const GLchar**)&v,nullptr);
std::cout << ((const GLchar**)&v)[0];
glCompileShader(vs);
glAttachShader(prog,vs);

// Fragment shader
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
std::string fsSource = Utilities::fileToString("main.frag");
const GLchar* f = fsSource.c_str();
glShaderSource(fs,1,(const GLchar**)&f,nullptr);
std::cout << ((const GLchar**)&f)[0];
glCompileShader(fs);
glAttachShader(prog,fs);

// Link program and use
glLinkProgram(prog);
glUseProgram(prog);
}


Utilities::fileToString("main.vert") returns a normal string, no pointers, no references. The cout calls both print the shader source as it should be, but when I'm running the application in BuGLe, the debugger already breaks on Vertex Shader compilation with the following message:



0:1(1): error: syntax error, unexpected $end


It seems that OpenGL doesn't find the data at all, but just in case, the vertex shader code:



#version 120
void main() { gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; }



Aucun commentaire:

Enregistrer un commentaire