Skip to main content

Overview

The GameRenderer class is the main rendering coordinator for Minecraft, handling camera positioning, viewport setup, FOV calculations, rendering effects, lighting, weather, and the main render loop. It orchestrates the rendering of the entire game view. Header: Minecraft.Client/GameRenderer.h

Class Definition

class GameRenderer

Constants

Light Textures

static const int NUM_LIGHT_TEXTURES = 4;
Number of light texture maps (one per split-screen player).

Static Members

static bool anaglyph3d;      // Enable 3D anaglyph rendering
static int anaglyphPass;     // Current anaglyph render pass (0 or 1)

Constructor

GameRenderer(Minecraft *mc);
Creates a new GameRenderer instance. Parameters:
  • mc - Pointer to the main Minecraft instance

Core Rendering Methods

render

void render(float a, bool bFirst);
Main render method called each frame. Parameters:
  • a - Interpolation alpha for smooth rendering (0.0-1.0)
  • bFirst - Whether this is the first player in split-screen
Example Usage:
float partialTick = calculatePartialTick();
gameRenderer->render(partialTick, true);

renderLevel

void renderLevel(float a);
void renderLevel(float a, __int64 until);
Renders the level/world from the current camera perspective. Parameters:
  • a - Interpolation alpha
  • until - (Optional) Timestamp to stop rendering (for performance budgeting)

Camera Methods

setupCamera

void setupCamera(float a, int eye);
Sets up the camera position, orientation, and projection matrix. Parameters:
  • a - Interpolation alpha
  • eye - Eye index for stereoscopic rendering (0 = left, 1 = right)
Example:
// Setup camera for main view
gameRenderer->setupCamera(partialTick, 0);

// Setup for VR/anaglyph right eye
if (GameRenderer::anaglyph3d) {
    GameRenderer::anaglyphPass = 1;
    gameRenderer->setupCamera(partialTick, 1);
}

pick

void pick(float a);
Performs ray-casting to determine what the player is looking at (block/entity selection). Parameters:
  • a - Interpolation alpha

zoomRegion / unZoomRegion

void zoomRegion(double zoom, double xa, double ya);
void unZoomRegion();
Zoom in on a specific region of the screen (used for spyglass, etc.). Parameters:
  • zoom - Zoom factor
  • xa - X offset (normalized -1 to 1)
  • ya - Y offset (normalized -1 to 1)

Field of View (FOV)

SetFovVal / GetFovVal

void SetFovVal(float fov);
float GetFovVal();
Set or get the base field of view value. Example:
// Set FOV to 90 degrees
gameRenderer->SetFovVal(90.0f);

// Get current FOV
float currentFov = gameRenderer->GetFovVal();

GUI and Screen Setup

setupGuiScreen

void setupGuiScreen(int forceScale = -1);
Sets up orthographic projection for rendering GUI/HUD elements. Parameters:
  • forceScale - Force a specific GUI scale (default -1 = use settings)
Example:
// Setup GUI rendering with auto-scale
gameRenderer->setupGuiScreen();

// Render GUI elements
screen->render(mouseX, mouseY, partialTick);

// Setup for forced 2x scale
gameRenderer->setupGuiScreen(2);

Lighting

Light Texture Management

int getLightTexture(int iPad, Level *level);
Gets the light texture ID for a specific player and level. Parameters:
  • iPad - Player index (0-3 for split-screen)
  • level - The level/dimension
Returns: OpenGL texture ID for the light map

turnOnLightLayer / turnOffLightLayer

void turnOnLightLayer(double alpha);
void turnOffLightLayer(double alpha);
Enable or disable the lighting layer blend (for fullbright effects). Parameters:
  • alpha - Transition alpha

updateLightTexture

void updateLightTexture(float a);
Updates the dynamic light texture based on time of day, dimension, and effects.

Weather Effects

renderSnowAndRain

void renderSnowAndRain(float a);
Renders precipitation effects (rain in overworld, snow in cold biomes). Parameters:
  • a - Interpolation alpha

Item in Hand

ItemInHandRenderer

ItemInHandRenderer *itemInHandRenderer;
Public member for rendering held items and tools. Example:
// Render the player's held item
gameRenderer->itemInHandRenderer->render(player, partialTick);

Chunk Updates

updateAllChunks

