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

Author Topic: noob draw question  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

Icup

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
noob draw question
« on: June 19, 2012, 12:52:37 pm »
So I am trying to teach myself how to program step by step. I started using SFML because of how easy I had heard it was easy to use.  I have messed around with the code for awhile now and looked for a bit using search but I found it better just to make my own topic so I apologize if this has been answered(I am sure it has).

I have my program to where all I want it to do is display an image on my screen(starting out real slow).  For whatever reason all I get is a white screen instead of the image I am trying to load and I have no idea why this is.

#include <SFML/Graphics.hpp>

 

int main()

{
        //sets screen dimentions and sets bit depth
        sf::VideoMode VMode(800, 600, 32);
        //creates the window and gives it a name
        sf::RenderWindow Window(VMode, "SFML Test");



        sf::Texture Texture;
        if(!Texture.loadFromFile("Hero.png"))
                return 1;
        sf::Sprite Sprite;
        Sprite.setTexture(Texture);
        Sprite.setPosition(100.0f, 30.0f);




       

       
        //loop for closing the window
        while (Window.isOpen())
{
        sf::Event Event;
        while (Window.pollEvent(Event))
        {
                switch (Event.type)
                {
                case sf::Event::Closed:
                        Window.close();
                        break;
                default:
                        break;
                }
        }
}
Window.clear();
Window.draw(Sprite);
Window.display();


    return 0;

}
 

man self learning this is not going to be easy :(
« Last Edit: June 19, 2012, 12:54:32 pm by Icup »

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: noob draw question
« Reply #1 on: June 19, 2012, 01:43:42 pm »
Your clear, draw and display calls are outside your "while (Window.isOpen())" loop.
TGUI: C++ SFML GUI

Icup

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: noob draw question
« Reply #2 on: June 19, 2012, 09:24:52 pm »
oh wow... I can't believe I didn't see that. Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: noob draw question
« Reply #3 on: June 19, 2012, 10:45:49 pm »
Quote
oh wow... I can't believe I didn't see that. Thanks!
Even with your fuzzy indentation, it was pretty obvious ???
Laurent Gomila - SFML developer

 

anything