Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML with openGL: SFML does not render (but openGL does)  (Read 2948 times)

0 Members and 1 Guest are viewing this topic.

Crafter

  • Newbie
  • *
  • Posts: 5
    • View Profile
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:
(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)

« Last Edit: February 07, 2016, 01:46:39 pm by Crafter »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #1 on: February 08, 2016, 02:34:09 pm »
what about checking for errors? Which video Card you have?

Crafter

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #2 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
« Last Edit: February 08, 2016, 05:25:44 pm by Crafter »

Crafter

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #3 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();
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #4 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.
Laurent Gomila - SFML developer

Crafter

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #5 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
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?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #6 on: February 09, 2016, 06:04:33 pm »
Why don't you try both and measure the performance yourself?

Crafter

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML with openGL: SFML does not render (but openGL does)
« Reply #7 on: February 11, 2016, 07:56:39 pm »
Seems like its only laborious.
(At least within a small test)