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 - burnack

Pages: [1]
1
Graphics / Re: texture NOT updating from window
« on: November 05, 2016, 10:27:38 pm »
Thank you Hapax and Mr_Blame for the explanations, deleting the display() call has solved the problem!

2
Graphics / (Solved!) texture NOT updating from window
« on: November 04, 2016, 03:15:46 pm »
Hello, I'm facing a problem of a sf::Texture NOT updating from sf::RenderWindow in SFML 2.4.
Here's the code example:
#pragma once

#include <iostream>
#include <SFML/Graphics.hpp>

int main ()
{
        sf::RenderWindow window (sf::VideoMode (1280, 720), sf::String ("100%"));
        sf::Texture grassTexture;
        if (!grassTexture.loadFromFile ("grass.jpg", sf::IntRect (0, 0, 1280, 720)))
        {
                std::cout << "Could not load image" << std::endl;
                return -1;
        }

        sf::Sprite background (grassTexture, sf::IntRect { 0, 0, 1280, 720 });

        while (window.isOpen ())
        {
                sf::Event event;
                while (window.pollEvent (event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close ();
                       
                        if (event.type == sf::Event::MouseButtonReleased &&
                                event.mouseButton.button == sf::Mouse::Left)
                        {
                                window.clear (sf::Color::White);
                                window.display ();
                                grassTexture.update (window, 0, 0);
                                sf::Image tmpImg = grassTexture.copyToImage ();
                                tmpImg.saveToFile ("tmp.jpg");

                                background = sf::Sprite (grassTexture);
                        }
                }

                window.clear (sf::Color::White);
                window.draw (background);
       
                window.display ();

                if (sf::Keyboard::isKeyPressed (sf::Keyboard::Escape))
                {
                        window.close ();
                }
        }

        return 0;
}
 
So after a left-click the texture should update with the white screen. I even save it to an image which shows that it's still the grass image loaded initially (it's attached) and not a white image.

The udpate() function description says:
    /// No additional check is performed on the size of the window,
    /// passing an invalid combination of window size and offset
    /// will lead to an undefined behavior.
    ///
    /// This function does nothing if either the texture or the window
    /// was not previously created.
 
These both are not the case as you can see.

I'm looking forward to any help.

Pages: [1]