1
Graphics / SFML with openGL: SFML does not render (but openGL does)
« on: February 07, 2016, 11:42:48 am »
Hi
I am trying to get through these openGL-Tutorials combining them with openGL: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
The program draws a triangle on the screen, but the SFML rectangle does not draw. Why?
Is there a problem using glew?
Thanks in advance
Edit:
Rendering on a sf::RenderTexture and binding it to an openGL-Object and then rendering the object with the texture with openGL seems to work. Is this a possible workaround or stupid?
Everything before the main loop:
main loop:
Simple shaders:
I am trying to get through these openGL-Tutorials combining them with openGL: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/
The program draws a triangle on the screen, but the SFML rectangle does not draw. Why?
Is there a problem using glew?
Thanks in advance
Edit:
Rendering on a sf::RenderTexture and binding it to an openGL-Object and then rendering the object with the texture with openGL seems to work. Is this a possible workaround or stupid?
Everything before the main loop:
(click to show/hide)
main loop:
while(window.isOpen())
{
Event event;
while(window.pollEvent(event))
{
if(event.type == Event::Closed)
window.close();
if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape))
window.close();
if(event.type == Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Use our shader
glUseProgram(programID);
// Send our transformation to the currently bound shader, in the "MVP" uniform
// This is done in the main loop since each model will have a different MVP matrix (At least for the M part)
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
glDisableVertexAttribArray(0);
window.pushGLStates();
window.draw(rect);
window.popGLStates();
window.display();
}
{
Event event;
while(window.pollEvent(event))
{
if(event.type == Event::Closed)
window.close();
if((event.type == Event::KeyPressed) && (event.key.code == Keyboard::Escape))
window.close();
if(event.type == Event::Resized)
glViewport(0, 0, event.size.width, event.size.height);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Use our shader
glUseProgram(programID);
// Send our transformation to the currently bound shader, in the "MVP" uniform
// This is done in the main loop since each model will have a different MVP matrix (At least for the M part)
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &mvp[0][0]);
// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
glDisableVertexAttribArray(0);
window.pushGLStates();
window.draw(rect);
window.popGLStates();
window.display();
}
Simple shaders:
(click to show/hide)