I have already solved de problem, thanks to this link:
https://github.com/SFML/SFML/wiki/FAQ#wiki-graphics-white-rectThanks anyway.
__________
Original post:
I am facing the following problem. I want to create a subclass of sf::RenderWindow but it doesn't display the images that I load, but just a white square of the same dimensions.
I post first a normal code (not object oriented), which shows the image that I load without any problem.
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
window.setVerticalSyncEnabled(true);
// Load a sprite to display
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
return EXIT_FAILURE;
sf::Sprite sprite;
sprite.setTexture(texture);
// Start the game loop
while ( true )
{
// Clear screen
window.clear();
// Draw the sprite
window.draw(sprite);
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
I post a second code, in which I use my subclass. The problem is that instead of showing the image that I load, it shows a white square of the same dimensions.
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
class CustomWindow : public sf::RenderWindow {
private:
sf::Sprite sprite;
public:
CustomWindow();
void drawSprite();
};
CustomWindow::CustomWindow() : sf::RenderWindow(sf::VideoMode(800, 600), "SFML window") {
setVerticalSyncEnabled(true);
sf::Texture texture;
texture.loadFromFile("image.png");
sprite.setTexture(texture);
}
void CustomWindow::drawSprite() {
draw(sprite);
}
int main()
{
// Create the main window
CustomWindow window;
// Start the game loop
while ( true )
{
// Clear screen
window.clear();
// Draw the sprite
window.drawSprite();
// Update the window
window.display();
}
return EXIT_SUCCESS;
}
I think that this is a very strange issue. Please help if you know something about it.
Thanks in advance,
Wofo.