moderngl / moderngl-window

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

Cannot create fullscreen window programatically #74

Closed vuki closed 4 years ago

vuki commented 4 years ago

I don't know if it's intentional, but it's not possible to create a fullscreen window without using command line options. I thought that defining fullscreen = True in the class would create a fullscreen window, but that's not the case. Here is what happens.

  1. I define a class with fullscreen = True attribute and I call run() of this class.
  2. run() calls moderngl_window.run_window_config(cls) where cls.fullscreen = True.
  3. run_window_config calls window_cls with fullscreen=values.fullscreen where values are parsed from the command line and the default value of fullscreen is False. config_cls.fullscreen is completely ignored.

Changing the line 179 in __init__.py to fullscreen=config_cls.fullscreen or values.fullscreen, solves this problem.

Also, I think that this code in context/pyglet\window.py is incorrect:

        if self.fullscreen:
            display = pyglet.canvas.get_display()
            screen = display.get_default_screen()
            self._width, self._height = screen.width, screen.height

        self._window = PygletWrapper(
            width=self.width, height=self.height,
            caption=self.title,
            resizable=self.resizable,
            vsync=self.vsync,
            fullscreen=self.fullscreen,
            config=config,
        )

First, screen size is written to _self._width, self._height (underscore), then values self.width, self.height (no underscore) are used, discarding the previously calculated values.

einarf commented 4 years ago

That looks like a silly oversight. I was planning to do a release today, so this should be quick to fix.

EDIT: .. and thanks a lot for reporting this

einarf commented 4 years ago

WindowConfig is really only supposed to be used for very simple things. You can create your own window, rendering loop, callback function etc if you neeed more control.

Looks like there is no way for WindowConfig to do fullscreen, but I see no harm in adding this

einarf commented 4 years ago

self._width and self.width is really the same thing. The latter is just a property method returning self._width. I changed it to use the interal properties so it looks less confusing.

einarf commented 4 years ago

New version out : https://pypi.org/project/moderngl-window/2.1.1/