Browse files

BF: For pyglet 1.3 we really have to use retina displays now

Trying to acoid this just caused the size of hte screen to appear
wrong and I couldn't work out where the code is that forces the
issue (reverting to pyglet 1.2 gets rid of the problem).

This seems OK but I've forced the setting useRetina to be True
and raised an error if the user tries to set it to False to
ensure that everyone knows it changed
  • Loading branch information...
peircej committed Aug 16, 2017
1 parent 2f0bcd9 commit 08163f78a9c8ab9bc625438d2de2fe330c1e3819
Showing with 31 additions and 41 deletions.
  1. +31 −41 psychopy/visual/
@@ -106,7 +106,7 @@
DEBUG = False
retinaContext = None # only needed for retina-ready displays
# keep track of windows that have been opened
# Use a list of weak references so that we don't stop the window being deleted
@@ -165,7 +165,7 @@ def __init__(self,
These attributes can only be set at initialization. See further down
@@ -238,10 +238,10 @@ def __init__(self,
this will be enabled.
You can switch between left and right-eye scenes for drawing
operations using :func:`~psychopy.visual.Window.setBuffer`
useRetina : True or *False*
Try to use the full resolution of the Retina display (only on
certain Macs). By default the display's reduced resolution will
be used. NB when you use Retina display the initial win size
useRetina : *True* or False
In PsychoPy >1.85.3 this should always be True as pyglet
(or Apple) no longer allows us to create a non-retina display.
NB when you use Retina display the initial win size
request will be in the larger pixels but subsequent use of
units='pix' should refer to the tiny Retina pixels. Window.size
will give the actual size of the screen in Retina pixels
@@ -273,6 +273,14 @@ def __init__(self,
self.useFBO = useFBO
self.useRetina = useRetina
if sys.platform=='darwin' and not useRetina and pyglet.version >= "1.3":
raise ValueError("As of PsychoPy 1.85.3 OSX windows should all be "
"set to useRetina=True (or remove the argument). "
"Pyglet 1.3 appears to be forcing "
"us to use retina on any retina-capable screen "
"so setting to False has no effect.")
self._toLog = []
self._toCall = []
# settings for the monitor: local settings (if available) override
@@ -1447,36 +1455,6 @@ def _setupPyglet(self):
samples=aa_samples, stencil_size=stencil_size, stereo=self.stereo,
# monkey patches for retina display if needed
def retinaAttach(self, canvas):
"""Replaces method
super(CocoaContext, self).attach(canvas)
except AttributeError:
def retina_on_resize(self, width, height):
"""Insert as method """
view = self.context._nscontext.view()
bounds = view.convertRectToBacking_(view.bounds()).size
back_width, back_height = (int(bounds.width), int(bounds.height))
GL.glViewport(0, 0, back_width, back_height)
GL.glOrtho(0, width, 0, height, -1, 1)
if self.useRetina and sys.platform == 'darwin':
from import CocoaContext
CocoaContext.attach = retinaAttach
from pyglet.window.cocoa import CocoaWindow
CocoaWindow.on_resize = retina_on_resize
defDisp = pyglet.window.get_platform().get_default_display()
allScrs = defDisp.get_screens()
# Screen (from Exp Settings) is 1-indexed,
@@ -1515,16 +1493,18 @@ def retina_on_resize(self, width, height):
self._hw_handle = self.winHandle._hwnd
elif sys.platform == 'darwin':
if self.useRetina:
global retinaContext
retinaContext = self.winHandle.context._nscontext
view = retinaContext.view()
bounds = view.convertRectToBacking_(view.bounds()).size
self.size = (int(bounds.width), int(bounds.height))
# python 32bit (1.4. or 1.2 pyglet)
self._hw_handle = self.winHandle._window.value
except Exception:
# pyglet 1.2 with 64bit python?
self._hw_handle = self.winHandle._nswindow.windowNumber()
if self.useRetina:
view = self.context._nscontext.view()
bounds = view.convertRectToBacking_(view.bounds()).size
self.size = (int(bounds.width), int(bounds.height))
elif sys.platform == 'linux2':
self._hw_handle = self.winHandle._window
@@ -2053,9 +2033,19 @@ def _onResize(width, height):
Override this event handler with your own to create another
projection, for example in perspective.
global retinaContext
if height == 0:
height = 1
GL.glViewport(0, 0, width, height)
if retinaContext is not None:
view = retinaContext.view()
bounds = view.convertRectToBacking_(view.bounds()).size
back_width, back_height = (int(bounds.width), int(bounds.height))
back_width, back_height = width, height
GL.glViewport(0, 0, back_width, back_height)
GL.glOrtho(-1, 1, -1, 1, -1, 1)

0 comments on commit 08163f7

Please sign in to comment.