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

Author Topic: The RenderTexture deform my sprites.  (Read 1755 times)

0 Members and 1 Guest are viewing this topic.

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
The RenderTexture deform my sprites.
« on: April 07, 2014, 11:02:18 am »
Hi, I've two source codes : once with draw sprites on a render window, and the other with draw sprites on a render texture and then draw this rendertexture on the renderwindow, but, when I draw my sprites on the render texture, they are deformed :

Here is the code and a screenshot of the two different results :
(First : it draws normally)

#include <SFML/Graphics.hpp>
#include "fastRenderComponentManager.h"
using namespace sf;
std::vector<sf::Sprite> generate_map(Texture& text, IntRect rect) {
    int startX = rect.left / 100 * 100;
    int startY = rect.top / 50 * 50;
    int endX = (rect.left + rect.width) / 100 * 100;
    int endY = (rect.top + rect.height) / 50 * 50;
    std::vector<sf::Sprite> ground;  
    for (int x = startX; x <= endX; x+=100) {
        for (int y = startY; y <= endY;  y+=50) {          
            Vector2f pos(x, y);        
            Sprite sprite (text);
            sprite.setPosition(pos);
            ground.push_back(sprite);
        }
    }
    return ground;
}
int main()
{
    // création de la fenêtre
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
    sf::Texture text;
    text.loadFromFile("tilesets/herbe.png");
    std::vector<Sprite> ground = generate_map(text,IntRect(0, 0, 1000, 1000));
    // on fait tourner le programme tant que la fenêtre n'a pas été fermée
    while (window.isOpen())
    {
        // on traite tous les évènements de la fenêtre qui ont été générés depuis la dernière itération de la boucle
        sf::Event event;
        while (window.pollEvent(event))
        {
            // fermeture de la fenêtre lorsque l'utilisateur le souhaite
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // effacement de la fenêtre en noir
        window.clear(sf::Color::Black);
        // c'est ici qu'on dessine tout
        for (unsigned int i = 0; i < ground.size(); i++)
            window.draw(ground[i]);

        // fin de la frame courante, affichage de tout ce qu'on a dessiné
        window.display();
    }

    return 0;
}
 

http://img15.hostingpics.net/pics/695819result1.jpg

And here's the second source code which give me a different result :

#include "fastRenderComponentManager.h"
#include <iostream>
using namespace sf;
FastRenderComponentManager::FastRenderComponentManager(RenderWindow& window) : window (window) {
}
void FastRenderComponentManager::clearBufferBits(sf::Color color) {
    clrColor = color;
    frameBuffer->clear(color);
}
Sprite FastRenderComponentManager::getFrameBufferTile () const {
    Sprite sprite (frameBuffer->getTexture());
    return sprite;
}
void FastRenderComponentManager::draw(Drawable& drawable, RenderStates states) const {  
    frameBuffer->setView(window.getView());
    frameBuffer->draw(drawable, states);
    frameBuffer->display();  
    Sprite sprite = getFrameBufferTile();
    window.draw(sprite);
}
FastRenderComponentManager::~FastRenderComponentManager() {
    delete frameBuffer;
    delete depthBuffer;
    delete depthBufferGenerator;
    delete frameBufferGenerator;
}
 
#include <SFML/Graphics.hpp>
#include "fastRenderComponentManager.h"
using namespace sf;
std::vector<sf::Sprite> generate_map(Texture& text, IntRect rect) {
    int startX = rect.left / 100 * 100;
    int startY = rect.top / 50 * 50;
    int endX = (rect.left + rect.width) / 100 * 100;
    int endY = (rect.top + rect.height) / 50 * 50;
    std::vector<sf::Sprite> ground;
    //Positions de départ et d'arrivées en fonction de la taille, de la position et de la taille des cellules de la map.
    for (int x = startX; x <= endX; x+=100) {
        for (int y = startY; y <= endY;  y+=50) {
            //On projete les positions en fonction de la projection du jeux.
            Vector2f pos(x, y);
            //Mur du coin en haut à gauche.
            Sprite sprite (text);
            sprite.setPosition(pos);
            ground.push_back(sprite);
        }
    }
    return ground;
}
int main()
{
    // création de la fenêtre
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
    sf::Texture text;
    text.loadFromFile("tilesets/herbe.png");
    std::vector<Sprite> ground = generate_map(text,IntRect(0, 0, 1000, 1000));
    FastRenderComponentManager componentManager(window);
    // on fait tourner le programme tant que la fenêtre n'a pas été fermée
    while (window.isOpen())
    {
        // on traite tous les évènements de la fenêtre qui ont été générés depuis la dernière itération de la boucle
        sf::Event event;
        while (window.pollEvent(event))
        {
            // fermeture de la fenêtre lorsque l'utilisateur le souhaite
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // effacement de la fenêtre en noir
        window.clear(sf::Color::Black);
        componentManager.clearBufferBits(sf::Color::Transparent);
        // c'est ici qu'on dessine tout
        for (unsigned int i = 0; i < ground.size(); i++)
            componentManager.draw(ground[i]);

        // fin de la frame courante, affichage de tout ce qu'on a dessiné
        window.display();
    }

    return 0;
}
 
http://img15.hostingpics.net/pics/868542result2.jpg

My sprites are scaled on y...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: The RenderTexture deform my sprites.
« Reply #1 on: April 07, 2014, 11:18:20 am »
One would think, you'd know by now how to create a minimal but complete example........

Is frameBuffer a global?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: The RenderTexture deform my sprites.
« Reply #2 on: April 07, 2014, 11:21:44 am »
Nobody will try to help you if you continue to post incomplete parts of your big project. Please write a complete and minimal example that reproduces the problem, as explained here. It will help both you and us.

Learn how to debug problems in a limited context, you'll save precious time and forum posts ;)
Laurent Gomila - SFML developer

Lolilolight

  • Hero Member
  • *****
  • Posts: 1232
    • View Profile
Re: The RenderTexture deform my sprites.
« Reply #3 on: April 07, 2014, 11:26:06 am »
Ha sorry but sometimes I'm stupid. :X

frameBuffer->create(resolution.x, resolution.x);
 frameBuffer->create(resolution.x, resolution.y);


Quote
Learn how to debug problems in a limited context, you'll save precious time and forum posts ;)

Yeah it's what I'm doing, because I don't find the bug in my big project so...