void updateAllChunks();
Forces update of all dirty chunks in the render distance.
Performance Impact: Calling this method can cause frame hitches as it rebuilds multiple chunks. Use sparingly.

Update Thread Management

void EnableUpdateThread();
void DisableUpdateThread();
Enable or disable multithreaded chunk updating. Example:
// Enable background chunk updates
gameRenderer->EnableUpdateThread();

// Disable when exiting level
gameRenderer->DisableUpdateThread();

Tick Methods

tick

void tick(bool bFirst);
Called once per game tick (20 times per second) to update camera state. Parameters:
  • bFirst - Whether this is the first player
Example:
// In main game loop
if (tickCount % 1 == 0) {
    gameRenderer->tick(true);
}

Memory Management

Delete Stack Methods

static void AddForDelete(byte *deleteThis);
static void AddForDelete(SparseLightStorage *deleteThis);
static void AddForDelete(CompressedTileStorage *deleteThis);
static void AddForDelete(SparseDataStorage *deleteThis);
static void FinishedReassigning();
Thread-safe deferred deletion for chunk data structures. Example:
// Queue chunk data for deletion
GameRenderer::AddForDelete(oldLightStorage);

// After chunk reassignment is complete
GameRenderer::FinishedReassigning();

Rendering Pipeline Example

// Main render loop
void renderGame(float partialTick) {
    // Update game state
    gameRenderer->tick(true);
    
    // Pick what player is looking at
    gameRenderer->pick(partialTick);
    
    // Setup camera for 3D world
    gameRenderer->setupCamera(partialTick, 0);
    
    // Render the level
    gameRenderer->renderLevel(partialTick);
    
    // Render weather
    gameRenderer->renderSnowAndRain(partialTick);
    
    // Setup for GUI/HUD rendering
    gameRenderer->setupGuiScreen();
    
    // Render HUD
    gui->render(partialTick);
}

Advanced Camera Control

// Third-person camera with smooth interpolation
class GameRenderer {
private:
    SmoothFloat smoothTurnX;      // Smooth camera rotation X
    SmoothFloat smoothTurnY;      // Smooth camera rotation Y
    SmoothFloat smoothDistance;   // Third-person distance
    SmoothFloat smoothRotation;   // Camera rotation around player
    SmoothFloat smoothTilt;       // Camera tilt angle
    SmoothFloat smoothRoll;       // Camera roll (for effects)
    
    float cameraRoll;             // Current camera roll
    float cameraRollO;            // Previous camera roll
    
    float fovOffset;              // FOV modification (sprint, etc.)
    float fovOffsetO;             // Previous FOV offset
};
These smooth interpolation members handle camera smoothing for third-person view and camera effects.

FOV Effects

The FOV system supports dynamic field of view changes:
// FOV changes when sprinting, using bow, underwater, etc.
float baseFov = gameRenderer->GetFovVal();
float effectiveFov = baseFov + fovOffset; // Modified by game state

Lighting System

The lighting system uses dynamic texture mapping:
// Light texture arrays (one per player in split-screen)
int lightTexture[NUM_LIGHT_TEXTURES];
intArray lightPixels[NUM_LIGHT_TEXTURES];

// Updates lighting based on:
// - Time of day (sun/moon position)
// - Dimension (Nether has no day/night)
// - Player effects (night vision)
// - Sky light level
// - Brightness setting

Usage with Level Renderer

// Typical integration
Minecraft* mc = /* ... */;
GameRenderer* gameRenderer = new GameRenderer(mc);
LevelRenderer* levelRenderer = new LevelRenderer(mc, textures);

// Render frame
void renderFrame(float partialTick) {
    // GameRenderer coordinates the rendering
    gameRenderer->setupCamera(partialTick, 0);
    
    // Update lighting
    gameRenderer->updateLightTexture(partialTick);
    
    // LevelRenderer does the actual level rendering
    levelRenderer->render(player, 0, partialTick, true);
    levelRenderer->render(player, 1, partialTick, false);
    
    // Weather effects
    gameRenderer->renderSnowAndRain(partialTick);
    
    // GUI
    gameRenderer->setupGuiScreen();
    renderHUD();
}

Performance Monitoring

// Frame timing
private:
    __int64 lastActiveTime;
    __int64 lastNsTime;
These members track frame timing for performance monitoring and tick synchronization.

Build docs developers (and LLMs) love