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

Author Topic: Error with drawing a Sprite  (Read 3018 times)

0 Members and 1 Guest are viewing this topic.

niehoelzz

  • Newbie
  • *
  • Posts: 13
    • View Profile
Error with drawing a Sprite
« on: July 11, 2016, 05:42:30 pm »
#include <SFML\Window.hpp>
#include <SFML\Graphics.hpp>


int main() {
        sf::RenderWindow mainwindow(sf::VideoMode(1920, 1080), "Mein Erstes Spiel", sf::Style::Default);

        sf::Texture background;
        background.loadFromFile("background.png");
        sf::Sprite backgroundsprite;
        backgroundsprite.setTexture(background);
       

        // As long as Window is open
        while (mainwindow.isOpen()) {
                sf::Event event;
                while (mainwindow.pollEvent(event)) {

                        if (event.type == sf::Event::Closed) {
                                // Hier kommt auch das speichern rein z.B.
                                mainwindow.close();
                        }

                        // clear window
                        mainwindow.clear();

                        // Draw here
                        mainwindow.draw(backgroundsprite);

                        // end the current frame
                        mainwindow.display();
                }
        }



        return 0;
}


I followed the Tutorial but im getting the error messages
LNK2001 and
LNK1120

Im not finding helpful thread on the internet ...
Please help me  :-X


[EDIT]
The error is where im trying to draw the sprite
mainwindow.draw(backgroundsprite);
When im removing this line it works (but obviously nothing is displayed)

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Error with drawing a Sprite
« Reply #1 on: July 11, 2016, 06:30:28 pm »
Giving us the real error message would be a nice second step. (after googling it)

niehoelzz

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Error with drawing a Sprite
« Reply #2 on: July 11, 2016, 06:57:52 pm »
Giving us the real error message would be a nice second step. (after googling it)

LNK2001    Not listed external Symbol ""public: static class sf::RenderStates const sf::RenderStatesDefault" (?Default@RenderStates@sf@@2V12@B)".
LNK1120 1 Unlisted external

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Error with drawing a Sprite
« Reply #3 on: July 11, 2016, 07:08:43 pm »
The error codes are indeed a bit strange, but I assume the issue is similar to pretty much every other linker error.
Make sure to only define DFML_STATIC when you link static libraries. Don't mix debug and release modes. Don't add multiple versions of thd same library to the linker field. Use libraries that are built for your compiler, i.e. don't use VS 13 libs in VS 14. Etc.

Can you provide the full build command?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

niehoelzz

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: AW: Error with drawing a Sprite
« Reply #4 on: July 11, 2016, 07:38:08 pm »
The error codes are indeed a bit strange, but I assume the issue is similar to pretty much every other linker error.
Make sure to only define DFML_STATIC when you link static libraries. Don't mix debug and release modes. Don't add multiple versions of thd same library to the linker field. Use libraries that are built for your compiler, i.e. don't use VS 13 libs in VS 14. Etc.

Can you provide the full build command?

Ive got the correct versions (Visual Studio 2015 and SFML C++ 14 which is for VS2015) and i dont have any static libraries linked. I didnt mix the release and debug modes. I dont know what it is.
Btw where can i find the full build command?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Error with drawing a Sprite
« Reply #5 on: July 11, 2016, 07:47:37 pm »
http://www.sfml-dev.org/faq.php#tr-grl-verbose-ide

Looks a lot like this guy who defined SFML_STATIC without linking to the -s version of the library.
From your post, it's unclear if you defined SFML_STATIC. If you wrote SFML_STATIC somewhere but aren't linking to the static libs, delete it.

niehoelzz

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Error with drawing a Sprite
« Reply #6 on: July 11, 2016, 08:25:48 pm »
Looks a lot like this guy who defined SFML_STATIC without linking to the -s version of the library.
From your post, it's unclear if you defined SFML_STATIC. If you wrote SFML_STATIC somewhere but aren't linking to the static libs, delete it.

I didnt write SFML_STATIC in the properties...

niehoelzz

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Error with drawing a Sprite
« Reply #7 on: July 11, 2016, 08:42:38 pm »
Ok guys i fixed it.

There was a SFML_STATIC in the Debug properties which i didnt see before. After removing it it worked. Thanks guys
« Last Edit: July 12, 2016, 08:05:44 am by Laurent »