This lab is due by Tuesday, December 06, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
Concepts
For this assignment, you have the opportunity to play with the power that SFML (a special framework called Simple and Fast Multimedia Library) offers.
SFML
SFML is a multimedia Application Programming Interface (API) written in C++ with bindings for various programming languages, including Java, Python, and Ruby. SFML provides an easy way to write code that utilizes graphics, sound effects, and/or networking. SFML is the chosen platform for many cool games, including the Atom Zombie Smasher. You can check out everything SFML has to offer by reading the SFML 2.5.1 documentation.
Setup
The first step is to download the source code from SFML from the SFML Download Page. Be sure to download the zip for the Source Code and not an OS specific package. This is at the bottom of the page. Once downloaded, unzip the package.
Next, download the cross-platform Makefile package. Once
downloaded, unzip the package and place the contents inside the SFML-2.5.1 folder from the above step alongside the readme.md
file.
Now in a terminal, navigate into the SFML-2.5.1 folder and type make
.
- Note 1: If you are running OS X, you will initially be prompted to enter your user password to allow the OS to unquarantine the SFML files.
- Note 2: If you are building on the lab machines, you will need to modify the
Makefile.win
file. Open this file in a text editor and set theCXX
variable to be the full absolute path ofC:/mingw-w64/mingw64/bin/g++.exe
. The lab machines have multiple versions ofg++
and we need to be explicit for which one it should use.
This Makefile will build each of the necessary libraries. If you receive errors during this step, please post to the corresponding post on Piazza matching your operating system. YMMV in this process but we are here to help!
Once successfully built, you'll now need to copy the library files to your installation. First, you'll need to copy the include headers that declare all the classes within the library. Next, you'll need to copy the precompiled library files. Finally, you'll need to copy the runtime files. Where each of these go will depend on operating system:
- Windows Personal Machine:
- Find your MinGW installation folder (likely
C:/mingw64
or similar). Copy the entireSFML
folder from~/SFML-2.5.1/include
to the~/mingw64/x86_64-w64-mingw32/include
folder contained within the MinGW folder (if thex86_64-w64-mingw32
folder does not exist, then place theSFML
folder inside of theinclude
folder in~/mingw64/include
. - Find your MinGW installation folder (likely
C:/mingw64
or similar). Copy the fivelibsfml-*.a
files from~/SFML-2.5.1/build/libs
to the~/mingw64/lib
folder contained within the MinGW folder. - Find your MinGW installation folder (likely
C:/mingw64
or similar). Copy the fivesfml-*.dll
files from~/SFML-2.5.1/build/libs
to the~/mingw64/bin
folder contained within the MinGW folder so they reside alongside theg++
program.
- Find your MinGW installation folder (likely
- Windows Lab Machine:
- On your Z: drive, create the following folder path:
Z:/CSCI200/include
. Copy the entireSFML
folder from~/SFML-2.5.1/include
to this folder. - On your Z: drive, create the following folder path:
Z:/CSCI200/lib
. Copy the fivelibsfml-*.a
files from~/SFML-2.5.1/build/libs
to this folder. - Here is where things are slightly less ideal. Due to the network accounts, there is not a standard folder that persists on your path
that you can write files to. Therefore, on your Z: drive, create the following folder path:
Z:/CSCI200/bin
. Copy the fivesfml-*.dll
files from~/SFML-2.5.1/build/libs
to this folder. Whenever you are working with an SFML project, you will need to copy these five DLL files into the folder where your executable exists so they can be found at runtime.
- On your Z: drive, create the following folder path:
- OS X Personal Machine:
- Copy the entire
SFML
folder from~/SFML-2.5.1/include
to/usr/local/include
. This can be done through the Finder selecting Go > Go To Folder and entering/usr/local
. If theinclude
folder does not exist, then create it. - Copy the five
*.dylib
files from~/SFML-2.5.1/build/libs
to/usr/local/lib
. Again, if this folder does not exist, then create it. - Copy the seven
*.framework
folders from~/SFML-2.5.1/extlibs/libs-osx/Frameworks
to/Library/Frameworks
. Again, this can be done through the Finder selecting Go > Go To Folder and entering/Library/Frameworks
.
- Copy the entire
Instructions
Download the SFML Template. This
will create an empty window to start working with.
First, take a look at the main.cpp
file provided. In class, we discussed each of the
commands shown (e.g., creation of the window object and the polling for events); ask questions if there is any confusion.
Second, we also saw the development of a smiley face in class today. A few key lines of code covered follow:
// Draw a circle object called face and color it yellow
CircleShape face;
face.setPosition( 15, 15 );
face.setRadius( 300 );
face.setFillColor( Color::Yellow );
window.draw( face );
// Draw a rectangle object called eye and color it blue
RectangleShape eye;
eye.setSize( Vector2f( 45, 150 ) );
eye.setPosition( 200, 150 );
eye.setFillColor( Color(0, 0, 255));
window.draw( eye );
// Draw a text object called label
// place in file loading section
Font myFont;
if( !myFont.loadFromFile( "data/arial.ttf" ) )
return -1;
// place in drawing section
Text label;
label.setFont( myFont );
label.setString( "Hello World!" );
label.setPosition( 250, 520 );
label.setFillColor( Color::Black );
window.draw( label );
Your job is to draw something in SFML. What you draw can be anything you want EXCEPT a smiley face (e.g., a tree, a bike, a dog, a word using rectangles/circles, etc.). For full credit, you must draw at least five shapes. Be creative and have fun!
Possible Extra Credit
You can earn 3 points of extra credit if the item you draw actually moves (yes, is animated - awesome!). Animation in SFML is actually easier than you might think. As you know, you add all your draw commands in the window loop:
while (window.isOpen()) {
// ADD SEVERAL DRAW COMMANDS HERE
// Apply all the draws to the screen
window.display();
}
To create an animation, you only need to change the draw commands a small amount based on a variable. Try it!
Lab Submission
Submit your main.cpp, Makefile, data/*
file(s).
You will submit your solution to this lab with the rest of Set6. Detailed instructions for doing this are posted in Assignment 6.
This lab is due by Tuesday, December 06, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.