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

moderngl on Jupyter Notebook or Google Colab #378

Closed
AK82 opened this issue Jan 27, 2020 · 4 comments
Closed

moderngl on Jupyter Notebook or Google Colab #378

AK82 opened this issue Jan 27, 2020 · 4 comments
Labels

Comments

@AK82
Copy link

AK82 commented Jan 27, 2020

Hi
Is moderngl working on Jupyter Notebook or Google Colab, and if so can you please post an example?
Thank you.

@einarf
Copy link
Member

einarf commented Jan 28, 2020

Personally I have very little knowledge about Jupyter Notebook or Google Colab, so I woudn't be able to give a concrete answer. Maybe someone else here knows?

@stuaxo
Copy link
Contributor

stuaxo commented Feb 10, 2020

The easiest way to get an image to appear as Jupyter cell output is by encoding it as a PNG, and passing that data to it's Image class.

# < insert code to get png data from ModernGL here. >
display(Image(data=png_data))

You can register data types so this happens automatically.

You could register types for moderngl.Texture and whatever else it makes sense to see in the cell.

There is some work to package this all up as an extension, this would probably be a seperate project - e.g moderngl-jupyter.

VisPy have (or had?) GL rendering in Notebooks a while ago, via their Gloo library, so if you need it now that may be an option for you.

Here's a Jupyter extension I made for cairo to display cairo Surfaces and Contexts, I lean heavily on the PngFormatter so I can just pass through png data to make this work.
https://github.com/stuaxo/cairo-jupyter/blob/master/extension/cairo_jupyter/__init__.py#L46

There is info on writing Jupyter extensions here.
https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html

@einarf
Copy link
Member

einarf commented Feb 25, 2020

Thank you @stuaxo for answering the question. I'll close this for now. The issue still be useful in search results in the future.

@einarf einarf closed this as completed Feb 25, 2020
@stuaxo
Copy link
Contributor

stuaxo commented Feb 25, 2020

I'll also point to Vispys GLIR spec. Which encodes a subset of opengl over the wire, which they use to for webgl targets.

If somebody liked moderngl syntax a lot more than Gloos they could target GLIR with a moderngl - like API.
http://api.vispy.org/en/latest/gloo.glir.html

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

No branches or pull requests

3 participants