#include #include using namespace std; #include using namespace sf; int main() { // creates the window object with an 640x640 resolution window RenderWindow window(VideoMode(640, 640, 32), "SFML Example"); // Draw loop: Each iteration of this loop draws a single frame while (window.isOpen()) { // Erase the screen with black (because space) window.clear( Color::Red ); /***** PLACE YOUR FILE PROCESSING CODE HERE, AND ADD DRAW CALLS *****/ // 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 2nd rectangle object called rect2 and color it blue RectangleShape rect2; rect2.setSize( Vector2f( 45, 150) ); rect2.setPosition( 400, 150 ); rect2.setFillColor( Color(0, 0, 255) ); window.draw(rect2); // Draw a smile for( float i = 0; i <= 3.14; i += 3.14/512.0f ) { ConvexShape convexShape( 4 ); convexShape.setPoint( 0, Vector2f( cos( i )*150+320, sin(i)*150+320 ) ); convexShape.setPoint( 1, Vector2f( cos( i )*150+320+15, sin(i)*150+320 ) ); convexShape.setPoint( 2, Vector2f( cos( i )*150+320+15, sin(i)*150+320+15 ) ); convexShape.setPoint( 3, Vector2f( cos( i )*150+320, sin(i)*150+320+15 ) ); convexShape.setFillColor( Color( 0, 128, 0 ) ); window.draw( convexShape ); } // 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 ); /***** END OF FILE PROCESSING AND DRAWING *****/ // Apply all the draws to the screen window.display(); // Check for any events Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) { window.close(); } else if( event.type == Event::KeyPressed ) { if( Keyboard::isKeyPressed( Keyboard::Q ) ) { window.close(); } } else if( event.type == Event::MouseButtonPressed ) { if( Mouse::isButtonPressed( Mouse::Left ) ) { Vector2i mousePos = Mouse::getPosition( window ); cout << "Mouse was clicked at position: " << mousePos.x << ", " << mousePos.y << endl; } } } } return EXIT_SUCCESS; }