Page 1 of 2

[SOLVED] SFML Help

Posted: Thu Dec 03, 2009 5:55 pm
by lotios611
I'm trying to get a window to display using SFML. Here is my code:

Code: Select all

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


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events");

    // Get a reference to the input manager associated to our window, and store it for later use
    const sf::Input& Input = App.GetInput();

    // Start main loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

        // Get some useless input states, just to illustrate the tutorial
        bool         LeftKeyDown     = Input.IsKeyDown(sf::Key::Left);
        bool         RightButtonDown = Input.IsMouseButtonDown(sf::Mouse::Right);
        bool         JoyButton1Down  = Input.IsJoystickButtonDown(0, 1);
        unsigned int MouseX          = Input.GetMouseX();
        unsigned int MouseY          = Input.GetMouseY();
        int          JoystickX       = (int)Input.GetJoystickAxis(1, sf::Joy::AxisZ);
        int          JoystickY       = (int)Input.GetJoystickAxis(1, sf::Joy::AxisY);
        int          JoystickPOV     = (int)Input.GetJoystickAxis(1, sf::Joy::AxisPOV);

        // Display window on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}
The window doesn't open, it says "Learning SFML has encountered a problem and needs to close." Any help would be very appreciated.

Re: SFML Help

Posted: Thu Dec 03, 2009 6:13 pm
by GroundUpEngine
Try putting sfml-graphics.dll, sfml-window.dll and sfml-system.dll in the same place as your executable file

Re: SFML Help

Posted: Thu Dec 03, 2009 6:21 pm
by lotios611
I did that, with the debug versions.

Re: SFML Help

Posted: Thu Dec 03, 2009 7:15 pm
by GroundUpEngine
lotios611 wrote:I did that, with the debug versions.
kk, what IDE are you using? Dev-C++, Code::Blocks, Visual?
also are you linking {sfml-system.a, sfml-graphics.a, sfml-window.a} in the library part and using SFML-DYNAMIC in the compiler settings part of your project options?

Re: SFML Help

Posted: Fri Dec 04, 2009 9:25 am
by K-Bal
You might be mixing debug and release versions.

Re: SFML Help

Posted: Fri Dec 04, 2009 1:53 pm
by lotios611
Not mixing debug and release versions. What's really annoying is that I can get the System to work, just not Window.

Re: SFML Help

Posted: Fri Dec 04, 2009 1:58 pm
by hurstshifter
#include <SFML/Window.hpp> ??


or is graphics.hpp sufficient?


Edit:
Nevermind, looks like it is in fact explicitly included in Graphics.hpp

Re: SFML Help

Posted: Fri Dec 04, 2009 2:05 pm
by K-Bal
What does your debugger show? Which version of SFML are you using? Do you have an USB joystick or gamepad plugged in?

Try calling input = App.GetInput() every frame. I also recommend the official SFML forum.

Re: SFML Help

Posted: Fri Dec 04, 2009 2:35 pm
by lotios611
Debugger says: Unhandled exception at 0x7c809e8a in Learning SFML.exe: 0xC0000005: Access violation reading location 0x0073746e.
I don't have a gamepad or USB joystick plugged in.
I'm using SFML V 1.5.
The input isn't what's wrong, the program breaks at the part where it says

Code: Select all

sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events");
I am using the code directly from the SFML tutorial.

Re: SFML Help

Posted: Fri Dec 04, 2009 2:54 pm
by K-Bal
What happens if you don't give the 32 as parameter but just 800 and 600?

Re: SFML Help

Posted: Fri Dec 04, 2009 3:01 pm
by lotios611
It still doesn't work.

Re: SFML Help

Posted: Sat Dec 05, 2009 5:01 pm
by Bludklok
K-Bal wrote:What happens if you don't give the 32 as parameter but just 800 and 600?
The 32 is just the color depth (which is correct).

Try this...

Code: Select all

#include <SFML/Graphics.hpp>
using namespace sf; //This just makes it so you don't have to keep typing sf:: before everything.

int main()
{
	RenderWindow App(VideoMode(1024, 768, 32), "SFML Graphics");
	return 0;
}
Don't forget to link to sfml-graphics-d.lib in the linker->input section of your project properties, either.

Re: SFML Help

Posted: Sun Dec 06, 2009 3:13 am
by K-Bal
Bludklok wrote:
K-Bal wrote:What happens if you don't give the 32 as parameter but just 800 and 600?
The 32 is just the color depth (which is correct).
Yeah, I just thought his hardware might not support 32 bit ;)

Re: SFML Help

Posted: Sun Dec 06, 2009 7:22 am
by lotios611
Either way, the default is 32.

Re: SFML Help

Posted: Wed Dec 09, 2009 11:00 pm
by Daxtorax
Bludklok wrote:
K-Bal wrote:What happens if you don't give the 32 as parameter but just 800 and 600?
The 32 is just the color depth (which is correct).

Try this...

Code: Select all

#include <SFML/Graphics.hpp>
using namespace sf; //This just makes it so you don't have to keep typing sf:: before everything.

int main()
{
	RenderWindow App(VideoMode(1024, 768, 32), "SFML Graphics");
	return 0;
}
Don't forget to link to sfml-graphics-d.lib in the linker->input section of your project properties, either.
If you haven't solved this already, than just replace sf::Window App(sf::VideoMode(800, 600, 32), "SFML Events"); with RenderWindow like Bludklok said. Assuming this is where the error is coming in.