add graphics demo
This commit is contained in:
parent
aee1265ebd
commit
ce7a57be64
4
Makefile
4
Makefile
@ -7,9 +7,9 @@ CXX := $(PREFIX)-g++
|
|||||||
LD := $(PREFIX)-ld
|
LD := $(PREFIX)-ld
|
||||||
CPPFLAGS := -I$(SFML_DIR)/include
|
CPPFLAGS := -I$(SFML_DIR)/include
|
||||||
CXXFLAGS := -mwindows
|
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
|
%: %.cpp
|
||||||
$(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $^ $(LDFLAGS)
|
$(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $^ $(LDFLAGS)
|
||||||
|
68
graphics.cpp
Normal file
68
graphics.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <math.h>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
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<sf::Shape> 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<sf::Shape>::iterator it = shapes.begin();
|
||||||
|
it != shapes.end();
|
||||||
|
it++)
|
||||||
|
{
|
||||||
|
it->Rotate(1000 * Clock.GetElapsedTime());
|
||||||
|
App.Draw(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
App.Display();
|
||||||
|
Clock.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user