我用:
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);
应用崩溃源变量也包含以下内容:
#version 330 core
layout(location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
应用程序崩溃了!有什么问题
最佳答案
问题在这里:(const GLchar* const *)source.c_str()
。没有强制转换(实际上是reinterpret_cast
)就无法工作的事实表明您做错了事。
将指针保存到变量const char *ptr = source.c_str();
,然后将&ptr
传递给glShaderSource
。
关于c++ - glShaderSource崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63656128/