Implementation:Google deepmind Mujoco Render GL2 Header
| Knowledge Sources | |
|---|---|
| Domains | OpenGL, Graphics, 2D Rendering |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Header declaring the public API for MuJoCo's OpenGL 2D rendering functions including framebuffer management, pixel I/O, text rendering, and 2D figure drawing.
Description
This header provides the function declarations for all 2D rendering operations in MuJoCo. It declares MJAPI-exported functions for framebuffer selection (window/offscreen), pixel read/write/blit operations, auxiliary buffer management, text and overlay rendering, rectangle and label drawing, and 2D figure plotting. It also declares the internal mjr_textActual helper used by the text rendering implementation.
Usage
Included by source files that need to call MuJoCo's 2D rendering functions, and by the 3D renderer (render_gl3.c) which depends on 2D operations for compositing overlays and text onto the rendered scene.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/render/render_gl2.h
- Lines: 1-84
Key Functions
// Restore the current buffer binding
MJAPI void mjr_restoreBuffer(const mjrContext* con);
// Internal text drawing (no OpenGL state init)
void mjr_textActual(int font, const char* txt, const mjrContext* con,
float x, float y, float z, float r, float g, float b);
// Framebuffer management
MJAPI void mjr_setBuffer(int framebuffer, mjrContext* con);
MJAPI void mjr_setAux(int index, const mjrContext* con);
// Pixel I/O
MJAPI void mjr_readPixels(unsigned char* rgb, float* depth,
mjrRect viewport, const mjrContext* con);
MJAPI void mjr_drawPixels(const unsigned char* rgb, const float* depth,
mjrRect viewport, const mjrContext* con);
MJAPI void mjr_blitBuffer(mjrRect src, mjrRect dst,
int flg_color, int flg_depth, const mjrContext* con);
MJAPI void mjr_blitAux(int index, mjrRect src, int left, int bottom,
const mjrContext* con);
// Text and overlay
MJAPI void mjr_text(int font, const char* txt, const mjrContext* con,
float x, float y, float r, float g, float b);
MJAPI void mjr_overlay(int font, int gridpos, mjrRect viewport,
const char* overlay, const char* overlay2, const mjrContext* con);
// Viewport and drawing
MJAPI mjrRect mjr_maxViewport(const mjrContext* con);
MJAPI void mjr_rectangle(mjrRect viewport, float r, float g, float b, float a);
MJAPI 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);
MJAPI 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* / const mjrContext* | Yes | Rendering context with OpenGL state |
| framebuffer | int | Yes (for setBuffer) | mjFB_WINDOW or mjFB_OFFSCREEN |
| viewport | mjrRect | Yes (for pixel/draw ops) | Viewport rectangle in framebuffer coordinates |
| font | int | Yes (for text ops) | Font index (mjtFont) |
| fig | mjvFigure* | Yes (for figure) | Figure data for 2D chart rendering |
Outputs
| Name | Type | Description |
|---|---|---|
| rgb | unsigned char* | Output buffer for pixel color data (via mjr_readPixels) |
| depth | float* | Output buffer for pixel depth data (via mjr_readPixels) |
| mjrRect | struct | Maximum viewport dimensions (via mjr_maxViewport) |