Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyOpenGL / PySDL ? #210

Open
stuaxo opened this issue Dec 10, 2017 · 2 comments
Open

PyOpenGL / PySDL ? #210

stuaxo opened this issue Dec 10, 2017 · 2 comments

Comments

@stuaxo
Copy link

stuaxo commented Dec 10, 2017

There are many emscripten apps that provide SDL (I guess it hooks into WebGL to provide OpenGL ES) ?

Would it be possible to provide pyopengl or PySDL ?

PypyJS looks like it would be fantastic for getting graphical python on the web.

@Fartuess
Copy link

Fartuess commented Jun 9, 2018

For the starters - i just found out about this project 10 minutes ago, but i was interested in the topic for some time so i will try to share some knowledge i collected so far.

  1. PyOpenGL is CPython extension and this Python interpreter is PyPy. But from what i know you could just compile CPython for web using Emscripten and target Web Assembly (wasm) instead of Javascript while at it.

  2. You would have to compile PyOpenGL.pyd extension to wasm as well.

  3. From my experience PyOpenGL is piece of crap. It's poorly documented, often recommended ways of doing things just don't work and require more hassle than doing them in C++. Anything outside absolute basics of OpenGL becomes extremally tedious and it tends to collide with other OpenGL contexts if you mix it into some other application that uses OpenGL on it's own. I strongly discourage from using PyOpenGL.
    But there is alternative. You can write OpenGL part in C++ and expose it to Python via wrapper. I suggest using Pybind11 for that. It's better, slimer version of Boost Python and it's header only library which changes targeted CPython version just by linking against particular CPython headers and python.lib file. Already used it for OpenGL with great success twice and one of them was for work and other one was personal project that i already worked on for some years back then. No problems encountered whatsoever.
    So recommended path for OpenGL in Python works like that:
    OpenGL/C++ + Pybind11 = OpenGL in Python.

So the path i would go would be:

  1. Compile CPython to Web Assembly using Emscripten.
  2. Write OpenGL part in C++.
  3. Write Pybind11 bindings, link against your compiled CPython/wasm header and built lib. Compile with Emscripten.
  4. Write your Python code.
  5. Deploy it as web page together.
  6. Tell me if it worked ;).

Overall it is the topic i will try to approach in upcoming month. Currently i haven't even compiled OpenGL/C++ with Emscripten yet, only Hello World example, but i know that it requires a bit of changes in the code.

@stuaxo
Copy link
Author

stuaxo commented Jun 10, 2018

I wonder if PySDL (or whichever the python SDL binding that works in pypy best is) would be the easiest place to start, since people have already done SDL in wasm ?

https://github.com/timhutton/sdl-canvas-wasm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants