I have the following code:
glShaderSource(shader, 1, (const char **)data.c_str(), NULL);
But it makes my program crash. How do I convert
glShaderSource
signature is, according to glShaderSource doc:
void glShaderSource(
GLuint shader,
GLsizei count,
const GLchar** string,
const GLint* length);
where string
"Specifies an array of pointers to strings containing the source code to be loaded into the shader". What you're trying to pass is a pointer to a NULL terminated string (that is, a pointer to a const char*
).
Unfortunately, I am not familiar with glShaderSource
, but I can guess it's not expected a pointer to "some code" but something like this instead:
const char** options =
{
"option1",
"option2"
// and so on
};
From opengl-redbook, you can read an example (I've shortened it in purpose):
const GLchar* shaderSrc[] = {
"void main()",
"{",
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;",
"}"
};
shader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shader, NumberOfLines(shaderSrc), shaderSrc, NULL);