Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco Render GL3

From Leeroopedia
Knowledge Sources
Domains OpenGL, Graphics, 3D Rendering, Physics Visualization
Last Updated 2026-02-15 04:00 GMT

Overview

OpenGL 3D rendering implementation providing scene rendering with lighting, shadows, reflections, and texture mapping for MuJoCo's visualization pipeline.

Description

This file implements the main 3D scene rendering for MuJoCo. It handles geometry rendering with support for reflective surfaces, shadow mapping via projective textures, skybox rendering, and multi-light setups. The renderer processes mjvScene objects containing sorted geometry lists and renders them with proper depth sorting, transparency handling, and view-dependent effects. Key internal routines manage texture state transitions, OpenGL fixed-function pipeline configuration, and per-geom material properties.

Usage

Called by the simulate viewer and any application using mjr_render to draw a 3D physics scene. The main entry point receives a viewport rectangle, a scene description, and a rendering context, then produces the fully rendered 3D view.

Code Reference

Source Location

Key Functions

// Main 3D scene rendering entry point
void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con);

// Wait for OpenGL rendering to finish
void mjr_finish(void);

// Get last OpenGL error
int mjr_getError(void);

// Internal: check if head is behind a plane (for reflection culling)
static int isBehind(const float* headpos, const float* pos, const float* mat);

// Internal: check if a geometry is reflective
static int isReflective(const mjvGeom* geom);

// Internal: enable/disable texture mapping for shadow, skybox, or regular textures
static void settexture(int type, int state, const mjrContext* con, const mjvGeom* geom);

// Internal: render a single geometry with material properties
static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
                       const mjrContext* con);

// Internal: initialize OpenGL state for 3D rendering
static void initGL3(const mjvScene* scn, const mjrContext* con);

// Internal: configure scene lights
static void initLights(mjvScene* scn);

Import

#include "render/render_gl3.h"

I/O Contract

Inputs

Name Type Required Description
viewport mjrRect Yes Rectangle defining the rendering area in framebuffer coordinates
scn mjvScene* Yes Scene containing geometry list, lights, camera, and rendering flags
con const mjrContext* Yes Rendering context with OpenGL resources, textures, and display lists

Outputs

Name Type Description
(rendered output) OpenGL framebuffer Fully rendered 3D scene with lighting, shadows, reflections, and textures
return value (getError) int OpenGL error code, 0 if no error

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment