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

Author Topic: I can't draw a sprite in RenderWindow  (Read 1221 times)

0 Members and 1 Guest are viewing this topic.

Ardeshir81

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
I can't draw a sprite in RenderWindow
« 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 !

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: I can't draw a sprite in RenderWindow
« Reply #1 on: October 19, 2013, 12:07:37 pm »
What about reading the official tutorials? ;)
You never draw the sprite nor clear the screen.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything