Here is the library I wrote with SFML:
#include <string>
#include "SFML/Graphics.hpp"
class Window
{
public:
sf::RenderWindow window;
sf::Event event;
Window(int width, int height, std::string title)
{
window.create(sf::VideoMode(width, height, 32), title);
}
void display()
{
window.display();
}
bool pollEvents()
{
while(window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
window.close();
return false;
}
else
return true;
}
}
void clear()
{
window.clear();
}
};
extern "C" Window* new_Window(int width, int height, char title[])
{
return new Window(width, height, title);
}
extern "C" void display_Window(Window* window)
{
window->display();
}
extern "C" void clear_Window(Window* window)
{
window->clear();
}
extern "C" bool pollEvents_Window(Window* window)
{
return window->pollEvents();
}
And here is the python wrapper:
from ctypes import *
windowLib = CDLL("./Window.so")
class Window(object):
def __init__(self, width, height, title):
self.obj = windowLib.new_Window(width, height, bytes(title, "ascii"))
def display(self):
windowLib.display_Window(self.obj)
def clear(self):
windowLib.clear_Window(self.obj)
def pollEvents(self):
return windowLib.pollEvents_Window(self.obj)
window = Window(800, 600, "Title")
windowIsOpen = True
while windowIsOpen:
windowIsOpen = window.pollEvents()
print(windowIsOpen)
window.clear()
window.display()
This python script works for opening the window, but the window closes shortly afterwords. The print function manages to print "1 1 1 0" before the window closes itself. I'm not sure what's causing my pollEvents function to return 0.