SFML community forums

Help => Window => Topic started by: Broken on November 14, 2009, 09:34:11 pm

Title: Event
Post by: Broken on November 14, 2009, 09:34:11 pm
Hi! I'm new here and I need help I start with tutorials
Now I working with event handling
Code: [Select]
#include<SFML/Window.hpp>
int main()
{
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");
bool Running=true;
while(Running)
{
App.Display();
}
while (App.IsOpened())
{
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        // Window closed
        if (Event.Type == sf::Event::Closed)
            App.Close();

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



when I compile and build code I get window but when I press Esc or X it can't close window
sry on my english I hope that you understand me
Title: Event
Post by: G. on November 14, 2009, 10:12:06 pm
That's definitely not in the tutorial. ;)

You have two loops and you never get out of the first one.
Title: Event
Post by: Broken on November 14, 2009, 10:25:20 pm
Yes that is not from tutorial but that is code from tutorial can you correct what is wrong
Title: Event
Post by: Dominator on November 14, 2009, 10:49:17 pm
You have to put the event loop in the main loop. I'd do it like this:

Code: [Select]

  while (Running && App.IsOpened()) //main loop
  {
     App.Display();

     while (App.GetEvent(Event)) //event loop
     {
        //handle events
     }
  }


You should acquire some basic knowledge in programming first, loops are very fundamental.
Title: Event
Post by: Broken on November 15, 2009, 01:33:08 am
thx
Title: Event
Post by: Broken on November 15, 2009, 04:29:54 pm
I have problem with time handling when i compile and run code i get this error
Code: [Select]
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Clock::Reset(void)" (__imp_?Reset@Clock@sf@@QAEXXZ) referenced in function _main
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: float __thiscall sf::Clock::GetElapsedTime(void)const " (__imp_?GetElapsedTime@Clock@sf@@QBEMXZ) referenced in function _main
sfml.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Clock::Clock(void)" (__imp_??0Clock@sf@@QAE@XZ) referenced in function _main
C:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml-timehandling.cpp\Debug\sfml-timehandling.cpp.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml-timehandling.cpp\sfml-timehandling.cpp\Debug\BuildLog.htm"
sfml-timehandling.cpp - 4 error(s), 0 warning(s)
Title: Event
Post by: Laurent on November 15, 2009, 04:46:02 pm
This is explained in the tutorial. There are even screenshots to show what to do in the project's settings.
Title: Event
Post by: Broken on November 15, 2009, 05:05:46 pm
in inputa I add sfml-window.lib in preprocesor SFML_DYNAMIC, I even add sfml-window.dll and sfml-system.dll in folder where is my project
Title: Event
Post by: Laurent on November 15, 2009, 07:06:43 pm
sf::Clock is defined in sfml-system.lib.
Title: Event
Post by: Broken on November 15, 2009, 07:13:13 pm
so in input i must put sfml-system.lib not sfml-window.lib why in tutorial about event handling is not included in source code <SFML/System.hpp>
Title: Event
Post by: Laurent on November 15, 2009, 07:17:11 pm
Because System.hpp is included by Window.hpp.
Title: Event
Post by: Broken on November 15, 2009, 08:08:21 pm
you say that in input always  must be sfml-system.lib ok i will try later because i have some work to do now
Title: Event
Post by: Nexus on November 15, 2009, 09:18:04 pm
Quote from: "Broken"
you say that in input always  must be sfml-system.lib
Hmm, I don't know if I understand this right, but input handling is part of the Window package (the headers of which include the System package).
Title: Event
Post by: Laurent on November 15, 2009, 11:14:25 pm
I think he was talking about the "input libraries" field of the linker settings in Visual Studio ;)
Title: Event
Post by: Broken on November 15, 2009, 11:40:44 pm
I try now and it doesn't work
I do this
file>new project>win32 console app.>source file>add new .cpp file>project>properties>c++>preprocessor>preprocessor definitions>where i write SFML_DYNAMIC; it looks like this "SFML_DYNAMIC;WIN32;_DEBUG;_CONSOLE">then linker>input>additional dependencies>sfml-system.lib>OK

I put sfml-system,-graphics dlls in folder where is project
and put this code in file .cpp

Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>


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

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

            // A key has been pressed
            if (Event.Type == sf::Event::KeyPressed)
            {
                // Escape key : exit
                if (Event.Key.Code == sf::Key::Escape)
                    App.Close();

                // F1 key : capture a screenshot
                if (Event.Key.Code == sf::Key::F1)
                {
                    sf::Image Screen = App.Capture();
                    Screen.SaveToFile("screenshot.jpg");
                }
            }
        }

        // Clear the screen with red color
        App.Clear(sf::Color(200, 0, 0));

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

    return EXIT_SUCCESS;
}

and build and then i get errors

 what is wrong?
Code: [Select]
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Display(void)" (__imp_?Display@Window@sf@@QAEXXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::Clear(class sf::Color const &)" (__imp_?Clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Image::~Image(void)" (__imp_??1Image@sf@@QAE@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Image::SaveToFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (__imp_?SaveToFile@Image@sf@@QBE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class sf::Image __thiscall sf::RenderWindow::Capture(void)const " (__imp_?Capture@RenderWindow@sf@@QBE?AVImage@2@XZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Close(void)" (__imp_?Close@Window@sf@@QAEXXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::GetEvent(class sf::Event &)" (__imp_?GetEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::IsOpened(void)const " (__imp_?IsOpened@Window@sf@@QBE_NXZ) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned long,struct sf::WindowSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUWindowSettings@1@@Z) referenced in function _main
cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
C:\Documents and Settings\Valentin\My Documents\Visual Studio 2008\Projects\sfml_grap.cpp\Debug\sfml_grap.cpp.exe : fatal error LNK1120: 12 unresolved externals
Title: Event
Post by: Laurent on November 16, 2009, 08:05:38 am
You forgot sfml-graphics.lib.

SFML is a modular project made of 5 separate modules, you have to link every module that you use.
Title: Event
Post by: Broken on November 16, 2009, 08:22:25 am
how ?
you think i need in input write sfml-system.lib,sfml-window.lib,sfml-graphics.lib
or i need first link in input sfml-system.lib then delete that and write sfml-graphics.lib
Title: Event
Post by: Hiura on November 16, 2009, 10:27:56 am
Write them all.
Title: Event
Post by: Laurent on November 16, 2009, 12:19:16 pm
Quote
you think i need in input write sfml-system.lib,sfml-window.lib,sfml-graphics.lib

Yes.
Title: Event
Post by: Broken on November 16, 2009, 08:24:03 pm
thanks it finally works  :D  
anyone who has the same problem like me he heed write in input
sfml-system.lib sfml-window.lib sfml-graphics.lib