Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable more than one MjViewer instance at a time #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions rllab/mujoco_py/mjviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _glfw_error_callback(e, d):

class MjViewer(object):

def __init__(self, visible=True, init_width=500, init_height=500, go_fast=False):
def __init__(self, visible=True, init_width=500, init_height=500, go_fast=False, title="Simulate"):
"""
Set go_fast=True to run at full speed instead of waiting for the 60 Hz monitor refresh
init_width and init_height set window size. On Mac Retina displays, they are in nominal
Expand All @@ -43,6 +43,7 @@ def __init__(self, visible=True, init_width=500, init_height=500, go_fast=False)
self.window = None
self.model = None
self.gui_lock = Lock()
self.title = title

# framebuffer objects
self._fbo = None
Expand Down Expand Up @@ -89,6 +90,10 @@ def get_rect(self):
def render(self):
if not self.data:
return

# Make the window's context current
glfw.make_context_current(self.window)

self.gui_lock.acquire()
rect = self.get_rect()
arr = (ctypes.c_double*3)(0, 0, 0)
Expand Down Expand Up @@ -176,15 +181,15 @@ def start(self):
if refresh_rate >= 100:
glfw.window_hint(glfw.STEREO, 1)
window = glfw.create_window(
self.init_width, self.init_height, "Simulate", None, None)
self.init_width, self.init_height, self.title, None, None)
if window:
stereo_available = True

# no stereo: try mono
if not window:
glfw.window_hint(glfw.STEREO, 0)
window = glfw.create_window(
self.init_width, self.init_height, "Simulate", None, None)
self.init_width, self.init_height, self.title, None, None)

if not window:
glfw.terminate()
Expand Down