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

Author Topic: short example of sfml [ SOLVED ]  (Read 1964 times)

0 Members and 1 Guest are viewing this topic.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
short example of sfml [ SOLVED ]
« on: July 31, 2015, 05:45:27 pm »
hi im trying to run this example
http://www.sfml-dev.org/documentation/2.3.1/
but when every time i want to run this the window will quickly close and i cannot see any thing!
what must i do ? :-\
thanks
« Last Edit: July 31, 2015, 06:12:50 pm by raminlich »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: short example of sfml
« Reply #1 on: July 31, 2015, 05:57:38 pm »
Did you just copy and paste that example? It's trying to load a texture called cute_image.jpg and a music file called nice_music.ogg. Do those exist on your system? If it fails to load those then it will immediately return EXIT_FAILURE.

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: short example of sfml
« Reply #2 on: July 31, 2015, 06:03:12 pm »
no i write code one by one here its my code

#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>

using namespace sf;

int main(){
        // First create main window
        RenderWindow window(VideoMode(800, 600), "SFML Window");
        //load texture
        Texture texture;
        if (!texture.loadFromFile("E:\img.jpg"));
        Sprite sprite(texture);
        return EXIT_FAILURE;
        //create graphical text
        Font font;
        if (!font.loadFromFile("E:\font.TTF"));
        return EXIT_FAILURE;
        Text text("HELLO SFML", font, 50);

        //load music
        Music music;
        if (!music.openFromFile("E:\nice_music.ogg"));
        return EXIT_FAILURE;

        //play music
        music.play();
        // Start the game loop
        while (window.isOpen())
        {
                // Process events
                Event event;
                while (window.pollEvent(event))
                {
                        // Close window: exit
                        if (event.type == Event::Closed)
                                window.close();
                }
                window.clear();
                window.draw(sprite);
                window.draw(text);
                window.display();
        }
        return EXIT_SUCCESS;

}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10989
    • View Profile
    • development blog
    • Email
Re: short example of sfml
« Reply #3 on: July 31, 2015, 06:05:33 pm »
You should use forward slashes for all paths and check the console for any errors like when it can't open a file.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: short example of sfml
« Reply #4 on: July 31, 2015, 06:10:11 pm »
You're exiting with EXIT_FAILURE even when the textures load correctly. Your "if" statements don't do anything based on the condition.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

raminlich

  • Newbie
  • *
  • Posts: 16
    • View Profile
    • Email
Re: short example of sfml
« Reply #5 on: July 31, 2015, 06:11:57 pm »
You should use forward slashes for all paths and check the console for any errors like when it can't open a file.

thanks this has solve my problem and thank u for tip  ;D

 

anything