SFML community forums

Help => Graphics => Topic started by: Ardeshir81 on October 19, 2013, 12:00:21 pm

Title: I can't draw a sprite in RenderWindow
Post by: Ardeshir81 on October 19, 2013, 12:00:21 pm
HI !
I am new to SFML .
I wanted to make a window and show a picture inside it .
I create the window correctly and the picture is loaded correctly , BUT I still can't display the sprite .
What I did is I created a RenderWindow and I tried to loadFromFile a sprite , BUT I saw an error indicating its not possible , so I loadeFromFileED a texture and setTextureED the sprite .
BUT I still can't observe the picture .
This is my code :
#include <SFML/graphics.hpp>
#include <iostream>

using std :: cout ;

int main ()
{
    sf::RenderWindow winMain (sf::VideoMode(800,600),"Test") ;
    sf::Texture winTexture ;
    if (!winTexture.loadFromFile("Untitled.jpg"))
    {
        cout << "ERROR opening Untitled.jpg" ;
    }
    sf::Sprite winSprite ;
    winSprite.setTexture(winTexture) ;
    winMain.display() ;
    while (winMain.isOpen())
    {
        sf::Event winEvent ;
        while (winMain.pollEvent(winEvent))
        {
            winMain.draw(winSprite) ;
            winTexture.update (winMain) ;
            switch (winEvent.type)
            {
            case sf::Event::Closed :
                winMain.close() ;
                break ;
            }
        }
    }
}
 
Thnaks !
Title: Re: I can't draw a sprite in RenderWindow
Post by: eXpl0it3r on October 19, 2013, 12:07:37 pm
What about reading the official tutorials (http://www.sfml-dev.org/tutorials/2.1/)? ;)
You never draw the sprite nor clear the screen.