Reputation:
I use:
std::string source;
char value;
std::ifstream stream(paths[id]);
while (stream.get(value)) {
source += value;
}
stream.close()
int shader = glCreateShader(mode);
shaders[id] = shader;
glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);
glCompileShader(shader);
And the app crashes on Also source varible contains exactly:
#version 330 core
layout(location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
And the app just crashes!
What is the issue?
Upvotes: 1
Views: 395
Reputation: 2080
the problem is in this
glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);
try to do this
const char* src = source.c_str();
glShaderSource(shader, 1, &src,nullptr);
Upvotes: 1
Reputation: 96081
The problem is here: (const GLchar* const *)source.c_str()
. The fact that it didn't work without a cast (effectively a reinterpret_cast
) is a sign that you're doing something wrong.
Save the pointer to a variable: const char *ptr = source.c_str();
, then pass &ptr
to glShaderSource
.
Upvotes: 3