Hello,
I am new to SFML and I am trying to learn to load and draw a .png to a window. I am using the Codelite IDE with TDM-GCC-32 compiler. here is my code:
#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
sf::Texture texture;
if(!texture.loadFromFile("texture.png"))
return 1;
sf::Sprite sprite;
sprite.setTexture(texture);
sf::RenderWindow window(sf::VideoMode(500, 500), "SFML works!");
while (window.isOpen()) { //Game Loop
sf::Event event; //Process Events
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) { //Close Window: exit
window.close();
}
if(event.type == sf::Event::KeyPressed){ //Gets WSAD key strokes
if(event.key.code == sf::Keyboard::W){
cout<<"you hit the W key" << endl;
window.draw(sprite);
}
if(event.key.code == sf::Keyboard::A){
cout<<"you hit the A key" << endl;
}
if(event.key.code == sf::Keyboard::S){
cout<<"you hit the S key" << endl;
}
if(event.key.code == sf::Keyboard::D){
cout<<"you hit the D key" << endl;
}
}
}
}//End of Game Loop
return 0;
}
My Error message tells of an undefined reference to my 'loadfromfile' line.
build log:
C:\WINDOWS\system32\cmd.exe /C C:/TDM-GCC-32/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ SFML - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Projects/SFML'
C:/TDM-GCC-32/bin/g++.exe -o ./Debug/SFML @"SFML.txt" -L. -LC:/SFML-2.3.2-windows-gcc-4.8.1-tdm-32-bit/SFML-2.3.2/lib -lsfml-graphics -lsfml-window -lsfml-system
./Debug/main.cpp.o: In function `main':
C:/Projects/SFML/main.cpp:12: undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/SFML] Error 1
SFML.mk:78: recipe for target 'Debug/SFML' failed
mingw32-make.exe[1]: Leaving directory 'C:/Projects/SFML'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====2 errors, 0 warnings====
Any help with this issue would be awesome!
Thanks,
lane