Ce code lève l'exception nvoglv32.dll. Je pense qu'il ya une erreur dans glShaderSource somewherer, mais je ne peux pas trouverOpenGL glShaderSource lève une exception
ifstream ifs("vertexShader.txt");
string vertexShadersSource((istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
ifs.close();
ifs.open("fragmentShader.txt");
string fragmentShadersSource((istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));
cout << fragmentShadersSource.c_str() << endl;
cout << vertexShadersSource.c_str() << endl;
GLuint shaderProgram;
GLuint fragmentShader, vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
const char *data = vertexShadersSource.c_str();
glShaderSource(vertexShader, 1, &data, (GLint*)vertexShadersSource.size());
data = fragmentShadersSource.c_str();
glShaderSource(fragmentShader, 1, &data, (GLint*)fragmentShadersSource.size());
EDIT:
Bien que je pense que le shader est correct, ici vous pouvez voir le code shader VertexShader:
#version 150
// in_Position was bound to attribute index 0 and in_Color was bound to attribute index 1
//in vec2 in_Position;
//in vec3 in_Color;
// We output the ex_Color variable to the next shader in the chain
out vec3 ex_Color;
void main(void) {
// Since we are using flat lines, our input only had two points: x and y.
// Set the Z coordinate to 0 and W coordinate to 1
//gl_Position = vec4(in_Position.x, in_Position.y, 0.0, 1.0);
// GLSL allows shorthand use of vectors too, the following is also valid:
// gl_Position = vec4(in_Position, 0.0, 1.0);
// We're simply passing the color through unmodified
ex_Color = vec3(1.0, 1.0, 0.0);
}
FragmentShader:
#version 150
// It was expressed that some drivers required this next line to function properly
precision highp float;
in vec3 ex_Color;
out vec4 gl_FragColor;
void main(void) {
// Pass through our original color with full opacity.
gl_FragColor = vec4(ex_Color,1.0);
}
Comment créer un contexte OpenGL? Quel est le contenu de 'vertexShader.txt' et' fragmentShader.txt'? – jimvonmoon
Modifier dans un [mcve]. – genpfault
J'utilise glfw pour créer ma fenêtre et j'utilise glfwMakeContextCurrent (window) pour créer le contexte. – Max