Skip to main content

Module gl

Module gl 

Source
Expand description

Immediate-mode drawing with UnityEngine.GL, for use inside an on_render callback (it’s only valid during rendering).

use hao_il2cpp_unity::{gl, on_render, Color, Vector3};

on_render(|_camera| {
    gl::load_pixel_matrix(0.0, 1920.0, 0.0, 1080.0);
    gl::draw(gl::Mode::Triangles, || {
        gl::color(Color::rgb(1.0, 0.0, 0.0));
        gl::vertex(16.0, 16.0);
        gl::vertex(216.0, 16.0);
        gl::vertex(16.0, 116.0);
    });
})?;

An egui (or other GPU UI) backend would translate its tessellated output into these calls, or hook the native graphics present for a full GPU surface — that part is renderer-specific and up to the mod.

Enums§

Mode
The primitive topology passed to draw/begin, matching Unity’s GL modes.

Functions§

begin
Begins a primitive of mode. Pair with end; prefer draw.
clear
Clears the active render target to color (and optionally the depth buffer).
color
Sets the current vertex colour.
draw
Draws a primitive: calls begin, runs body (which emits color and vertex/vertex3), then end, even if body returns an error.
end
load_ortho
Sets up an orthographic projection with coordinates from (0, 0) to (1, 1).
load_pixel_matrix
Sets up a pixel-space projection: (left, bottom) to (right, top) in pixels.
pop_matrix
push_matrix
Saves the projection/model-view matrix; restore with pop_matrix.
tex_coord
Sets the texture coordinate for the next vertex.
vertex
Emits a 2D vertex at z = 0.
vertex3
Emits a 3D vertex.