moderngl / moderngl-window

A cross platform utility library for ModernGL making window creation and resource loading simple
MIT License
245 stars 59 forks source link

How to customize context creation? #185

Open szabolcsdombi opened 10 months ago

szabolcsdombi commented 10 months ago

I would like to customize context creation for moderngl.

The current workaround is to hack on the create context function.

import moderngl_window as mglw
import moderngl

moderngl.create_context = ...
mglw.BaseWindow.init_mgl_context = ...

Is there any way to customize context creation from a WindowConfig?


class Example(mglw.WindowConfig):
    gl_version = (3, 3)
    title = "ModernGL Example"
    window_size = (1280, 720)
    aspect_ratio = 16 / 9
    resizable = True

    resource_dir = os.path.normpath(os.path.join(__file__, '../data'))

    # something like:
    def init_mgl_context(self): ... # or similar
compik710 commented 10 months ago

Hello! All WindowConfig methods are described here: https://moderngl-window.readthedocs.io/en/latest/reference/context/windowconfig.html

init_mgl_context() is available in BaseWindow and other window configurations: https://moderngl-window.readthedocs.io/en/latest/reference/context/basewindow.html

Next to each method there is a [source] button, which allows you to view an example of creating a similar method.

einarf commented 9 months ago

Taking any ideas for making this less hacky.