1
Graphics / Error while loading image
« on: September 24, 2016, 12:46:30 pm »
I'am getting this error while trying loading image using loadFromFile. I tried placing my png in the buid directory, but it seems like it's not the problem. i'm getting same error no matter what. I have all dlls needed in buid folder.
PS. Sorry for the format, I'm totaly new here. Any critique comments are welcome
PS. Sorry for the format, I'm totaly new here. Any critique comments are welcome
Quote
#include <iostream>
#include <math.h>
#include <SFML/Graphics.hpp>
using namespace std;
int main()
{
sf::Vector2f position;
sf::Vector2f velocity;
float maxspeed = 4.0f;
float accel = 1.5f;
float decel = 0.01f;
sf::RenderWindow window(sf::VideoMode(800, 600), "Main Window");
window.setFramerateLimit(60);
sf::RectangleShape shape(sf::Vector2f(20,20));
shape.setFillColor(sf::Color::Red);
shape.setPosition(400,300);
sf::Texture texture;
if(!texture.loadFromFile("whatever.png")) // It doesnt matter what path I type, error is the same.
{
cout<< "Texture loading failed";
}
else
{
cout<<"texture loaded succesfully";
}
sf::Sprite sprite;
sprite.setTexture(texture);
sprite.setPosition(400,600);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
{
window.close();
}
break;
}
}
window.clear(sf::Color::White);
window.draw(shape);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
velocity.x -= accel;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
velocity.x += accel;
}
else
{
velocity.x *= decel;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
velocity.y -= accel;
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
velocity.y += accel;
}
else
{
velocity.y *= decel;
}
if(velocity.x < -maxspeed) velocity.x = -maxspeed;
if(velocity.x > maxspeed) velocity.x = maxspeed;
if(velocity.y < -maxspeed) velocity.y = -maxspeed;
if(velocity.y > maxspeed) velocity.y = maxspeed;
position += velocity;
shape.setPosition(position);
float actualspeed = sqrt((velocity.x * velocity.x) + (velocity.y * velocity.y));
if(actualspeed > maxspeed)
{
velocity *= maxspeed / actualspeed;
}
window.display();
}
return 0;
}