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;
}