Skip to content

A cross platform helper library for ModernGL making window creation and resource loading simple

License

Notifications You must be signed in to change notification settings

alicja-januszkiewicz/moderngl-window

 
 

Repository files navigation

pypi rtd

moderngl-window

A cross platform helper library for ModernGL making window creation and resource loading simple. It can also be used with PyOpenGL for rendering with the programmable pipeline.

Please report bugs or post questions/feedback on github.

Features

  • Cross platform support. Tested on Windows 10, Linux and Mac OS X. This can save users a lot of time and is often more difficult than most people imagine it to be.
  • Easily create a window for ModernGL using pyglet, pygame, PySide2, GLFW, SDL2, PyQt5 or tkinter supporting a wide range of window, keyboard and mouse events. These events are unified into a single system so your project can work with any window.
  • Load 2D textures, texture arrays and cube maps using Pillow
  • Load shaders as single or multiple glsl files
  • Load objects/scenes from wavefront/obj, GLTF 2.0 or STL
  • Resource finder system supporting multiple resource directories
  • A highly plugable library supporting custom loaders, resource finders and windows.
  • Type hints everywhere making code completion and linting a breeze

We are not trying to force the user into using every aspect of this library. If you have an exiting project and just need texture loading you will be able to do this without unnecessary hurdles as long as you provide us your moderngl.Context.

Install

pip install moderngl-window

Supported Platforms

  • Windows
  • Linux
  • Mac OS X

Sample Usage

Simple example opening a window clearing every frame using red (color).

# test.py
import moderngl_window as mglw

class Test(mglw.WindowConfig):
    gl_version = (3, 3)

    def render(self, time, frametime):
        self.ctx.clear(1.0, 0.0, 0.0, 0.0)

mglw.run_window_config(Test)

Run the example with different window backends:

python test.py --window pyglet
python test.py --window pygame
python test.py --window glfw
python test.py --window sdl2
python test.py --window pyside2
python test.py --window pyqt5
python test.py --window tk

WindowConfig classes are the simplest way to get started without knowing a lot about this library. For more advanced usage see documentation or examples.

Setup from source

We assume the user knows how to handle vitrualenvs.

# Install the package in editable mode
$ pip install -e .

# Set up and dev requirements
pip install -r requirements.txt
pip install -r tests/requirements.txt

Running Tests

Tests are set up with tox running pytest with coverage and flake8.

pip install -r tests/requirements.txt
tox -e py35
tox -e py36
tox -e py37
tox -e py38
tox -e pep8

Building Docs

pip install -r docs/requirements.txt
python setup.py build_sphinx

Contributing

Contributions are welcome regardless of experience level. Don't hesitate submitting issues, opening partial or completed pull requests.

Plugins

We are interested in contributions providing new loaders, windows etc. For these to be included in this library we require them to work cross platforms (win10/linux/osx) and be fairly easy to set up.

If it requires more than manually downloading a pre-compiled dll (like SDL2, GLFW etc.) it would most likely not be included, but you are welcome to present your case if you still think it should be included.

If you create your own repo/package containing plugins for this library, please make an issue and we'll link back to it. Be sure to include what platforms are supported, install instructions, how you configure it in moderngl-window and of course a clear and concise description of what exactly your package provides.

Attributions

We can't build everything from scratch. We rely on certain packages and resources to make this project possible.

Windows

Loaders

Testing & Utility

Resources

Some History

The majority of the code in this library comes from demosys-py (somewhat modified). Because demosys-py is a framework we decided to split out a lot useful functionality into this library. Frameworks are a lot less appealing to users and it would be a shame to not make this more available to the ModernGL user base.

About

A cross platform helper library for ModernGL making window creation and resource loading simple

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.4%
  • GLSL 0.6%