SFML community forums

Help => Window => Topic started by: distagon140 on November 24, 2019, 05:08:07 pm

Title: Conflict OpenGL - SFML?
Post by: distagon140 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?
Title: Re: Conflict OpenGL - SFML?
Post by: Laurent 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... ;)
Title: Re: Conflict OpenGL - SFML?
Post by: distagon140 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();
}
 
Title: Re: Conflict OpenGL - SFML?
Post by: Laurent 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).
Title: Re: Conflict OpenGL - SFML?
Post by: distagon140 on November 26, 2019, 02:36:08 pm
That's plausible. Now I can handle it, thanks.