Skip to content

Commit

Permalink
Merge pull request #188 from Tremeschin/master
Browse files Browse the repository at this point in the history
Implement size setter for Headless Window backend
  • Loading branch information
einarf authored Feb 25, 2024
2 parents 3e27b29 + 3137d17 commit 55ddedf
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions moderngl_window/context/headless/window.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import moderngl
from typing import Tuple

import moderngl
from moderngl_window.context.base import BaseWindow
from moderngl_window.context.headless.keys import Keys

Expand Down Expand Up @@ -41,11 +42,39 @@ def init_mgl_context(self) -> None:
require=self.gl_version_code,
)

self._create_fbo()
self.use()

def _create_fbo(self):
if self._fbo:
for attachment in self._fbo.color_attachments:
attachment.release()
if self._fbo.depth_attachment:
self._fbo.depth_attachment.release()
self._fbo.release()

self._fbo = self.ctx.framebuffer(
color_attachments=self.ctx.texture(self.size, 4, samples=self._samples),
depth_attachment=self.ctx.depth_texture(self.size, samples=self._samples),
)
self.use()

@property
def size(self) -> Tuple[int, int]:
"""Tuple[int, int]: current window size.
This property also support assignment::
# Resize the window to 1000 x 1000
window.size = 1000, 1000
"""
return self._width, self._height

@size.setter
def size(self, value: Tuple[int, int]):
if value == (self._width, self._height):
return
self._width, self._height = value
self._create_fbo()

def use(self):
"""Bind the window's framebuffer"""
Expand Down

0 comments on commit 55ddedf

Please sign in to comment.