Recent Changes - Search:
ECG Home






Fall 2017

Older Courses

Spring 2017

Fall 2016

Spring 2016

Fall 2015

Spring 2015

Fall 2014

Spring 2014

Fall 2013

Spring 2013

Fall 2012

Spring 2012

Fall 2011

Spring 2011

Fall 2010

Spring 2010

Fall 2009

Spring 2009

Fall 2008

Spring 2008

Fall 2007


edit SideBar


Home Assignments Lecture Blog Resources Discussion Group

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.

  1. You can set up a virtual machine. Two popular options are VirtualBox and VMware Player.

    We are supporting VirtualBox. See instructions here: Configure VirtualBox
  2. You can use the department's Linux machines in the 308 and 310 labs. NOT YET
  3. You can install Linux and dual-boot your machine. We recommend Ubuntu Desktop. Often, it is straightforward to set up for dual-boot—but 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, 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., 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:

  1. drawing an image sprite
  2. make the image sprite move
  3. make the image sprite respond to keystrokes
  4. make it do something else

Use the documentation at

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


  • 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 image—e.g. "./sprite.png", not "/home/fredm/ps0/sprite.png".
  • 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:
  • 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:
There are six examples of academic misconduct, labeled (a) through (f). Other than (a), "Seeks to claim credit for the work or efforts of another without authorization or citation," which of these do you think would most apply to this class, and why? Write approx. 100 words.
Note: there is no single correct answer to this. I am looking for your opinion.

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 ps0-readme.txt.

6. Submit!

You will be submitting at least four files.

  1. Your SFML demo program, named main.cpp.
  2. Your sprite image file, named sprite.png. (If you made more than one sprite, you can name the others whatever you like.)
  3. Your screen grab showing your code running, named screenshot.png.
  4. Your completed ps0-readme.txt file.

The four files must be in a subdirectory named ps0. Then, cd to the directory containing the three files, and type the following:

  $ ls

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:


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:

Grading rubric

core implementation6full & 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)
screenshot2screenshot of just SFML window included
  -1 pt if it's a screen-grab of your entire monitor
tar.gz archive2all files packaged in .tar.gz file with correct directory structure
Edit - History - Print - Recent Changes - Search
Page last modified on August 31, 2016, at 03:10 AM