SFML community forums

Help => Graphics => Topic started by: LucasShadow on May 24, 2012, 05:31:12 am

Title: sf::RenderTexture positioning?
Post by: LucasShadow on May 24, 2012, 05:31:12 am
I am creating a simple tile generator using sf::RenderTexture and have run into an odd problem.  The below code (minimal example) should produce a nice small patch of grass, but nothing appears but a blank screen.  Am I using the rendertexture incorrectly or is this a bug?

#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;

 int main()
 {
     sf::RenderWindow App(sf::VideoMode(800, 600), "Upgrading to SFML 2.0 Testing Environment");

     sf::Texture grassimg;
     if(!grassimg.loadFromFile("img\\Terrain\\new_grass_tile.png")) {cout << "Error" << endl;};
     sf::Sprite Tile(grassimg);
     Tile.setPosition(0,0);

     float GridX = 3, GridY = 5, CountX = 0, CountY = 0, Iso = 0;
     float TileX = grassimg.getSize().x;
     float TileY = grassimg.getSize().y;
     sf::RenderTexture bg;
     bg.create(800, 800);

     for(int i = 1; i < GridX * GridY + 1; i++)
     {
         Tile.setPosition((TileX * CountX) + (TileX/2 * Iso), (TileY/2) * CountY);
         bg.draw(Tile);

         CountX++;
         if(CountX > GridX + 1 && Iso == 0) CountX = 0, CountY++, Iso = 1;
         if(CountX > GridX + 1 && Iso == 1) CountX = 0, CountY++, Iso = 0;
     }

     sf::Sprite grassobj;
     grassobj.setTexture(bg.getTexture());
     grassobj.setPosition(0,0);

     while (App.isOpen())
     {
         sf::Event Event;
         while (App.pollEvent(Event))
         {
             if (Event.type == sf::Event::Closed)
                 App.close();
         }

         App.clear();

         App.draw(grassobj);

         App.display();
     }
     return EXIT_SUCCESS;
 }
 
Title: Re: sf::RenderTexture positioning?
Post by: LucasShadow on May 24, 2012, 07:07:37 am
Nevermind, I figured it out. Feel free to delete this topic since it appears I can not.
Title: Re: sf::RenderTexture positioning?
Post by: eXpl0it3r on May 24, 2012, 12:44:56 pm
I don't think Laurent deletes threads, thus if anyone ever finds this thread the solution would be to call display() on the render texture. ;)