Hi all,
I am getting only white screen when rendering "outside" of main loop. I have Renderer class where I have render method and I pass sf::renderWindow by reference to there.
Renderer.cpp
#include "Renderer.h"
#include <iostream>
Renderer::Renderer() {
sf::Texture tex;
if (!tex.loadFromFile("background.png")) {
std::cout << "Error loading file \"background.png\"" << std::endl;
}
_background.setTexture(tex);
std::cout << _background.getTexture() << std::endl;
}
void Renderer::Render(sf::RenderWindow &window) {
window.clear();
window.draw(_background);
window.display();
}
Renderer.h
#ifndef __ImpossiblePlatformer_Renderer_h__
#define __ImpossiblePlatformer_Renderer_h__
#include "SFML\Graphics.hpp"
class Renderer {
public:
Renderer();
void Render(sf::RenderWindow &window);
private:
sf::Sprite _background;
};
#endif
And lastly main.cpp
#include "SFML\Graphics.hpp"
#include "Constants.h"
#include "EventHandler.h"
#include "Renderer.h"
#include <iostream>
int main() {
sf::RenderWindow window(sf::VideoMode(1280, 720), "Impossible platformer VERSION");
EventHandler eh;
Renderer renderer;
while (window.isOpen()) {
eh.LoopAllKeyEvents(window);
renderer.Render(window);
}
return 0;
}