Hello World with SFML
The main purpose of this assignment is for you to get up and running with your build environment. You'll write a bit of code. Also you'll join the class's Google discussion group.
1. Get your build environment set up
You must use GCC and Make to configure and build your code. The reference compiler for the course is
g++ version 4.6.3.
There are various options:
(a) You have your own Linux machine. Then, install SFML. Note, please follow directions here, they're much easier than any other way! Linux Setup
(b) You have a Mac. If you like, you can use it. See guidance here: Mac Setup
(c) You have a Windows machine. You have a few options.
- You can set up a virtual machine. Two popular options are VirtualBox and VMware Player.
We are supporting VirtualBox. See instructions here: Configure VirtualBox
- You can use the department's Linux machines in the 308 and 310 labs. NOT YET
- You can install Linux and dual-boot your machine. We recommend Ubuntu Desktop. Often, it is straightforward to set up for dual-bootbut there is potential for things to go awry and render your machine non-bootable.
So, we recommend this only if you are confident about being able to recover in case of problems, and that you definitely have your Windows machine backed up.
(You have to have Windows on the machine first; then install Ubuntu.)
We are using the C++ Simple Fast Media Library, SFML, www.sfml-dev.org. Either version 2.0 or 2.1 will work. Do not install 1.6.
You may use any IDE that you like, or none at all.
2. Build the SFML Hello World code
The SFML “did I install everything correctly” code is about 20 lines long and results in your computer popping up a window like this:
Go to the tutorial for your platform, e.g. http://www.sfml-dev.org/tutorials/2.1/start-linux.php, and get the code running on your machine.
3. Extend the demo code.
Now that you've got things running, do something fun with SFML. In addition to the green circle, look at the documentation and get your window to show:
- drawing an image sprite
- make the image sprite move
- make the image sprite respond to keystrokes
- make it do something else
Use the documentation at http://www.sfml-dev.org/documentation/2.1/.
You probably want to make your window bigger than the 200x200 specified in the Hello World code. Also, no need for audio now (we will be using it later).
For #2 and #3 above, you can make x, y variables that represent the position of the sprite, and update them when a keystroke is detected. You're welcome to do something more complicated if you like. The
window.setFramerateLimit() method might be helpful if things move too fast (see “Controlling the framerate” at http://www.sfml-dev.org/tutorials/2.1/window-window.php).
- It's correct to clear everything in the window and redraw stuff each time through the event loop. That's how SFML works.
- You reposition things (e.g. a sprite) by setting its position before you draw it. Check the sprite API docs.
- Use only relative paths to load your sprite imagee.g.
- If you draw stuff outside the bounds of the window, you won't see it :)
When you compile your code, add the flags
-Wall -Werror -ansi -pedantic. We will be using these to test your code, and your code must compile when these flags are used.
Make sure your code file is named
main.cpp. You will submit this. Make sure your name is at the top of the file.
Make sure your sprite image file is named
sprite.png. You will submit this.
When you are done, take a screenshot of just your SFML window, and save this image in a file named
screenshot.png. You will submit this.
If you are new to Ubuntu, I highly recommend Shutter for doing screen grabs of windows or a selected area of the screen. Install with:
sudo add-apt-repository ppa:shutter/ppa sudo apt-get update sudo apt-get install shutter
The Print Screen key also works, but you'll have to crop the grab afterward to just show your SFML window.
4. Additional Course Participation
Please do the following:
- Sign up for the course discussion group. You may do this by either:
- logging into your Google account, visiting https://groups.google.com/forum/#!forum/91-204-s15, and requesting to join, or
- entering your email addr into the form at the bottom of the course homepage
- Review the Academic Integrity discussion at the bottom of the course homepage. Follow the link to the University policy on Academic Integrity, and answer the following question:
5. Assignment readme File
Before submitting, fill out info in the
ps0-readme.txt file. Make sure you re-save it as a text only file. It must be named
You will be submitting at least four files.
- Your SFML demo program, named
- Your sprite image file, named
sprite.png. (If you made more than one sprite, you can name the others whatever you like.)
- Your screen grab showing your code running, named
- Your completed
The four files must be in a subdirectory named
cd to the directory containing the three files, and type the following:
You should see the three files:
main.cpp ps0-readme.txt screenshot.png sprite.png
Then, type the following commands to make a gzipped tar archive of the directory:
$ cd .. $ tar czvf my-submit.tar.gz ps0
You should see the following displayed:
ps0/ ps0/sprite.png ps0/screenshot.png ps0/ps0-readme.txt ps0/main.cpp
Then, submit the file
my-submit.tar.gz to the autograder. (Note: you don't have to call it my-submit.tar.gz. It would be better to name it with your real name and PS0, e.g. fredm-ps0.tar.gz. But it must be a gzipped tar of the correct directory.)
Submit as follows:
- Martin section (201): https://grader.cs.uml.edu/assignments/464
- Grinberg section (202): https://grader.cs.uml.edu/assignments/465
|core implementation||6||full & correct implementation|
|1 pt file name correct|
|1 pt for SFML window being displayed|
|1 pt for image|
|1 pt for image being in moving sprite|
|1 pt for sprite changing direction or somehow responding to keystrokes|
|1 pt for additional feature (explain in README)|
|screenshot||2||screenshot of just SFML window included|
|-1 pt if it's a screen-grab of your entire monitor|
|tar.gz archive||2||all files packaged in .tar.gz file with correct directory structure|