SFML community forums

Help => Graphics => Topic started by: Crafter on February 07, 2016, 11:42:48 am

Title: SFML with openGL: SFML does not render (but openGL does)
Post by: Crafter 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/ (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();
        }

 


Simple shaders:
(click to show/hide)

Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Mr_Blame on February 08, 2016, 02:34:09 pm
what about checking for errors? Which video Card you have?
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Crafter on February 08, 2016, 04:27:24 pm
I do not get any errors.
My video card: ATI Mobility Radeon HD 5850

glGetError() returns 0.
It just looks like
                window.pushGLStates();
                window.draw(rect);
                window.popGLStates();
 
is beeing ignored.


On Intel(R) HD Graphics:
window.draw(rect);
throws exception at 0x101290D7 (ig4icd32.dll)
access violation reading at position 0x066AEC70
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Crafter on February 08, 2016, 07:02:54 pm
Does
window.pushGLStates();
window.draw(rect);
window.popGLStates();
 
maybe not do enough?


Adding
glBindVertexArray(GL_NONE);
glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);
 
makes it work:

// end of main loop

glBindVertexArray(GL_NONE);
glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);

window.pushGLStates();
window.draw(rect);
window.popGLStates();
 
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Laurent on February 08, 2016, 08:23:50 pm
SFML push/pop only takes care of OpenGL 1.x states. States that require a higher GL core version are up to you.
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Crafter on February 09, 2016, 05:55:55 pm
ok thanks :)
Would you please add this to the tutorial?
http://www.sfml-dev.org/tutorials/2.3/window-opengl.php (http://www.sfml-dev.org/tutorials/2.3/window-opengl.php)
This could be helpful; thank you!

I want to use SFML for the 2D user interface.
Whis way is faster?
Rendering SFML into a RenderTexture, getting its texture and binding it to openGL and rendering two trianglas forming a plane over the window with them,
oder switching the contexts using window.push/pop glStates?
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Jesper Juhl on February 09, 2016, 06:04:33 pm
Why don't you try both and measure the performance yourself?
Title: Re: SFML with openGL: SFML does not render (but openGL does)
Post by: Crafter on February 11, 2016, 07:56:39 pm
Seems like its only laborious.
(At least within a small test)