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

Author Topic: sf::RenderTexture::clear not working. (bug?)  (Read 6775 times)

0 Members and 1 Guest are viewing this topic.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
sf::RenderTexture::clear not working. (bug?)
« on: January 10, 2014, 12:17:31 pm »
Hey I have a simple problem. It seems that the clear function of a RenderTexture doens't work for me.

Minimal example (It's the renderTexture example + a RectangleShape updated to the mouse position (to draw some stuff  :P):
#include <SFML\Graphics.hpp>

int main()
{
        // Create a new render-window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
        // Create a new render-texture
        sf::RenderTexture texture;
        if (!texture.create(500, 500))
                return -1;
        // Create rectangle
        sf::RectangleShape rect;
        rect.setSize({ 25.f, 25.f });
        // The main loop
        while (window.isOpen())
        {
                // Event processing
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }
                //Update the rect position to mouse position (to draw some stuf :P)
                rect.setPosition(static_cast<sf::Vector2f>(sf::Mouse::getPosition(window)));
                // Clear the whole texture with red color
                texture.clear(sf::Color::Red);
                // Draw stuff to the texture
                texture.draw(rect);
                // We're done drawing to the texture
                texture.display();
                // Now we start rendering to the window, clear it first
                window.clear();
                // Draw the texture
                sf::Sprite sprite(texture.getTexture());
                window.draw(sprite);
                // End the current frame and display its contents on screen
                window.display();
        }


    return 0;
}

The result for me: http://imgur.com/DEFr4Fb

What I would expect: http://imgur.com/gsTZJfd = only one rectangle. When I draw directly on a window everything works fine.

My system:
OS: Windows 8 64bit
GPU: AMD 6850 (I have the lastest beta driver)
(I don't think the CPU/Ram are important for this issue but anyways)
CPU: AMD FX-8350
RAM: 8gb 1600mhz

Sadly I have currently no other PC to test it.



AlexAUT

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #1 on: January 10, 2014, 12:28:00 pm »
(I have the lastest beta driver)
I essentially should just raise my hands and say: You're on your own - Beta is beta. ;)

In the past, this has been an issue with bad Intel drivers and it took some heavy debugging and a different implementation to fix it. Not sure why it now would pop up on an AMD card...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #2 on: January 10, 2014, 12:45:09 pm »
I essentially should just raise my hands and say: You're on your own - Beta is beta. ;)

 ;D . I downgraded the driver to the current stable (just in case) and the problem still remains (installing beta again  :P). So it looks like its a "real" bug. I can ask a friend later to test the application, he has a AMD 7880 gpu...


AlexAUT

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #3 on: January 10, 2014, 01:14:56 pm »
Then the question is, what exact version of SFML do you use?

And since it works on fine on other system, it still sounds like yet another driver bug. :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #4 on: January 10, 2014, 02:48:07 pm »
Then the question is, what exact version of SFML do you use?

The lastest source, ~3Weeks old from the master branch(no commits since then) compiled for VS12 (2013).

GCC with SFML 2.1 precompiled also produce this "bug". So it really looks like a driver issue. I never used RenderTextures before so I can't tell if the issue is only related to the latest driver.

When I use a FBO by myself (using raw opengl) the clear does work as intended (I'm using a openGL 4.2 context when I use raw Opengl). So I guess it's a problem with the implementation of SFML, I will have a closer look tonight.


AlexAUT

CriticalThread

  • Guest
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #5 on: January 10, 2014, 11:05:16 pm »
I have the same problem (using latest source from github, compiled with mingw/gcc).

when i activate the window overlay from msi afterburner the render texture clears correctly.
also when calling "window.resetGLStates();" every frame it also works.

GPU: AMD HD5850 (with catalyst 13.10 on windows)
OS: Windows 7 and Ubuntu 13.04

CriticalThread

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #6 on: January 11, 2014, 12:15:22 am »
also when calling "window.resetGLStates();" every frame it also works.

Hmm this works for me too  ??? . So it really looks like we have a ATI/AMD bug here, because my friends has this problem too (AMD 7880).


AlexAUT

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #7 on: January 11, 2014, 01:34:58 am »
also when calling "window.resetGLStates();" every frame it also works.

Hmm this works for me too  ???
This sounds rather like your OpenGL driver provides a higher context as the one SFML is used to or automatically changes states for some reason... If only I had more experience on that level...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

the_mean_marine

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: sf::RenderTexture::clear not working. (bug?)
« Reply #8 on: January 11, 2014, 04:01:10 am »
There's also an older thread on this issue here: http://en.sfml-dev.org/forums/index.php?topic=9350.0

It does seem to be only affecting AMD cards and their drivers. I have the issue on my desktop but there's nothing on my laptop which has an Nvidia card.

It's interesting that there seems to be three ways to fix this problem.

1. window.resetGLStates()
2. draw a fully transparent sprite over the entire screen
3. apply a post-effect shader

It's obviously got something to do with the OpenGl state but it's interesting that two and three also fix the state issue. I've tried calling all of the OpenGl functions that SFML calls in resetGLStates() but none of them had any effect. I then tried the internal SFML functions but the only one that had any effect on the output was sf::Texture::bind(nullptr, sf::Texture::Pixels) which resulted in a blank white screen.

I'm not sure if this information will help anyone but I don't know anywhere near enough about OpenGl to have any idea where to go from here.
« Last Edit: January 11, 2014, 04:13:20 am by the_mean_marine »

 

anything