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

Author Topic: sf::RenderTexture problem  (Read 9507 times)

0 Members and 2 Guests are viewing this topic.

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
sf::RenderTexture problem
« on: August 01, 2014, 09:14:14 pm »
Is hope it is not normal for sf::RenderTexture:

Can I fix it somehow, or what I'm doing wrong ?

Graphics Card: Radeon HD 5570
Lastest drivers.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow app(sf::VideoMode(800,600),"RT Test");
    // Load a sprite to display
    sf::Texture texture;
    if (!texture.loadFromFile("cb.bmp"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);

    sf::RenderTexture rt;
    rt.create(800,600);

    sf::Sprite surface(rt.getTexture());

        // Start the game loop
    while (app.isOpen())
    {
        // Process events
        sf::Event event;
        while (app.pollEvent(event))
        {
            // Close window : exit
            if (event.type == sf::Event::Closed)
                app.close();
        }
        sprite.move(0.1f,0);
        // app.resetGLStates(); // with this, all work
        rt.clear(sf::Color::White);
        rt.draw(sprite);
        rt.display();


        // Clear screen
        app.clear();

        // Draw the sprite
        app.draw(surface);

        // Update the window
        app.display();
    }

    return 0;
}
 
« Last Edit: August 03, 2014, 10:30:36 am by fr33k »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::RenderTexture problem
« Reply #1 on: August 02, 2014, 12:02:37 am »
Why not post the complete code? It can't be much more than what you posted  :o

I just put this in a main() with the require #include and created app as a render window. Not sure why you didn't just post those lines too. It runs fine and doesn't show the artifacts you demonstrated in your video. Which version of SFML are you using, although I would've first thought it was a driver issue?

Worst.texture.ever.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #2 on: August 02, 2014, 05:21:57 am »
Quote
Worst.texture.ever.
Just Code::Blocks SFML project, for test.  :D
I'm using SFML 2.1 :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::RenderTexture problem
« Reply #3 on: August 02, 2014, 08:38:48 am »
You can try the latest sources, we made fixes that could solve your problem.
Laurent Gomila - SFML developer

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #4 on: August 02, 2014, 07:11:29 pm »
Nope, I still have the same problem.  :-\

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::RenderTexture problem
« Reply #5 on: August 02, 2014, 09:36:59 pm »
Try to reset the openGL states before you are drawing/clearing the rendertexture. (I have the same issue)



AlexAUT

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #6 on: August 03, 2014, 05:42:56 am »
Quote
Try to reset the openGL states before you are drawing/clearing the rendertexture. (I have the same issue)
It's working!  :D
Thanks Alex.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::RenderTexture problem
« Reply #7 on: August 03, 2014, 09:33:23 am »
Can you show the working code? It could help us to solve this problem.
Laurent Gomila - SFML developer

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #8 on: August 03, 2014, 10:13:09 am »
Why not.
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC

#include <SFML/Graphics.hpp>
#include <SFML\OpenGL.hpp>
#include "include/Defaults.hpp"
#include "include/Debug.hpp"
#include "include/FPS.h"
#include "include/Timer.hpp"
#include "include/Camera.hpp"
#include "include/Animation.hpp"
#include "include/Collision.hpp"
#include "include/Object.hpp"
#include "include/Player.hpp"
#include "include/Scene.hpp"


int main()
{
        sf::RenderWindow window(sf::VideoMode(Default::windowWidth, Default::widnowHeight),
                                                        Default::windowTitle, Default::windowStyle);
        window.setFramerateLimit(60);

        Scene test(sf::Vector2f(400,300));
        sf::Texture * tex = new sf::Texture();
        tex->loadFromFile("gfx/test.png");
        Animation anim;
        anim.setImage(tex, 64);
        anim.setOrigin(32, 32);
        Player hero(sf::Vector2f(64,64),anim);
        test.add(&hero);



        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        hero.eventUpdate(event);
                }
                FPS::update();
                window.resetGLStates();
                hero.update(FPS::dt);
                window.clear(sf::Color::Black);
                test.draw(window);
                window.display();
        }

        delete tex;
        return 0;
}
 

Scene::Scene(sf::Vector2f Size)
{
        previous = NULL; // previous scene pointer
        next = NULL;
        name = "";
        this->Size = Size;
        camera.setCenter(Default::windowWidth / 2, Default::widnowHeight / 2);
        surface.create(Size.x,Size.y, true); // sf::RenderTexture
        surfaceRenderer.setPosition(0, 0); // sprite for render sf::RenderTexture
        surfaceRenderer.setTexture(surface.getTexture());
}
//...
void Scene::draw(sf::RenderWindow & window)
{
        surface.clear(sf::Color::White);
        surface.draw(objects.back()->getAnimation());
        surface.display();
       
        window.draw(surfaceRenderer);
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::RenderTexture problem
« Reply #9 on: August 03, 2014, 10:18:45 am »
The working version of the code you posted previously would be more helpful :P
Laurent Gomila - SFML developer

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #10 on: August 03, 2014, 10:27:54 am »
It's the same as in first post, but before app.clear() line, I wrote app.resetGLStates() as Alex proposed.
EDIT: I edited first post.
« Last Edit: August 03, 2014, 10:30:11 am by fr33k »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf::RenderTexture problem
« Reply #11 on: August 03, 2014, 10:30:46 am »
By the way, you should not do that:
sf::Texture * tex = new sf::Texture();
... // big amount of code
delete tex;

The reason is that if you later add a return statement in between, or a function throws an exception, you will have memory leaks.

Instead, use RAII:
sf::Texture tex;
... // big amount of code
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: sf::RenderTexture problem
« Reply #12 on: August 03, 2014, 10:46:08 am »
I think this should be the same problem as described here: http://en.sfml-dev.org/forums/index.php?topic=14110



AlexAUT

fr33k

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: sf::RenderTexture problem
« Reply #13 on: August 03, 2014, 10:54:12 am »
Thanks Nexus, good to know about RAII :).
EDIT: First video clip is without glResetStates(), second with.
« Last Edit: August 03, 2014, 11:01:59 am by fr33k »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: sf::RenderTexture problem
« Reply #14 on: August 03, 2014, 02:47:53 pm »
Good to see you fixed the problem!  :)

Just for reporting of this problem, I'm using Radeon HD 5450 and it didn't require the "fix".
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything