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

Author Topic: Conflict OpenGL - SFML?  (Read 1181 times)

0 Members and 1 Guest are viewing this topic.

distagon140

  • Newbie
  • *
  • Posts: 3
    • View Profile
Conflict OpenGL - SFML?
« on: November 24, 2019, 05:08:07 pm »
Hello
I've a question about the following code:

void CScreen2::Update (float timestep) const {
    glClearColor (0.1, 0.2, 0.4, 1.0);
    sf::RenderWindow *window = app.winctrl.GetWin ();  // get a pointer to the instance of RenderWindow
    window->clear (sf::Color (25, 50, 100, 255));
//      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    DrawTexture (texid, 100, 100, 1, OR_BOTTOM);    // drawn in classic opengl manner
    window->display();
}
 

Update() is a callback, called in every frame. In this function I've to draw a lot of things with OpenGL, not with SFML graphics. The texture is only a test object. The code above doesn't work, it shows the empty background, not the texture. But when I change the window->clear() call with glClear() then all seems to be ok. Same when I add the line with glClear().
Could anyone explain this effect?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Conflict OpenGL - SFML?
« Reply #1 on: November 24, 2019, 08:41:13 pm »
Window::clear only clears the color buffer, so it is not equivalent to your glClear call, which clears the stencil and the depth buffers as well.

If that doesn't explain your problem, then show more code, we can't guess... ;)
Laurent Gomila - SFML developer

distagon140

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Conflict OpenGL - SFML?
« Reply #2 on: November 25, 2019, 11:05:07 am »
That doesn't explain the problem since I can't see why to clear the depth buffer and stencil buffer, too, when only drawing a plain texture. But it solves the problem, the code below works well. Some questions are left, but that's a matter of OpenGL not of SFML. Thank you.

void CScreen2::Update (float timestep) const {
    glClear (GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    window->clear (sf::Color (25, 50, 100, 255));
    DrawTexture (texid, 100, 100, 1, OR_BOTTOM);
    window->display();
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Conflict OpenGL - SFML?
« Reply #3 on: November 25, 2019, 12:31:30 pm »
Your geometry has a Z component, even if you never explicitly use it. Therefore, if you enable the Z buffer but never clear it, anything can happen (depending on how Z testing is configured).
Laurent Gomila - SFML developer

distagon140

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Conflict OpenGL - SFML?
« Reply #4 on: November 26, 2019, 02:36:08 pm »
That's plausible. Now I can handle it, thanks.