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

Author Topic: Window.Draw error LNK2001(Answered)  (Read 2682 times)

0 Members and 1 Guest are viewing this topic.

nickkorta

  • Newbie
  • *
  • Posts: 17
    • View Profile
Window.Draw error LNK2001(Answered)
« on: July 31, 2013, 07:42:40 pm »
Hi I started using SFML with Visual Studio 2012 today.  Iv have not ran into any problems while rendering a Window , and using events such as keyboard, joystick , window and mouse. I'm trying to display an image on screen using the "Texture" and "Sprite" Class. My image is called "Mage" witch is a png file that is in the same folder as Main. I get this error when I use write "Window.Draw(sprite)".

Error   1   error LNK2001: unresolved external symbol "public: static class sf::RenderStates const sf::RenderStates::Default" (?Default@RenderStates@sf@@2V12@B)   c:\Users\nicho_000\documents\visual studio 2012\Projects\XXX\XXX\Main.obj

My Code
#include<SFML/Graphics.hpp>

void LoadContent();
void Update();
void Draw();

sf::RenderWindow window;
sf::Texture texture;
sf::Sprite sprite;

int main()
{
        window.create(sf::VideoMode(800,600),"Game");
        LoadContent();
        while (window.isOpen())
        {
                Update();
                Draw();
        }
}

void LoadContent()
{
        texture.loadFromFile("Mage.png");
        sprite.setTexture(texture);
}

void Update()
{      
       sf::Event event;
        while (window.pollEvent(event))
        {
                if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape )
                        window.close();
        }
}

void Draw()
{
        window.clear(sf::Color(116,146,208));
        window.draw(sprite);
        window.display();
}

Thanks
« Last Edit: August 01, 2013, 02:42:50 am by nickkorta »

nickkorta

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Window.Draw error LNK2001
« Reply #1 on: July 31, 2013, 09:18:20 pm »
Ok I found something out. When I use release instead of debug everything works. Why is this happening?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window.Draw error LNK2001
« Reply #2 on: July 31, 2013, 09:43:17 pm »
Make sure that you're not mixing static and dynamic settings (read the tutorial carefully).
Laurent Gomila - SFML developer

Yemeni Cpluspluser

  • Newbie
  • *
  • Posts: 25
  • C/C++, Soon Java and SQL ^_^
    • View Profile
    • Email
Re: Window.Draw error LNK2001
« Reply #3 on: July 31, 2013, 09:47:13 pm »
Something not related to the question,
I would recommend that you use inline function because you are now calling function each frame that way.  ::)
sf::signature mySignature;
mySignature.setPosition(forum.x,forum.y);
window.draw(mySignature);

nickkorta

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Window.Draw error LNK2001
« Reply #4 on: July 31, 2013, 10:23:07 pm »
Thanks Laurent. Works now.
Yemeni Cpluspluser thanks as well. I'm new to C++ (Been using C# for a year) and never needed to worry about inline functions, but I remember them now in the C++ book I went through, I should have remembered to use them.

Edit: How do I mark this question as answered?
« Last Edit: July 31, 2013, 10:42:51 pm by nickkorta »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Window.Draw error LNK2001
« Reply #5 on: July 31, 2013, 11:14:28 pm »
Quote
How do I mark this question as answered?
You edit the title. Or you don't.
Laurent Gomila - SFML developer