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 GL2

From Leeroopedia
Revision as of 12:47, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Render_GL2.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains OpenGL, Graphics, Rendering, 2D Rendering
Last Updated 2026-02-15 04:00 GMT

Overview

OpenGL 2D rendering implementation providing framebuffer management, pixel I/O, text drawing, overlay rendering, and 2D figure plotting for MuJoCo.

Description

This file implements the core 2D rendering operations used by MuJoCo's visualization system. It provides framebuffer selection and binding (window vs. offscreen), pixel read/write/blit operations, auxiliary buffer management, text rendering with font support, overlay drawing on viewports, rectangle and label drawing, and 2D figure/chart rendering. All functions operate on an mjrContext that tracks the current OpenGL rendering state.

Usage

Used throughout MuJoCo's visualization pipeline for all 2D rendering tasks including HUD overlays, text labels, pixel readback for offscreen rendering, and figure/chart visualization in the simulate viewer.

Code Reference

Source Location

Key Functions

// Set OpenGL framebuffer for rendering: mjFB_WINDOW or mjFB_OFFSCREEN
void mjr_setBuffer(int framebuffer, mjrContext* con);

// Restore con->currentBuffer as active framebuffer
void mjr_restoreBuffer(const mjrContext* con);

// Read pixels from current OpenGL framebuffer
void mjr_readPixels(unsigned char* rgb, float* depth,
                    mjrRect viewport, const mjrContext* con);

// Draw pixels to current OpenGL framebuffer
void mjr_drawPixels(const unsigned char* rgb, const float* depth,
                    mjrRect viewport, const mjrContext* con);

// Blit between framebuffers
void mjr_blitBuffer(mjrRect src, mjrRect dst,
                    int flg_color, int flg_depth, const mjrContext* con);

// Set/blit auxiliary buffers
void mjr_setAux(int index, const mjrContext* con);
void mjr_blitAux(int index, mjrRect src, int left, int bottom, const mjrContext* con);

// Text rendering
void mjr_text(int font, const char* txt, const mjrContext* con,
              float x, float y, float r, float g, float b);
void mjr_overlay(int font, int gridpos, mjrRect viewport,
                 const char* overlay, const char* overlay2, const mjrContext* con);

// 2D drawing
void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a);
void mjr_label(mjrRect viewport, int font, const char* txt,
               float r, float g, float b, float a, float rt, float gt, float bt,
               const mjrContext* con);
void mjr_figure(mjrRect viewport, mjvFigure* fig, const mjrContext* con);

Import

#include "render/render_gl2.h"

I/O Contract

Inputs

Name Type Required Description
con mjrContext* Yes Rendering context holding OpenGL state, framebuffer IDs, and font data
framebuffer int Yes (for setBuffer) Target framebuffer: mjFB_WINDOW or mjFB_OFFSCREEN
viewport mjrRect Yes (for pixel/draw ops) Viewport rectangle in OpenGL framebuffer coordinates
fig mjvFigure* Yes (for figure) Figure data structure containing line/bar chart data

Outputs

Name Type Description
rgb unsigned char* Pixel color data read from framebuffer (via mjr_readPixels)
depth float* Pixel depth data read from framebuffer (via mjr_readPixels)
(rendered output) OpenGL framebuffer Text, overlays, rectangles, figures drawn to the active framebuffer

Related Pages

Page Connections

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