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

How to customize context creation? #185

Open
szabolcsdombi opened this issue Jan 22, 2024 · 3 comments
Open

How to customize context creation? #185

szabolcsdombi opened this issue Jan 22, 2024 · 3 comments
Milestone

Comments

@szabolcsdombi
Copy link
Member

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
Copy link

compik710 commented Jan 22, 2024

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
Copy link
Member

einarf commented Feb 4, 2024

Taking any ideas for making this less hacky.

@einarf
Copy link
Member

einarf commented Nov 29, 2024

Monkey-patching the BaseWindow.init_mgl_context() definitely seems to be the laziest solution here.

Will keep this open in case better ideas turn up.

@einarf einarf added this to the Future milestone Nov 29, 2024
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

3 participants