mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-09-01 02:17:19 +00:00
fix "Could not create GL context" (#1889)
* fix "Could not create GL context" * get available display in case of None spec - create context all the time
This commit is contained in:
@@ -43,19 +43,31 @@ def get_display(spec):
|
|||||||
Pyglet only supports multiple Displays on Linux.
|
Pyglet only supports multiple Displays on Linux.
|
||||||
"""
|
"""
|
||||||
if spec is None:
|
if spec is None:
|
||||||
return None
|
return pyglet.canvas.get_display()
|
||||||
|
# returns already available pyglet_display,
|
||||||
|
# if there is no pyglet display available then it creates one
|
||||||
elif isinstance(spec, str):
|
elif isinstance(spec, str):
|
||||||
return pyglet.canvas.Display(spec)
|
return pyglet.canvas.Display(spec)
|
||||||
else:
|
else:
|
||||||
raise error.Error('Invalid display specification: {}. (Must be a string like :0 or None.)'.format(spec))
|
raise error.Error('Invalid display specification: {}. (Must be a string like :0 or None.)'.format(spec))
|
||||||
|
|
||||||
|
def get_window(width, height, display):
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
|
||||||
class Viewer(object):
|
class Viewer(object):
|
||||||
def __init__(self, width, height, display=None):
|
def __init__(self, width, height, display=None):
|
||||||
display = get_display(display)
|
display = get_display(display)
|
||||||
|
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.window = pyglet.window.Window(width=width, height=height, display=display)
|
self.window = get_window(width=width, height=height, display=display)
|
||||||
self.window.on_close = self.window_closed_by_user
|
self.window.on_close = self.window_closed_by_user
|
||||||
self.isopen = True
|
self.isopen = True
|
||||||
self.geoms = []
|
self.geoms = []
|
||||||
|
Reference in New Issue
Block a user