Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Graphics Configuration

Console configuration and render state functions.

Configuration (Init-Only)

These functions must be called in init() and cannot be changed at runtime.

set_resolution

Sets the render resolution.

Signature:

#![allow(unused)]
fn main() {
fn set_resolution(res: u32)
}

Parameters:

ValueResolution
0360p (640x360)
1540p (960x540) - default
2720p (1280x720)
31080p (1920x1080)

Constraints: Init-only. Cannot be changed after init() returns.

Example:

#![allow(unused)]
fn main() {
fn init() {
    set_resolution(2); // 720p
}
}

set_tick_rate

Sets the game’s tick rate (updates per second).

Signature:

#![allow(unused)]
fn main() {
fn set_tick_rate(fps: u32)
}

Parameters:

ValueTick Rate
024 fps
130 fps
260 fps - default
3120 fps

Constraints: Init-only. Affects GGRS synchronization.

Example:

#![allow(unused)]
fn main() {
fn init() {
    set_tick_rate(2); // 60 fps
}
}

set_clear_color

Sets the background clear color.

Signature:

#![allow(unused)]
fn main() {
fn set_clear_color(color: u32)
}

Parameters:

NameTypeDescription
coloru32RGBA color as 0xRRGGBBAA

Constraints: Init-only. Default is 0x000000FF (black).

Example:

#![allow(unused)]
fn main() {
fn init() {
    set_clear_color(0x1a1a2eFF); // Dark blue
    set_clear_color(0x87CEEBFF); // Sky blue
}
}

render_mode

Sets the rendering mode (shader pipeline).

Signature:

#![allow(unused)]
fn main() {
fn render_mode(mode: u32)
}

Parameters:

ValueModeDescription
0UnlitFlat colors, no lighting
1MatcapPre-baked lighting via matcap textures
2Metallic-RoughnessPBR-style Blinn-Phong with MRE textures
3Specular-ShininessTraditional Blinn-Phong

Constraints: Init-only. Default is mode 0 (Unlit).

Example:

#![allow(unused)]
fn main() {
fn init() {
    render_mode(2); // PBR-style lighting
}
}

See Also: Render Modes Guide


Render State

These functions can be called anytime during render() to change draw state.

set_color

Sets the uniform tint color for subsequent draws.

Signature:

#![allow(unused)]
fn main() {
fn set_color(color: u32)
}

Parameters:

NameTypeDescription
coloru32RGBA color as 0xRRGGBBAA

Example:

#![allow(unused)]
fn main() {
fn render() {
    // White (no tint)
    set_color(0xFFFFFFFF);
    draw_mesh(model);

    // Red tint
    set_color(0xFF0000FF);
    draw_mesh(enemy);

    // 50% transparent
    set_color(0xFFFFFF80);
    draw_mesh(ghost);
}
}

depth_test

Enables or disables depth testing.

Signature:

#![allow(unused)]
fn main() {
fn depth_test(enabled: u32)
}

Parameters:

NameTypeDescription
enabledu321 to enable, 0 to disable

Example:

#![allow(unused)]
fn main() {
fn render() {
    // 3D scene with depth
    depth_test(1);
    draw_mesh(level);
    draw_mesh(player);

    // UI overlay without depth
    depth_test(0);
    draw_sprite(0.0, 0.0, 100.0, 50.0, 0xFFFFFFFF);
}
}

cull_mode

Sets face culling mode.

Signature:

#![allow(unused)]
fn main() {
fn cull_mode(mode: u32)
}

Parameters:

ValueModeDescription
0NoneDraw both sides
1BackCull back faces (default)
2FrontCull front faces

Example:

#![allow(unused)]
fn main() {
fn render() {
    // Normal geometry
    cull_mode(1); // Back-face culling
    draw_mesh(solid_object);

    // Skybox (inside-out)
    cull_mode(2); // Front-face culling
    draw_mesh(skybox);

    // Double-sided foliage
    cull_mode(0); // No culling
    draw_mesh(leaves);
}
}

blend_mode

Sets the alpha blending mode.

Signature:

#![allow(unused)]
fn main() {
fn blend_mode(mode: u32)
}

Parameters:

ValueModeDescription
0NoneNo blending (opaque)
1AlphaStandard transparency
2AdditiveAdd colors (glow effects)
3MultiplyMultiply colors (shadows)

Example:

#![allow(unused)]
fn main() {
fn render() {
    // Opaque geometry first
    blend_mode(0);
    draw_mesh(level);
    draw_mesh(player);

    // Transparent objects (sorted back-to-front)
    blend_mode(1);
    draw_mesh(window);

    // Additive glow effects
    blend_mode(2);
    draw_mesh(fire_particles);
    draw_mesh(laser_beam);
}
}

texture_filter

Sets texture filtering mode.

Signature:

#![allow(unused)]
fn main() {
fn texture_filter(filter: u32)
}

Parameters:

ValueModeDescription
0NearestPixelated (retro look)
1LinearSmooth (modern look)

Example:

#![allow(unused)]
fn main() {
fn render() {
    // Pixel art sprites
    texture_filter(0);
    draw_sprite(0.0, 0.0, 64.0, 64.0, 0xFFFFFFFF);

    // Photo textures
    texture_filter(1);
    draw_mesh(realistic_model);
}
}

uniform_alpha

Sets the dither alpha level for PS1-style transparency.

Signature:

#![allow(unused)]
fn main() {
fn uniform_alpha(level: u32)
}

Parameters:

NameTypeDescription
levelu32Alpha level 0-15 (0 = invisible, 15 = opaque)

Example:

#![allow(unused)]
fn main() {
fn render() {
    // Fade in effect
    let alpha = (fade_progress * 15.0) as u32;
    uniform_alpha(alpha);
    draw_mesh(fading_object);

    // Reset to fully opaque
    uniform_alpha(15);
}
}

See Also: dither_offset


dither_offset

Sets the dither pattern offset for animated dithering.

Signature:

#![allow(unused)]
fn main() {
fn dither_offset(x: u32, y: u32)
}

Parameters:

NameTypeDescription
xu32X offset 0-3
yu32Y offset 0-3

Example:

#![allow(unused)]
fn main() {
fn render() {
    // Animate dither pattern for shimmer effect
    let frame = tick_count() as u32;
    dither_offset(frame % 4, (frame / 4) % 4);
}
}

Complete Example

#![allow(unused)]
fn main() {
fn init() {
    // Configure console
    set_resolution(1);        // 540p
    set_tick_rate(2);         // 60 fps
    set_clear_color(0x1a1a2eFF);
    render_mode(2);           // PBR lighting
}

fn render() {
    // Draw 3D scene
    depth_test(1);
    cull_mode(1);
    blend_mode(0);
    texture_filter(1);

    set_color(0xFFFFFFFF);
    draw_mesh(level);
    draw_mesh(player);

    // Draw transparent water
    blend_mode(1);
    set_color(0x4080FF80);
    draw_mesh(water);

    // Draw UI (no depth, alpha blending)
    depth_test(0);
    texture_filter(0);
    draw_sprite(10.0, 10.0, 200.0, 50.0, 0xFFFFFFFF);
}
}