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

Author Topic: Error while loading image  (Read 2473 times)

0 Members and 1 Guest are viewing this topic.

Lighting

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
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  :)


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;
}


« Last Edit: September 24, 2016, 01:02:37 pm by Lighting »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Error while loading image
« Reply #1 on: September 24, 2016, 05:26:43 pm »
You are probably linking debug libs(the ones -d suffix) in release or release libs in debug(without -d suffix).

Lighting

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Error while loading image
« Reply #2 on: September 25, 2016, 01:51:10 pm »
Thanks man, looks like debugger caused this problem. Thanks for help :)

 

anything