Hi! I'm new to SFML (and a bit of newbie at programming), and I'm currently reading the tutorials. I'm on the sprites tutorial and I'm stuck on the first example, it says:
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
{
// error...
}
So I drew an image, named it image.png, saved it in the project folder and wrote this in my .cpp file:
#include <iostream>
#include <SFML\Graphics.hpp>
int main()
{
// create render window
sf::RenderWindow rmain(sf::VideoMode(800, 600), "My Window");
rmain.setFramerateLimit(30);
sf::Texture texture;
if (!texture.loadFromFile("image.png"))
{
std::cout << "Unable to load image from file" << std::endl;
}
// run program as long as windos is open
while (rmain.isOpen())
{
// check all the window's events that were triggered since the last iteration of loop
sf::Event event;
while (rmain.pollEvent(event))
{
// "close requested" event, close the windoe
if (event.type == sf::Event::Closed)
rmain.close();
}
// clear the window with black color
rmain.clear(sf::Color::Black);
// draw stuff here
// windoe.draw(..);
// end current frame
rmain.display();
}
return 0;
}
The error that I get is pretty crazy, it makes the console go all nuts while blips and bloops spill out from my computers alarm and I have no idea why this happens, the image is on the right place, I even moved it around the project folder in case it was misplaced, but to no avail.
Can someone please help me identify the problem and perhaps guide me through the proces of fixing it? Thanks.
Also, I did a search on the forums but I got errors every time I tried, so very sorry if this have been brought up times before.
Elias
Thanks for the fast reply!
That code shouldn't fail, you must be doing something else wrong.
That's what I figured as well, but I was unsure as to where to look for the source of the problem.
My OS is Win7 64x
I'm compiling using VS12 and the version of SFML I downloaded was "Visual C++ 11 (2012) - 32 bits", which I guess is the right one, because I want to compile for 32x and not 64x.
Oh and he line that fails is:
if (!texture.loadFromFile("image.png"))
The error I get says:
Unhandled exception at 0x738BDEF8 (msvcr110.dll) in SFML_test.exe: 0xC0000005: Access violation reading location 0x00273000.
btw, does it matter what settings I use to save .png's? In case the file I try to open is problem.