This lab is due by Thursday, April 21, 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 lab, 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 C++, Java, Python, and Ruby). SFML provides an easy way to write code that requires graphics and/or sound effects. 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
Follow the instructions based on where you plan to work and the corresponding operating system:
Campus Windows Lab Machines
The SFML library has been pre-built in the lab environment. Download the bundle here. Extract the zip file.
include
Copy the contents of include/
to Z:\CSCI261\include\
.
lib
Copy the contents of lib/
to Z:\CSCI261\lib\
.
bin
Copy the contents of bin/
to Z:\CSCI261\bin\
.
You'll now need to edit the environment variables for your account. Edit the Path
and add Z:\CSCI261\bin\
. Unfortunately, when you log off the lab machines
this setting is lost and must be repeated everything you login to work on an SFML project.
Test Your Setup
Test your installation with the Hello SFML World starter code. Use the included Makefile to build SFML.
Windows Users
We'll walk through the ideal scenario first. Personal Windows machines will have the most variation. Begin by checking what version of MinGW you are running. Open a terminal and type:
g++ --version
Download the corresponding bundle that matches your version:
Extract the contents and copy the contents to the corresponding locations. There are a few potential places these files may go, so we'll first try the ideal.
include/
- copy the contents to your mingw64/include folder.lib/
- copy the contents to your mingw64/lib folder.bin/
- copy the contents to your mingw64/bin folder.
If when testing, it's not finding the files in those locations then repeat that process copying them to the respective mingw64/x86_64-w64-mingw32/.
folder.
Test Your Setup
Test your installation with the Hello SFML World starter code. Use the included Makefile to build SFML.
OSX Users
Begin by downloading the macOS bundle from the SFML Downloads page. Extract the zipped file. We will need to copy some of the contents to various places. With the exception of the last steps, these can be done via the terminal or the Finder application. We are largely following the SFML OS X Tutorial, skipping the final XCode step.
includes
We will place the include headers in the folder /usr/local/include
. If this location does not exist yet on your device, then you will need to make the folders to do so.
/usr
will exist as a system folder. If you attempt to make the local and then include folders, you will be prompted for your password through the Finder. If you choose
to make them through the terminal, then you will need to use sudo
to gain temporary privilege elevation. The terminal command to do so is sudo mkdir /usr/local
and then /usr/local/include
.
Once /usr/local/include
exists, copy the entire contents of SFML-2.5.1-macos-clang/include
. There should now be an SFML
folder
inside /usr/local/include
.
libs
The lib files will go alongside the headers in the folder /usr/local/lib
. As with the headers, ensure this location exists.
Once /usr/local/lib
exists, copy the entire contents of SFML-2.5.1-macos-clang/lib
.
Since the libs contain runnable code, OS X by default quarantines these files as potentially dangerous and doesn't allow them to be run. We need to unquarantine them.
In a terminal, navigate to /usr/local/lib
. You can view the file attributes by typing ls -laFh@
. You will see each file with a
com.apple.quarantine
value. Remove this attribute via the following command: sudo xattr -d com.apple.quarantine libsfml*
. If you view the
file attributes again using ls -laFh@
the quarantine flag will be removed.
Extra libs
SFML requires a few additional dependencies that come with the bundle. Copy the contents of SFML-2.5.1-macos-clang/extlibs
to /Library/Frameworks
.
The Frameworks are also runnable code and therefore quarantined. We need to unquarantine them as well.
In a terminal, navigate to /Library/Frameworks
. Since the Frameworks involve a folder structure, there are several commands we need to run:
sudo xattr -d com.apple.quarantine *.framework
sudo xattr -d com.apple.quarantine *.framework/*
sudo xattr -d com.apple.quarantine *.framework/*/*
sudo xattr -d com.apple.quarantine *.framework/*/*/*
sudo xattr -d com.apple.quarantine *.framework/*/*/*/*
Some of those commands will result in a message stating xattr: [..]]: No such xattr: com.apple.quarantine
or xattr: [Errno 1] Operation not permitted: 'iTunesLibrary.framework'
,
both of these are ok and can be safely ignored.
Test Your Setup
Test your installation with the Hello SFML World starter code. Use this Makefile to build SFML. Once downloaded, open the file and view the following lines:
# For OS X using an Intel chip, use the following line
#CXX_FLAGS =
# For OS X using an M1 chip, use the following line
#CXX_FLAGS = -arch x86_64
Uncomment the appropriate CXX_FLAGS
line by removing the leading #
.
Hello SFML World!
Below is a starter template to test the installation of SFML.
#include <SFML/Graphics.hpp>
using namespace sf;
int main() {
// create a window
RenderWindow window( VideoMode(640, 640), "SFML Test" );
/////////////////////////////////////
// BEGIN ANY FILE LOADING
// perform any file processing once before draw loop begins
// END ANY FILE LOADING
/////////////////////////////////////
// create an event object once to store future events
Event event;
// while the window is open
while( window.isOpen() ) {
// clear any existing contents
window.clear();
/////////////////////////////////////
// BEGIN DRAWING HERE
// place any draw commands here to display in the window
// END DRAWING HERE
/////////////////////////////////////
// display the current contents of the window
window.display();
/////////////////////////////////////
// BEGIN EVENT HANDLING HERE
// check if any events happened since the last time checked
while( window.pollEvent(event) ) {
// if event type corresponds to pressing window X
if(event.type == Event::Closed) {
// tell the window to close
window.close();
}
// check addition event types to handle additional events
}
// END EVENT HANDLING HERE
/////////////////////////////////////
}
return 0;
}
When the above program displays a black window that you can close, SFML is setup correctly. For assistance with any of the above steps, respond to the appropriate OS post pinned on Piazza.
There is no file to submit for this lab. Complete the installation survey through Canvas to report your progress.
Lab Submission
Submit your [none, see above]
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 Thursday, April 21, 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.