in mujoco_py/mjviewer.py [0:0]
def _read_pixels_as_in_window(self, resolution=None):
# Reads pixels with markers and overlay from the same camera as screen.
if resolution is None:
resolution = glfw.get_framebuffer_size(self.sim._render_context_window.window)
resolution = np.array(resolution)
resolution = resolution * min(1000 / np.min(resolution), 1)
resolution = resolution.astype(np.int32)
resolution -= resolution % 16
if self.sim._render_context_offscreen is None:
self.sim.render(resolution[0], resolution[1])
offscreen_ctx = self.sim._render_context_offscreen
window_ctx = self.sim._render_context_window
# Save markers and overlay from offscreen.
saved = [copy.deepcopy(offscreen_ctx._markers),
copy.deepcopy(offscreen_ctx._overlay),
rec_copy(offscreen_ctx.cam)]
# Copy markers and overlay from window.
offscreen_ctx._markers[:] = window_ctx._markers[:]
offscreen_ctx._overlay.clear()
offscreen_ctx._overlay.update(window_ctx._overlay)
rec_assign(offscreen_ctx.cam, rec_copy(window_ctx.cam))
img = self.sim.render(*resolution)
img = img[::-1, :, :] # Rendered images are upside-down.
# Restore markers and overlay to offscreen.
offscreen_ctx._markers[:] = saved[0][:]
offscreen_ctx._overlay.clear()
offscreen_ctx._overlay.update(saved[1])
rec_assign(offscreen_ctx.cam, saved[2])
return img