Setting up the SFML 2 Release candidate

Posted by Astryl on Jan. 31, 2013, 3:45 a.m.

Copy-pasted from here.

Anybody who has been spying on me thanks to Twitter, Facebook or whatever other communistsocialist media sites I happen to be on might have seen something I posted about accidentally deleting my SFML folder…

So I used this unfortunate accident as a convenient excuse to go and install the SFML 2 RC, and figure out how it works. So here's an overview:

Begin of copy-pasta

Note that this is specifically for setting up the library using Code::Blocks and MinGW. Should translate to the Linux version of CB quite easily.

First things first:http://www.sfml-dev.org/download.php#2.0-rc

Unzip it somewhere sensible. I use C:\Dev\SFML-2.0-rc

Now open Code::Blocks. There are two ways to use the library. Either you can make a project template, or you can change the global compiler path and allow it to use the SFML library at all times. I do the latter.

The process for doing it on a per-project basis simple requires one to use the Project->Build Options menu instead of the Settings->Compiler and Debugger menu.

Anyway, open Settings->Compiler and Debugger. On this page, we want the Search Directories tab, Compiler sub-tab. Here, click on Add, and locate the include directory in the SFML-2.0-rc folder.

Then, switch to the Linker sub-tab, hit Add again, and point it to the lib folder.

Your compiler can now 'see' the SFML headers.

Linking to the SFML library

The names of the libraries haven't changed, but here's a basic configuration I use. In the Project->Build Options->Linker tab, in the Linker Options text box, I usually place the following:

[i]-lsfml-graphics[/i]
[i]-lsfml-window[/i]
[i]-lsfml-system[/i]
[i]-lsfml-main<br />[/i]

Static libraries don't seem to be working right now, for some reason or other, so you'll have to make do with the DLLs. Make sure to move them to the directory your program resides in. Otherwise, it all seems to be plain ol' SFML…

… Or not.

Here's a snippet of code from a bare-bones 'blank window' test I just coded:

// SFML 2 test

#include &lt;SFML/Graphics.hpp>
#include &lt;SFML/Window.hpp>
#include &lt;SFML/System.hpp>

int main(int argc, char** argv)
{
    sf::RenderWindow app(sf::VideoMode(640,480,32),"SFML 2 Test Window");
    app.setFramerateLimit(60);

    while(app.isOpen())
    {
        sf::Event event;
        while(app.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)app.close();
        }

        app.clear();
        app.display();
    }
    return 0;
}

Note the subtle differences. Also, the RenderWindow class has some nice additions to it, and I noticed the addition of a RenderTexture class. I can see these all becoming very useful in my future work.

End of copy-pasta

One + for 64Digits. Our blog editor is better than Tumblr's. It keeps adding in <p> tags whenever it feels like it, forcing me to use the HTML editor. Not that I'll complain too much; I needed to use the HTML editor regardless. Can't format my code otherwise.

Anyway, I promise a potentially interesting blog next time. Unless I forget.

Comments

Astryl 11 years, 7 months ago

Actually, he seems to be standardizing them, making them easier to remember or predict. So I won't complain.

svf 11 years, 7 months ago

oh, it's not a huge deal. unless you make a huge program….

haha.

Ctrl + F ahoy!