The whole problem was that you never created the render texture, thus it had a size of (0,0) and obviously nothing gets displayed...
Here's a fully working code. I cleaned up your strange indentation (now uses tabs) and removed the useless vector thingy. I mean there's no sense in reading it into one vector if you're going to draw it once to a render texture and then use that texture. You don't need the sprites objects later. I also fixed the possibility that the program crashes if the map file doesn't exists and a few other minor things...
You should really stop just trying to 'solve' things by programming and rather sit down and think about what you're doing.
Edit: Hmm the indentation doesn't look that nice now either...
@Laurent: Is it really necessary that one tab gets translated to 8 spaces? :O
#include <iostream>
#include <fstream>
#include <SFML/Graphics.hpp>
class Map
{
public:
int map_x, map_y; // width, height
int map[100][100]; // Maparray
sf::Texture textur; // Texture from Image Tilemap
sf::RenderTexture rMap; // Texture sMap
sf::Sprite sMap; // Mapsprite
public:
Map() :
map_x(0),
map_y(0)
{
// Loading Texture
if(!textur.loadFromFile("boden.png"))
{
std::cout << "boden.png konnte nicht geladen werden!\n";
}
};
// Just tilesize
static int getTile()
{
return 32; // 1 Tile = 32 Pixel
}
void loadMap(const char *filename)
{
// Load map from filename, first line width and height, other lines: id of tile
int loadCounterX = 0, loadCounterY = 0;
std::ifstream file(filename);
// Exit if file doesn't exist
if(!file.is_open())
{
std::cout << "Couldn't open '" << filename << "'. Aborting." << std::endl;
return;
}
file >> map_x >> map_y;
while(!file.eof())
{
file >> map[loadCounterX][loadCounterY];
loadCounterX++;
if(loadCounterX >= map_x)
{
loadCounterX = 0;
loadCounterY++;
}
}
// Create the off screen texture
rMap.create(map_x*32, map_y*32);
rMap.clear();
// Create tiles
for(unsigned int y = 0; y < map_y; ++y)
for(unsigned int x = 0; x < map_x; ++x)
{
sf::IntRect ir(map[y][x]*32, 0, 32, 32);
sf::Sprite sprite(textur, sf::IntRect(map[y][x]*32, 0, 32, 32));
sprite.setPosition(x*32, y*32);
rMap.draw(sprite);
}
rMap.display();
rMap.getTexture().copyToImage().saveToFile("test.png");
sMap.setTexture(rMap.getTexture(), true);
}
// get Mapsprite
const sf::Sprite& getSprite() const
{
return sMap;
}
//draw Mapsprite on target
void draw(sf::RenderTarget& target) const
{
target.draw(sMap);
}
};
int main()
{
// Create window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML");
// Limit framerate
window.setFramerateLimit(60);
Map mm;
mm.loadMap("map1.txt");
while(window.isOpen())
{
// Event handling
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
// Render
window.clear();
mm.draw(window);
window.display();
}
}