1
////////////////////////////////////////////////////////////////////////////////
3
// pySFML - Python bindings for SFML
4
// Copyright 2012-2013, Jonathan De Wachter <dewachter.jonathan@gmail.com>
6
// This software is released under the LGPLv3 license.
7
// You should have received a copy of the GNU Lesser General Public License
8
// along with this program. If not, see <http://www.gnu.org/licenses/>.
10
////////////////////////////////////////////////////////////////////////////////
12
// Including Python.h first is mandatory!
18
// Make sure to include the SFML headers before the pySFML ones
19
#include <SFML/Graphics.hpp>
20
#include <pysfml/graphics_api.h>
22
int main(int argc, char *argv[])
24
// Initialization (mandatory stuff)
25
Py_SetProgramName(argv[0]);
28
// Add the current path to sys.path to find our script
30
if (!getcwd(cwd, sizeof(cwd))) {
31
std::cout << "Couldn't get the current path" << std::endl;
32
return EXIT_FAILURE; }
33
PyObject *sys = PyImport_ImportModule("sys");
34
PyObject *path = PyObject_GetAttrString(sys, "path");
35
PyList_Append(path, PyString_FromString(cwd));
37
// Import our script that creates a texture
38
PyObject* script = PyImport_ImportModule("script");
42
// Retrieve the texture
43
PyTextureObject *texture;
44
texture = (PyTextureObject*)PyObject_GetAttrString(script, "texture");
46
// Create a window and display the texture for five seconds
47
sf::RenderWindow window(sf::VideoMode(640, 480), "pySFMl - Embedding Python");
50
window.draw(sf::Sprite(*texture->p_this));
53
sf::sleep(sf::seconds(5));
55
// Then, terminate properly...