Using GLFW in a Python Project with Pybind11

Hey all!

Over the past years whenever I’ve had spare time (which is almost never), I’ve worked on a cute little data vizualization project as an installable python package. It leverages Imgui with GLFW and OpenGL.

There’s a really simple high level plotting SDK that’s exposed to Python devs who install it. Supports a 2D (orthographic projection) and 3D (perspective) viewport, with simple mouse controls, rotation, panning, zooming, etc…

It also supports animated time steps if you have track data (like GPS, AIS, or flight radar data).

What might be useful to others is having the example of building a Python project that includes the raw C code for GLFW as an “extern” and binding into it with Pybind11. It took me quite a bit to get the whole thing to compile on both OSX and Linux, but it was a success.

No need for cmake or anything like that.

You can pip install zenith-viz, or clone the repository and run pip install .

All of the deps such as imgui, glm, glfw itself, and glad are submoduled or included as externs – so when you build the project all you really need is clang or g++ installed on your machine.

Haven’t tried windows yet, since most windows machines don’t have a C++ compiler installed, but I will probably just build the win32 binary in github actions.

Mac and Linux will remain a “source” distribution python package, and Windows can be a binary dist.

Anyway, hope ya’ll like it. Love GLFW btw. <3