Skip to content

Instantly share code, notes, and snippets.

@mantognini
Created September 4, 2011 16:19
Show Gist options
  • Save mantognini/1193095 to your computer and use it in GitHub Desktop.
Save mantognini/1193095 to your computer and use it in GitHub Desktop.
SFML test sf::Window::Create
//#define CREATE // vs new/delete
//#define SHAPE // vs sprite+texture
// Create VERSION :
#ifdef CREATE
#include <SFML/Graphics.hpp>
int main (int argc, const char * argv[])
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
#ifdef SHAPE
sf::Shape s = sf::Shape::Rectangle(0, 0, 100, 100, sf::Color::Blue);
#else
sf::Image img; img.Create(100, 100, sf::Color::Blue);
sf::Texture t; t.LoadFromImage(img);
sf::Sprite s(t);
#endif
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.Type == sf::Event::KeyPressed)
if (event.Key.Code == sf::Keyboard::Escape)
window.Close();
else
window.Create(sf::VideoMode(800, 600), "SFML window");
}
// Clear screen
window.Clear();
s.Rotate(30.0);
window.Draw(s);
// Update the window
window.Display();
}
return EXIT_SUCCESS;
}
#else
// new/delete VERSION :
#include <SFML/Graphics.hpp>
int main (int argc, const char * argv[])
{
// Create the main window
sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML window");
#ifdef SHAPE
sf::Shape s = sf::Shape::Rectangle(0, 0, 100, 100, sf::Color::Blue);
#else
sf::Image img; img.Create(100, 100, sf::Color::Blue);
sf::Texture t; t.LoadFromImage(img);
sf::Sprite s(t);
#endif
// Start the game loop
while (window->IsOpened())
{
// Process events
sf::Event event;
while (window->PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window->Close();
if (event.Type == sf::Event::KeyPressed)
if (event.Key.Code == sf::Keyboard::Escape)
window->Close();
else {
delete window;
window = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML window");
}
}
// Clear screen
window->Clear();
s.Rotate(30.0);
window->Draw(s);
// Update the window
window->Display();
}
delete window;
return EXIT_SUCCESS;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment