Skip to content

Commit

Permalink
pyglet GL context for SimpleImageViewer case (openai#1916)
Browse files Browse the repository at this point in the history
* pyglet GL context for SimpleImageViewer case

* typo fxd 'viewer_type' argument in get_window()

* use **kwargs in get_window()

* remove viewer_type from Viewer class
  • Loading branch information
shashikg authored May 29, 2020
1 parent 612bf41 commit 0f513ac
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions gym/envs/classic_control/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def get_display(spec):
else:
raise error.Error('Invalid display specification: {}. (Must be a string like :0 or None.)'.format(spec))

def get_window(width, height, display):
def get_window(width, height, display, **kwargs):
"""
Will create a pyglet window from the display specification provided.
"""
screen = display.get_screens() #available screens
config = screen[0].get_best_config() #selecting the first screen
context = config.create_context(None) #create GL context

return pyglet.window.Window(width=width, height=height, display=display, config=config, context=context)
return pyglet.window.Window(width=width, height=height, display=display, config=config, context=context, **kwargs)

class Viewer(object):
def __init__(self, width, height, display=None):
Expand Down Expand Up @@ -335,7 +335,7 @@ class SimpleImageViewer(object):
def __init__(self, display=None, maxwidth=500):
self.window = None
self.isopen = False
self.display = display
self.display = get_display(display)
self.maxwidth = maxwidth
def imshow(self, arr):
if self.window is None:
Expand All @@ -344,8 +344,7 @@ def imshow(self, arr):
scale = self.maxwidth / width
width = int(scale * width)
height = int(scale * height)
self.window = pyglet.window.Window(width=width, height=height,
display=self.display, vsync=False, resizable=True)
self.window = get_window(width=width, height=height, display=self.display, vsync=False, resizable=True)
self.width = width
self.height = height
self.isopen = True
Expand Down

0 comments on commit 0f513ac

Please sign in to comment.