def getGammaRamp(self): # get the current gamma ramp win = glfw.get_window_user_pointer(self.winHandle) # if not fullscreen, we get an access violation (bug?) if not win._isFullScr: return None monitor = glfw.get_window_monitor(self.winHandle) currentGammaRamp = glfw.get_gamma_ramp(monitor) return np.asarray(currentGammaRamp, dtype=np.float32)
def _toggle_fullscreen(self): if glfw.get_window_monitor(self._window): # fullscreen to window glfw.set_window_monitor(self._window, None, *self._window_info, 0) else: # window to fullscreen info = [0] * 4 info[0], info[1] = glfw.get_window_pos(self._window) info[2], info[3] = glfw.get_window_size(self._window) self._window_info = info monitor = glfw.get_primary_monitor() size = glfw.get_video_mode(monitor)[0] glfw.set_window_monitor(self._window, monitor, 0, 0, *size, 0)
def setGammaRamp(self, gammaRamp): """Set the hardware CLUT to use the specified ramp. This is a custom function for doing so using GLFW. :param gammaRamp: :return: """ win = glfw.get_window_user_pointer(self.winHandle) # if not fullscreen, we get an access violation if not win._isFullScr: return None monitor = glfw.get_window_monitor(self.winHandle) if self.getGammaRampSize() == gammaRamp.shape[1]: new_ramp = (gammaRamp[0, :], gammaRamp[1, :], gammaRamp[2, :]) glfw.set_gamma_ramp(monitor, new_ramp)
def getGammaRampSize(self): """Get the gamma ramp size for the current display. The size of the ramp depends on the bits-per-color of the current video mode. :return: """ # get the current gamma ramp win = glfw.get_window_user_pointer(self.winHandle) if not win._isFullScr: return None monitor = glfw.get_window_monitor(self.winHandle) currentGammaRamp = glfw.get_gamma_ramp(monitor) # get the gamma ramps for each color channel red_ramp = currentGammaRamp[0] green_ramp = currentGammaRamp[1] blue_ramp = currentGammaRamp[2] return max(len(red_ramp), len(green_ramp), len(blue_ramp))
def setFullScr(self, value): """Sets the window to/from full-screen mode. Parameters ---------- value : bool or int If `True`, resize the window to be fullscreen. """ # convert value to correct type value = bool(value) # get monitor handle for the window monitor = glfw.get_window_monitor(self.winHandle) # get the video mode for the monitor # get monitors, with GLFW the primary display is ALWAYS at index 0 allScrs = glfw.get_monitors() if len(allScrs) < int(self.win.screen) + 1: logging.warn("Requested an unavailable screen number - " "using first available.") self.win.screen = 0 thisScreen = allScrs[self.win.screen] if self.win.autoLog: logging.info('configured GLFW screen %i' % self.win.screen) # get monitor information nativeVidmode = glfw.get_video_mode(thisScreen) refreshRateHz = nativeVidmode.refresh_rate scrWidth, scrHeight = nativeVidmode.size winWidth, winHeight = nativeVidmode.size if value else self.win.windowedSize # set the monitor # glfw.window_hint(glfw.DECORATED, glfw.FALSE) glfw.set_window_monitor( self.winHandle, monitor if value else None, # if `None` windowed, else fullscreen 0, 0, # position keep zero and set later nativeVidmode.size[0] if value else self.win.windowedSize[0], nativeVidmode.size[1] if value else self.win.windowedSize[1], refreshRateHz) if not value: # extra stuff for non-fullscreen # if no window position is specified, centre it on-screen if self.win.pos is None: self.win.pos = [ (scrWidth - winWidth) / 2.0, (scrHeight - winHeight) / 2.0] # get the virtual position of the monitor, apply offset to the # window position px, py = glfw.get_monitor_pos(thisScreen) glfw.set_window_pos( self.winHandle, int(self.win.pos[0] + px), int(self.win.pos[1] + py)) # get the reported client size self.win.clientSize[:] = glfw.get_window_size(self.winHandle) self.frameBufferSize[:] = glfw.get_framebuffer_size(self.winHandle) self.win.viewport = ( 0, 0, self._frameBufferSize[0], self._frameBufferSize[1]) self.win.scissor = ( 0, 0, self._frameBufferSize[0], self._frameBufferSize[1]) self.win.resetEyeTransform()