Skip to content

Question about OpenGL rendering size #1482

@tlpss

Description

@tlpss

It seems that the OpenGL rendering size is set once for mujoco enviroments instead of using the actual width and height provided to the MujocoRenderer

model.vis.global_.offwidth = self.width

I used the MujocoRenderer to create a custom renderer with a different size, but this causes black bands on the part outside of the original size.

    renderer = MujocoRenderer(
        env.unwrapped.model,
        env.unwrapped.data, 
        None,
        width=width,
        height=height,
        camera_name=camera_name,
    )
img = renderer.render(render_mode)

Image

Shouldn't the OpenGL size be set inside the renderer before creating the screen? i.e. here

I changed the code like his

                # save the original width and height of the model to restore it later
                orig_width = self.model.vis.global_.offwidth
                orig_height = self.model.vis.global_.offheight

                # set the width and height to the context, otherswise the rendering will have black bands if the resolution differs from the one     with which the gym env was created.
                self.model.vis.global_.offwidth = self.width
                self.model.vis.global_.offheight = self.height

                self.viewer = OffScreenViewer(
                    self.model,
                    self.data,
                    self.width,
                    self.height,
                    self.max_geom,
                    self._vopt,
                )

                # restore the default  width and height to the context
                self.model.vis.global_.offwidth = orig_width
                self.model.vis.global_.offheight = orig_height

which solved the black bands for me:

Image

Not an expert on mujoco rendering though, so I might be overlooking something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions