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

Author Topic: Failed to use Graphics  (Read 9643 times)

0 Members and 1 Guest are viewing this topic.

windhl

  • Newbie
  • *
  • Posts: 8
    • View Profile
Failed to use Graphics
« on: August 22, 2007, 04:17:19 pm »
now I am trying to test the code about Graphics

Code: [Select]

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


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

    // Load the sprite image from a file
    sfImage Image;
    if (!Image.LoadFromFile("sprite.tga"))
        return EXIT_FAILURE;

    // Create the sprite
    sfSprite Sprite(Image);

    // Change its properties
    Sprite.SetColor(sfColor(0, 255, 255, 128));
    Sprite.SetLeft(200.f);
    Sprite.SetTop(100.f);
    Sprite.SetScale(2.f);

    // Start game loop
    bool Running = true;
    while (Running)
    {
        // Process events
        sfEvent Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sfEvent::Close)
                Running = false;
        }

        // Get elapsed time
        float ElapsedTime = App.GetFrameTime();

        // Move the sprite
       if (App.GetInput().IsKeyDown(sfKey::Left))  Sprite.SetLeft(Sprite.GetLeft() - 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sfKey::Right)) Sprite.SetLeft(Sprite.GetLeft() + 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sfKey::Up))    Sprite.SetTop(Sprite.GetTop() - 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sfKey::Down))  Sprite.SetTop(Sprite.GetTop() + 100 * ElapsedTime);

        // Rotate the sprite
        if (App.GetInput().IsKeyDown(sfKey::Add))      Sprite.Rotate(- 100 * ElapsedTime);
        if (App.GetInput().IsKeyDown(sfKey::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);

        // Display sprite in our window
        App.Draw(Sprite);

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

    return EXIT_SUCCESS;
}





I have added sfml-graphics.lib ,and  I also added DevIL.dll, freetype6.dll and zlib1.dll in my project's directory. However, when I compile the code , there always are some problems:

 
Quote

error LNK2001: unresolved external symbol "public: bool __thiscall sfInput::IsKeyDown(enum sfKey::Code)const " (?IsKeyDown@sfInput@@QBE_NW4Code@sfKey@@@Z)   



Quote

error LNK2001: unresolved external symbol "private: virtual void __thiscall sfWindow::OnEvent(class sfEvent const &)" (?OnEvent@sfWindow@@EAEXABVsfEvent@@@Z)   




how  can  I  do???
 
tks very much ~~~~ :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to use Graphics
« Reply #1 on: August 22, 2007, 04:32:08 pm »
You also need to link with sfml-window.lib and sfml-system.lib.
Laurent Gomila - SFML developer

windhl

  • Newbie
  • *
  • Posts: 8
    • View Profile
I get it , but .......
« Reply #2 on: August 22, 2007, 04:53:31 pm »
firstly ,  I  use "Console App"


I compile successfully, but when I run the application, it runs wrong !!! :cry:  :?:  

Should I use "Win32 App"??


thank u~

lubos

  • Newbie
  • *
  • Posts: 17
    • ICQ Messenger - 385328377
    • MSN Messenger - qwarmail@yahoo.co.uk
    • View Profile
Failed to use Graphics
« Reply #3 on: August 22, 2007, 05:00:51 pm »
what do you mean by runs wrong? it crashes?

windhl

  • Newbie
  • *
  • Posts: 8
    • View Profile
why is it ??
« Reply #4 on: August 22, 2007, 05:04:33 pm »
code :

Code: [Select]

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


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

 

sfString Text("Hello SFML", "cheeseburger.ttf", 50);

    bool Running = true;
    while (Running)
    {
        // Process events
        sfEvent Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sfEvent::Close)
                Running = false;
        }

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

    return EXIT_SUCCESS;
}






 I  use  F10 to trace the application,   when it gos to
"   sfString Text("Hello SFML", "cheeseburger.ttf", 50);  "

there will be  a message box with  the Error:

Quote

Unhandled exception at 0x7c812a5b in sfml1.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012f45c.





why is it ??? :?:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Failed to use Graphics
« Reply #5 on: August 22, 2007, 09:31:43 pm »
Make sure you link to the "-d" versions in debug mode (sfml-graphics-d.lib, etc.), and also that you're using the multithreaded DLL CRT (in your project's options, C/C++, Code gneration, Runtime library).
... and Visual C++ 2005 of course :)
Laurent Gomila - SFML developer

 

anything