SFML?

Hi all,

I just installed the SFML program on my computer, as i just started c++ programming and was redirected on this forum to use SFML instead of console applications.

The thing is, i'm at the website for the SFML reading up on some tutorials, and imo i cant really see a difference? i cant see that any tutorial is actually learning me to make something more valid that i could just use and learn via the console application? maybe im getting it wrong.

My question in short is = What is the difference on a console application and going the SFML way? im still using codeblocks as before, guess thats needed. so what on earth do i use that SFML for? :)

hope u can understand and hopefully take ur time to reply :)
You use SFML for graphical applications (including games). It also includes audio and network functionality.
However, that should be glaringly obvious, so I'm not sure what you're actually asking.
Right. SFML makes it easy to do things like draw images to the screen, play music, get realtime input from the keyboard, mouse, and gamepad devices, etc, etc. Stuff that is very useful when making games.

None of that can be accomplished with the standard C++ library. All the standard lib allows you to do is print and receive lines of text.
Hi again disch, again you clarified a bit :) so even though my c++ skills is extremely limited, all i know is loops, if /else, variables etc and a few functions, i should be able to make something work with the SFML using the tutorials provided on the website?

thanks for ur input athar :)

Sorry if im asking lots of questions, but i finally pulled myself together to really get into programming so i just wanna make sure i start out right :)
I would start with a prebuilt foundation until you get the idea.

Here's a simple SFML program taken from the below page and modified/simplified a bit:
http://www.sfml-dev.org/documentation/1.6/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 #include <SFML/Graphics.hpp>
 
 int main()
 {
     // Create the main window
     sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");
 
     // Load a sprite to display
     sf::Image Image;
     if (!Image.LoadFromFile("whatever_image.png"))  // <- save an image on your computer
         return EXIT_FAILURE;
     sf::Sprite Sprite(Image);

     // Start the game loop
     while (App.IsOpened())
     {
         // Process events
         sf::Event Event;
         while (App.GetEvent(Event))
         {
             // Close window : exit
             if (Event.Type == sf::Event::Closed)
                 App.Close();
         }
 
         // Clear screen
         App.Clear();
 
         // Draw the sprite
         App.Draw(Sprite);
 
         // Update the window
         App.Display();
     }
 
     return EXIT_SUCCESS;
 }


step 1: Get this compiling and running so you see the image

step 2: Make the image move around the screen (like have it move left until it hits the left side of the screen, then have it move right until it hits the right side... or just have it move one way and "wrap around" to the other side of the screen)

step 3: Make the image move around according to user input. So like if the user holds the up arrow, have it move up, etc.


If you can get through those 3 steps you can start to see how making a basic game will work.
I have a few minute break, so I'll just cut in here and answer that question.

Another thing that I'd say is required knowledge is how to use classes with member functions. Not how to create classes, - though that's inevitably useful ;] - just how to use them with the dot operator.

That's very quick to learn, though, so you should be fine. :)

EDIT: Dangit Disch.

-Albatross
Last edited on
Thanks for posting that code. When i try to run and compile it it displays errors saying "undefined reference to imp_blablabla"

As i said my knowledge is extremely basic, and when i read just the first tutorial on that homepage i dont really think im learning something. maybe im in over my head and should go back to my dummies book and console programs untill i get more ground covered on the c++ language?
Are you 100% sure you set up SFML correctly? SFML, like many other libraries, requires a little bit of setup to use.

Specifically, are you sure your compiler knows where the SFML libraries are and has been commanded to use them?

Don't give up, okay? It's a pain setting up an external library the first time, but it gets a lot easier after that. :)

-Ninjatross
Last edited on
When i try to run and compile it it displays errors saying "undefined reference to imp_blablabla"


Yeah that's part of setting the lib set up. You need to link to the SFML libraries.

There's a walkthrough here:

http://www.sfml-dev.org/tutorials/1.6/start-vc.php

maybe im in over my head and should go back to my dummies book and console programs untill i get more ground covered on the c++ language?


Getting it set up is definitely the hardest part. Once you get the program running you'll be over the biggest hurdle.

After that, you can play around with it and get the idea a lot faster. If you really do feel like you're in over your head still, then maybe go back to the console for a bit *shrug*

In any case, don't just abandon your book. Still read it and still try to learn the C++ language from it. But when it comes time to test the knowledge the book is teaching you, do it in game form instead of console program form. It's more fun when you apply what you've learned to a game instead of some useless program you'd never use.

EDIT: ninja's by Albatross!
Last edited on
Well i set it up enough to use that clock code in the tutorial, but maybe i need to dó some more linking or something in order to get Line of code u wrote disch working?

I ONLY followed that tutorial and didnt enable any further linking, As i wouldnt know what to enable. Just Cant seem to Make it run and compile that program... U sure i dont have to enable any further linking or something other than whats taught ón that tutorial with the clock?

Anywhoo, im writing This from my iPad in bed, so i wong be able to try before tommoroW again. Got a day off from work so ill be using quite a few hours ón hopefully doing some programming progress :) ill write a reply in This thread if i get that Line of code working :) if i dont, well u Will prolly hear from mé again.

Please note that the thoughts and time u put into helping newbies like mé is highly appriciated! I would be forever lost if i had no where go. Guess thats obvious :p
Last edited on
U sure i dont have to enable any further linking or something other than whats taught ón that tutorial with the clock?


Sorry, I thought that tutorial covered it but it looks like it doesn't cover it fully.

For the graphics stuff, you would need to link to sfml-graphics.lib. Do this the same way the tutorial shows you how to link to sfml-system.lib.

You might also need sfml-window.lib

When you get into audio stuff, you'll need to link to sfml-audio.lib as well, etc.
when i run it says "cannot find -l-lsfml-system"? what on earth does that mean? i have linked the SFML/include and SFML/lib in my Global compiler settings, i transfered the system.dll file in the project folder, and under "build options" i have linked -lsfml-system and -lfsml-graphics?

meeh hard this is :P
Yes getting it set up is difficult for newbies. But once you get this figured out you never have to do it again and the rest will be easy =P

Is this Visual C++? Or are you using some other IDE?

If this is VS, you don't link to "-lsfml-system", you link to "sfml-system.lib"

On other IDEs you probably don't link to "-lsfml-system" either, you probably just link to "sfml-system"

It looks like the IDE is adding an additional "-l" before your lib name so you don't need to do that.
Topic archived. No new replies allowed.