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

Spawn the window of the offscreen context out of focus #510

Open
iSaran opened this issue Feb 20, 2020 · 3 comments
Open

Spawn the window of the offscreen context out of focus #510

iSaran opened this issue Feb 20, 2020 · 3 comments

Comments

@iSaran
Copy link

iSaran commented Feb 20, 2020

I am creating an offscreen context using the following:

offscreen = MjRenderContextOffscreen(sim, 0)

This creates a window which spawns in front of the other windows (in focus) that I have open. Is this the intended behavior?

I have a setup in which I create multiple mujoco sessions overtime and I run them in the same pc, which I am working on. This means that the spawning windows interrupt my workflow. One fix is to minimize the window right after the context construction with:

glfw.iconify_window(offscreen.opengl_context.window)

This is not a correct solution though because even momentarily the focus goes to the Mujoco window.

Can I create this context with its window spawning out of focus from the very start?

My mujoco-py version is 1.50.1.68.

@iSaran
Copy link
Author

iSaran commented Mar 5, 2020

It seems that MjRenderContextOffscreen does not really create an offscreen context and this is why it creates these annoying windows. If I change the constructor of MjRenderContextOffscreen from cinit to init then it properly creates an offscreen context.

For now I directly create an instance of the base class, in order to create an offscreen context properly:

offscreen = MjRenderContext(sim=self.sim, device_id=0, offscreen=True, opengl_backend='glfw')

@gonultasbu
Copy link

I also haven't been able to solve this problem. Super annoying.

@kracon7
Copy link

kracon7 commented May 27, 2020

@iSaran
Your approach worked for me. Now I can render offscreen images without having to spawn an empty mj_viewer window.

For anyone who is interested, here's what I did:
I'm using Ubuntu 16.04 and mujoco-py 2.0.2.5
After initializing the sim object

from mujoco_py import MjSim, MjViewer, load_model_from_path, MjRenderContext 

model = load_model_from_path(xml_path)
sim = MjSim(model)

If I want to render images without visualizing the simulation using MjViewer()
Previously I need to do this:

viewer = MjViewer(sim)
img = sim.render(w, h, camera_name, depth=True)

This will initialize an empty window for rendering in ''window' mode, otherwise sim.render() alone couldn't work.

Now after change the constructor of MjRenderContextOffscreen from cinit to init, I did this:

offscreen = MjRenderContext(sim=sim, device_id=0, offscreen=True, opengl_backend='glfw')
offscreen.render(100, 100, camera_id=-1)
img = offscreen.read_pixels(100, 100, depth=True)

It doesn't spawn any extra window, the whole rendering process is at the backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants