Implementation:Google deepmind Mujoco GLFW Init CreateWindow
| Knowledge Sources | |
|---|---|
| Domains | Windowing, Input_Handling, OpenGL |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
External tool for creating OpenGL windows and handling input via the GLFW library used in MuJoCo interactive examples.
Description
glfwInit initializes the GLFW library and glfwCreateWindow creates an OS window with an OpenGL context. MuJoCo's sample/basic.cc demonstrates the standard pattern of GLFW initialization with MuJoCo callback registration for keyboard, mouse button, mouse move, and scroll events.
Usage
Use for interactive visualization. Initialize GLFW before creating the MuJoCo rendering context (mjr_makeContext). Register MuJoCo-compatible callbacks for user interaction.
Code Reference
Source Location
- Repository: mujoco
- File: sample/basic.cc
- Lines: 126-149
Signature
// GLFW library functions (external)
int glfwInit(void);
GLFWwindow* glfwCreateWindow(int width, int height, const char* title,
GLFWmonitor* monitor, GLFWwindow* share);
void glfwMakeContextCurrent(GLFWwindow* window);
Import
#include <GLFW/glfw3.h>
External Reference
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| width | int | Yes | Window width in pixels (e.g., 1200) |
| height | int | Yes | Window height in pixels (e.g., 900) |
| title | const char* | Yes | Window title string |
Outputs
| Name | Type | Description |
|---|---|---|
| window | GLFWwindow* | Window handle with active OpenGL context |
Usage Examples
#include <GLFW/glfw3.h>
#include <mujoco/mujoco.h>
// Initialize GLFW
if (!glfwInit()) {
return 1;
}
// Create window with OpenGL context
GLFWwindow* window = glfwCreateWindow(1200, 900, "MuJoCo", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // vsync
// Register MuJoCo callbacks
glfwSetKeyCallback(window, keyboard);
glfwSetCursorPosCallback(window, mouse_move);
glfwSetMouseButtonCallback(window, mouse_button);
glfwSetScrollCallback(window, scroll);
// ... create mjrContext here ...
// Render loop
while (!glfwWindowShouldClose(window)) {
// simulate, update scene, render...
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();