diff --git a/Makefile b/Makefile index 8342f65..4df0457 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ CXX := $(PREFIX)-g++ LD := $(PREFIX)-ld CPPFLAGS := -I$(SFML_DIR)/include CXXFLAGS := -mwindows -LDFLAGS := -L$(SFML_DIR)/lib -lsfml-system -lsfml-window -lopengl32 -lglu32 -static-libstdc++ -static-libgcc -mwindows +LDFLAGS := -L$(SFML_DIR)/lib -lsfml-system -lsfml-window -lsfml-graphics -lopengl32 -lglu32 -static-libstdc++ -static-libgcc -mwindows -all: clock window events opengl dlls +all: clock window events opengl graphics dlls %: %.cpp $(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $^ $(LDFLAGS) diff --git a/graphics.cpp b/graphics.cpp new file mode 100644 index 0000000..0eb0809 --- /dev/null +++ b/graphics.cpp @@ -0,0 +1,68 @@ + +#include +#include +#include +#include + +sf::Shape build_ngon(int n, float radius) +{ + sf::Shape s; + for (int i = 0; i < n; i++) + { + float angle = i * 2.0 * M_PI / n; + float x = radius * cos(angle); + float y = radius * sin(angle); + s.AddPoint(x, y, sf::Color(255, 128, 0), sf::Color(0, 0, 100)); + } + s.SetColor(sf::Color(255, 255, 255, 255)); + s.SetOutlineWidth(4); + return s; +} + +int main() +{ + sf::Clock Clock; + sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics"); +// App.UseVerticalSync(true); +// App.SetActive(); + std::list shapes; + + for (int n = 3, x = 0; x < 4; x++) + { + for (int y = 0; y < 3; y++, n++) + { + sf::Shape s = build_ngon(n, 75); + s.Move(200 * x + 100, 200 * y + 100); + shapes.push_back(s); + } + } + + while (App.IsOpened()) + { + sf::Event Event; + while (App.GetEvent(Event)) + { + if (Event.Type == sf::Event::Closed) + App.Close(); + + if ( (Event.Type == sf::Event::KeyPressed) + && (Event.Key.Code == sf::Key::Escape) ) + App.Close(); + } + + App.Clear(sf::Color(0, 0, 0)); + + for (std::list::iterator it = shapes.begin(); + it != shapes.end(); + it++) + { + it->Rotate(1000 * Clock.GetElapsedTime()); + App.Draw(*it); + } + + App.Display(); + Clock.Reset(); + } + + return EXIT_SUCCESS; +}