CSCI 261 - Programming Concepts (C++)

Spring 2018 - Lab 6B

Quick Links: Canvas | CS @ Mines | Cloud9 | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |
This lab is due by Thursday, April 5, 2018 11:59 PM .

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 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 documentation.


Open and Run the Project



When you run your project, be sure to select " C++ (Makefile) " as your run option. Once you have the following two pieces in your program:

RenderWindow window( VideoMode( 640, 480 ), "SFML Window" );
window.display();

run it. You WILL get an error message that says

bash: line 12: 646995 Segmentation fault $file.o $args

THIS IS OK! We can safely ignore that message. Why? Well, Cloud9 is trying to run your program in the tab you have open right now. But SFML wants to open a new window to display the graphics. Cloud9 cannot open a second window on its own. But you can! Part of the magic setup process that you did at the beginning added another runner to your Cloud9 workspace. Go to " Run > Run With > C9vnc ". This will pop open a little window in your workspace with information that looks like the following:

Your GUI is running at https://class-examples-jpaone.c9users.io/vnc.html.
VNC client running at https://class-examples-jpaone.c9users.io/vnc.html
2017-03-20 02:30:40,315 INFO supervisord started with pid 635120
2017-03-20 02:30:41,318 INFO spawned: 'novnc' with pid 635125
2017-03-20 02:30:41,320 INFO spawned: 'xvfb' with pid 635126
2017-03-20 02:30:41,322 INFO spawned: 'x11vnc' with pid 635127
2017-03-20 02:30:41,325 INFO spawned: 'fluxbox' with pid 635128
2017-03-20 02:30:42,417 INFO success: novnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2017-03-20 02:30:42,419 INFO success: xvfb entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2017-03-20 02:30:42,419 INFO success: x11vnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2017-03-20 02:30:42,420 INFO success: fluxbox entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

That first line is the most important one. It is telling you that your GUI is running at another website. Open that URL in a new tab. You will see a window like below:

C9vnc

Right click on the background and select "Applications > Shells > Bash".

C9vnc

This will open a terminal window just like in the Cloud9 environment. We will enter all of our commands here to run our program.

C9vnc

Remember all those commands you were copying in before? Well, they are Linux commands (congrats! you've been working with Linux this whole time). What you need to do is to change your directory (folder) to where your Lab6B is. If you have been following our naming scheme, then Lab6B should be located inside of a folder called Set6. You can change to this folder by typing

cd Set6/L6B

If you type the command " ls " you should see a list of all the files. One of them will colored green with a * next to it. This should be a.out , the executable for your program! You can run your program by typing the following command:

./a.out

You might see a message that says "Failed to use XRandR extension". Once again, it's ok. Ignore it. More importantly, you should now see a new window that has popped up containing your SFML program! How cool!


Instructions



First, take a look at the main.cpp file provided in the SFML template. 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 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.setColor( 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 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!


Lab Submission



You will submit your solution to this lab with the rest of Set6. Detailed instructions for doing this are posted in Assignment 6.

Remember your smiley face solution for Assignment 1? You've sure come a long way since then! Do you recall how we had a prize for the best smiley face submitted in all sections (a Free HW)? That was cool. Let's do this again for Lab6b. That is, we'll have a prize for the best Lab6b submitted in all sections. Good luck!
This lab is due by Thursday, April 5, 2018 11:59 PM .
Last Updated: 02/15/18 13:22


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0