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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - buster

Pages: [1]
1
Graphics / LoadFromFile undefined reference problem
« on: September 26, 2016, 11:03:36 pm »
I have no idea what to do. I tried loading images (bmp), music (wav) or font (ttf) with LoadFromFile function, but the compiler always spits out similar error.

|In function `main':|
C:\_stuff\code blocks\projects\game1\main.cpp|14|undefined reference to `sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)'|
C:\_stuff\code blocks\projects\game1\main.cpp|15|undefined reference to `sf::Font::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'|
 

This is how the source code looks:

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>

int main()
{
    sf::Font font;
    sf::Texture hero_idle_texture;
    hero_idle_texture.loadFromFile("hero_idle.bmp");
    font.loadFromFile("arial.ttf");
    return 0;
}

I put files both in the obj file and in the exe file directory. I tried reinstalling SFML, compiler and Code::Blocks several times, but it didn't work.

I'm programming in Code::Blocks, using SFML 2.3.2 and my OS is Windows 10 64 bit.

I also tried to recompile SFML using CMake but I got this problem: http://stackoverflow.com/questions/39680283/cannot-generate-files-with-cmake-using-mingw-makefiles

2
Graphics / sf::RenderWindow problem
« on: April 11, 2015, 07:56:02 pm »
I apoligize for my laziness if a thread with this problem has already been created.

I have a problem with RenderWindow. Specifically, after compilation, I get a crash report like this:
Quote from: Windows
gamePrototype.exe stopped working
An error caused a program to stop working correctly. Windows will close the program and notify you of available solutions.
The window doesn't want to open, but the console still works.
My code:
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cmath>
#include <iostream>
float falling(float time)
{
    return 10*(time/1000);
}
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "My Window");   //1
    window.setFramerateLimit(60);
    sf::Texture texture;
    sf::Sprite sprite;
    sf::Clock clock;
    sf::Event event;
    texture.loadFromFile("cos.png");
    sprite.setTexture(texture);
    sprite.setScale(sf::Vector2f(0.1f, 0.1f));
    sf::RectangleShape rectangle(sf::Vector2f(30, 600));
    rectangle.setFillColor(sf::Color::Red);
    rectangle.setPosition(510,0);
    int a = -30, mode = 1;
    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::F10))
                window.close();
        }
        if(mode==0)
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))sprite.move(-4,0);
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))sprite.move(4,0);
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::X))
            {
                sf::Time playerTime=clock.getElapsedTime();
                float time=playerTime.asMilliseconds();
                sprite.move(0,a+falling(time));
                mode = 1;
            }
            if(sprite.getPosition().x>510&&sprite.getPosition().x<540)
            {
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))mode = 2;
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))mode = 2;
            }
            clock.restart();
        }
        if(mode==1)
        {
            sf::Time playerTime=clock.getElapsedTime();
            float time=playerTime.asMilliseconds();
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))sprite.move(-4,0);
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))sprite.move(4,0);
            if(sprite.getPosition().y<500)
            {
                sprite.move(0,falling(time));
            }
            else mode = 0;
            if(sprite.getPosition().x>510&&sprite.getPosition().x<540)
            {
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))mode = 2;
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))mode = 2;
            }
        }
        if(mode==2)
        {
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))sprite.move(0,-4);
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
            {
                if(sprite.getPosition().y<500)sprite.move(0,4);
                else mode = 0;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::X))mode = 1;
            clock.restart();
        }
        window.clear(sf::Color::White);
        window.draw(rectangle);
        window.draw(sprite);
        window.display();
    }

    return 0;
}
// 1 = everything except for this line is alright
 
I use Code::Blocks.

Pages: [1]