This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/System.hpp> | |
#include <iostream> | |
int main() | |
{ | |
int i = 0; | |
sf::Thread thread([](int *j) { ++*j; }, &i); | |
thread.launch(); | |
std::cout << i; // This output is a race condition; it's either 0 or 1 depending on how fast the extra thread is executed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics/Transform.hpp> | |
#include <SFML/System/Vector2.hpp> | |
#include <iostream> | |
int main() { | |
// First we'll need a vector to tranform | |
sf::Vector2f myVector(2, 0); | |
std::cout << "myVector: " << myVector.x << ", " << myVector.y << "\n"; | |
// Then the actual transform |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
int main() { | |
sf::RenderWindow window(sf::VideoMode(800, 600), "Tetrominos"); | |
// The quads approach is easiest to understand | |
// (Note this is not supported on mobile targets and you'd have to define triangles instead) | |
sf::VertexArray quads(sf::Quads); | |
// Left piece |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
int main(int argc, char **argv) { | |
sf::RenderWindow window(sf::VideoMode(800, 600), "Circle Text", sf::Style::Default); | |
window.setVerticalSyncEnabled(true); | |
sf::Font font; | |
font.loadFromFile("arial.ttf"); | |
sf::Text text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut ultrices ante. Aliquam ornare eu enim eget accumsan.", font); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <functional> | |
#include <string> | |
// Definee an `Observable` class. | |
// This works as a wrapper around a variable of any type. | |
// Once it's assigned a new value, a predefined callback is defined to react on this. | |
template<typename T> | |
class Observable { | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
* Load a font, if you don't have one yet | |
* Create the `FpsMeter` object | |
* Optional: Set a position | |
* Draw the meter | |
sf::Font font; | |
font.loadFromFile("myfont.ttf"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string getSelf() | |
{ | |
char buf[1024] = { 0 }; | |
#ifdef WIN32 | |
DWORD ret = GetModuleFileNameA(NULL, buf, sizeof(buf)); | |
if (ret && ret != sizeof(buf)) { | |
std::string res(buf); | |
for (auto &c : res) | |
if (c == '\\') | |
c = '/'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <sstream> | |
class RenderWindowStats : public sf::RenderWindow { | |
public: | |
RenderWindowStats() : RenderWindow({640, 480}, "Test") { | |
} | |
void draw(sf::Drawable &dr, sf::RenderStates states = sf::RenderStates()) { | |
++mDrawCallsTemp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <sstream> | |
#include <iomanip> | |
int main(int argc, char **argv) { | |
sf::RenderWindow window(sf::VideoMode(300, 100), "Timer Test", sf::Style::Default); | |
window.setVerticalSyncEnabled(true); | |
sf::Font font; | |
font.loadFromFile("Arial.ttf"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file conext.h | |
* @author Mario Liebisch <[email protected]> | |
* @section LICENSE | |
* | |
* © 2011 All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are met: | |
* |