CSCI 261 - Programming ConceptsFall 2018 - Lab 7C - SFML DrawingQuick Links: Canvas | Mines | Piazza | zyBooks |
|
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |
This lab is due by Thursday, November 15, 2018, 11:59 PM. ConceptsFor 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 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.0 documentation.
Setup
First, take a look at the
main.cpp
file provided in the provided SFML template.
Be sure to start with the template as it will automatically link against the SFML
library for you. This template has been tested to work on the lab machines. If you want
to set up your own personal machine, YMMV (your mileage may vary).Windows Users: If your version of MinGW matches the lab machines that SFML was compiled for, it may work out of the box. If it doesn't work, some users have reported using this version of MinGW. Unzip it anywhere on your computer (I like C:\) and then launch CLion; go into Settings... from the File menu and find Toolchains under Build, Execution, and Deployment in the left-hand pane. In the right hand pane, use the drop down to choose the MinGW directory you just created. The project should then work correctly. Mac High Sierra Users: Download the MacOS Project file. Mac Mojave Users: Download the MacOS Mojave Project file. Linux Users: You can likely install SFML from your corresponding package manager or need to build from source. InstructionsIn 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 star and color it yellow
CircleShape star; star.setPosition( 15, 15 ); star.setRadius( 300 ); star.setFillColor( Color::Yellow ); window.draw( star ); // Draw a rectangle object called rect and color it blue RectangleShape rect; rect.setSize( Vector2f( 45, 150 ) ); rect.setPosition( 200, 150 ); rect.setFillColor( Color(0, 0, 255) ); window.draw( rect ); // Draw a text object called label Font myFont; if( !myFont.loadFromFile( "data/arial.ttf" ) ) return -1; 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 CreditYou can earn 2 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 that are executed on a given
loop. Try it!
Remember your smiley face solution for Assignment
1? You've sure come a long way since then!
Lab SubmissionYou will submit your solution to this lab with the rest of Set7. Detailed instructions for doing this are posted in Assignment 7. This lab is due by Thursday, November 15, 2018, 11:59 PM. | |
Last Updated: 11/02/18 19:40
|