glShaderSource ulega awarii
Aug 30 2020
Używam:
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);
Aplikacja ulega awarii na Zmienna także źródłowa zawiera dokładnie:
#version 330 core
layout(location = 0) in vec3 aPos;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}
A aplikacja po prostu się zawiesza!
Jaki jest problem?
Odpowiedzi
4 HolyBlackCat Aug 30 2020 at 09:53
Problemem jest tutaj: (const GLchar* const *)source.c_str(). Fakt, że nie zadziałało bez obsady (w zasadzie a reinterpret_cast) jest znakiem, że robisz coś źle.
Zapisz wskaźnik do zmiennej:, a const char *ptr = source.c_str();następnie przejdź &ptrdo glShaderSource.
2 Spinkoo Aug 30 2020 at 09:55
problem tkwi w tym
glShaderSource(shader, 1, (const GLchar* const *)source.c_str(), nullptr);
spróbuj to zrobić
const char* src = source.c_str();
glShaderSource(shader, 1, &src,nullptr);