Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - wofo

Pages: [1]
1
Graphics / Re: [Solved] Problem with derived class of sf::RenderWindow
« on: April 06, 2013, 09:34:17 pm »
Thank you. I am going to correct it.

2
Graphics / [Solved] Problem with derived class of sf::RenderWindow
« on: April 06, 2013, 08:15:41 pm »
I have already solved de problem, thanks to this link: https://github.com/SFML/SFML/wiki/FAQ#wiki-graphics-white-rect

Thanks 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.

Pages: [1]