[SOLVED] SFML Help

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

[SOLVED] SFML Help

Post 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.
Last edited by lotios611 on Sat Dec 12, 2009 3:31 pm, edited 1 time in total.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: SFML Help

Post by GroundUpEngine »

Try putting sfml-graphics.dll, sfml-window.dll and sfml-system.dll in the same place as your executable file
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: SFML Help

Post by lotios611 »

I did that, with the debug versions.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: SFML Help

Post 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?
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: SFML Help

Post by K-Bal »

You might be mixing debug and release versions.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: SFML Help

Post by lotios611 »

Not mixing debug and release versions. What's really annoying is that I can get the System to work, just not Window.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: SFML Help

Post by hurstshifter »

#include <SFML/Window.hpp> ??


or is graphics.hpp sufficient?


Edit:
Nevermind, looks like it is in fact explicitly included in Graphics.hpp
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: SFML Help

Post 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.
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: SFML Help

Post 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.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: SFML Help

Post by K-Bal »

What happens if you don't give the 32 as parameter but just 800 and 600?
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: SFML Help

Post by lotios611 »

It still doesn't work.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Re: SFML Help

Post 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.
Youtube
Website
Current project: Enigma Core
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: SFML Help

Post 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 ;)
User avatar
lotios611
Chaos Rift Regular
Chaos Rift Regular
Posts: 160
Joined: Sun Jun 14, 2009 12:05 pm
Current Project: Game engine for the PC, PSP, and maybe more.
Favorite Gaming Platforms: Gameboy Micro
Programming Language of Choice: C++

Re: SFML Help

Post by lotios611 »

Either way, the default is 32.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Daxtorax
ES Beta Backer
ES Beta Backer
Posts: 26
Joined: Sun Mar 15, 2009 1:34 pm
Favorite Gaming Platforms: Dreamcast, N64, Xbox 360
Programming Language of Choice: C++

Re: SFML Help

Post 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.
Post Reply