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

Window resize is laggy and doesn't resize viewport #181

Open
gtimoshaz opened this issue Nov 3, 2023 · 1 comment
Open

Window resize is laggy and doesn't resize viewport #181

gtimoshaz opened this issue Nov 3, 2023 · 1 comment

Comments

@gtimoshaz
Copy link

gtimoshaz commented Nov 3, 2023

Probably a revival of this one, which seems to be closed as solved

The code below starts a window, and it works fine in 60+ FPS, but if I try to resize the window, everything lags and the viewport is not resized.

Screencast.from.04.11.2023.00.41.47.webm

I use Ubuntu 22.04.3 LTS, with proprietary nVidia drivers on X11. moderngl and moderngl-window are installed from pypi inside a clean conda environment.

Expected result:

The resize should be smooth, and the viewport should match the window

Actual result:

The resize is laggy and the viewport size doesn't follow the window size

Here is the output of the program at the start:

2023-11-04 00:41:39,876 - moderngl_window - INFO - Attempting to load window class: moderngl_window.context.pyglet.Window
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - Context Version:
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - ModernGL: 5.8.2
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - vendor: NVIDIA Corporation
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - renderer: NVIDIA GeForce MX130/PCIe/SSE2
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - version: 3.3.0 NVIDIA 535.129.03
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - platform: linux
2023-11-04 00:41:40,027 - moderngl_window.context.base.window - INFO - code: 330

Here is the code:

import moderngl
import moderngl_window as mglw
import numpy as np


fragment_shader = '''
#version 330

out vec4 color;
uniform float time;

void main() {
    color = vec4(gl_FragCoord.x / 4000.0, gl_FragCoord.y / 4000.0, sin(time) / 2 + 0.5, 1.0);
}
'''

vertex_shader = '''
#version 330

in vec2 vertex_xy;

void main() {
    gl_Position = vec4(vertex_xy, 0.0, 1.0);
}
'''


class App(mglw.WindowConfig):
    gl_version = (3, 3)
    resizable = True

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.prog = self.ctx.program(vertex_shader=vertex_shader, fragment_shader=fragment_shader)
        vertices = np.array([-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0], dtype='f4')

        self.vbo = self.ctx.buffer(vertices.astype('f4'))
        self.vao = self.ctx.vertex_array(self.prog, [
                (self.vbo, '2f', 'vertex_xy')
            ])

    def render(self, time, frametime):
        self.ctx.clear(time % 1.0, 1.0, 1.0)
        uniform = self.prog["time"]
        uniform.value = time
        self.vao.render(mode=moderngl.TRIANGLE_STRIP)


App.run()
@einarf
Copy link
Member

einarf commented Nov 10, 2023

Try adding aspect_ratio = None

class App(mglw.WindowConfig):
    gl_version = (3, 3)
    resizable = True
    aspect_ratio = None

By default we try to respect the aspect ratio for the initial resolution. Possibly there is a scissor box being set causing only a partial screen clear.

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

2 participants