Modules

Simp

moduleSource
macOSLinuxWindows

#import "Simp";

Procedures#

Images#

Mipmaps#

Image codecs#

(bitmap: *Bitmap, filepath: string) -> bool

Reads an image file into bitmap. Returns false when the file is missing or is not an image.

(bitmap: *Bitmap, filepath: string, save_alpha := false) -> bool

Writes bitmap to an image file. Returns false for any other extension, for a bitmap that is not RGB8 or RGBA8, or when the write fails.

Loaded fonts#

(_page_size_x: s32 = -1, _page_size_y: s32 = -1)

Dynamic fonts#

get_font_at_size2 overloads
(path: string, name: string, pixel_height: int, pixel_scale := 1.0) -> *Dynamic_Font

Sizes are in drawing units. With pixel_scale above 1 (a Retina window) the glyphs are rasterized at pixel_height * pixel_scale device pixels and drawn at 1/pixel_scale, so text stays sharp.

same_scalesince 0.31.0
(a: float, b: float) -> bool
(path: string, basename: string, pixel_height: int, pixel_scale := 1.0) -> font: *Dynamic_Font

Loads a font file at one size. Returns null when the file cannot be read.

begin_prepare_textsince 0.28.0
(font: *Dynamic_Font)

Starts a new run of prepared text, dropping what an earlier run gathered, glyphs and quads alike.

#import "Simp";
#import "File";

draw_label :: (font: *Dynamic_Font) {
    begin_prepare_text(font);
    append_prepare_text(font, "Score: ");
    append_prepare_text(font, "42");
    end_prepare_text(font);

    // The quads are laid out from the origin, one per glyph, left to right.
    last := font.current_quads[font.current_quads.count - 1];
    width := last.lr.x;

    draw_prepared_text(font, 20, 40, .{ 1, 1, 0, 1 });
}

This one is only checked to compile, not run.

end_prepare_textsince 0.28.0
(font: *Dynamic_Font)

Closes the run and lays its glyphs out as font.current_quads, with the pen at the origin and the baseline at y = 0, so the quads can be inspected. draw_prepared_text draws the same run at a position of its choosing.

GL textures#

(map: *Texture, filename: string, srgb := false, build_mipmaps := false) -> bool

Reads an image file and uploads it as map. Returns false when it cannot read or decode the file.

(texture: *Texture, memory: [] u8, srgb := false, build_mipmaps := false) -> bool

Like texture_load_from_file, for an image that is already in memory.

GL shaders#

GL renderer#

(window: Window_Type, wanted_msaa: int) -> chosen_msaa: s32
(window: Window_Type, coords := Simp_Coordinate_System.RIGHT_HANDED)

Chooses where drawing goes, and what the coordinates mean. Anything drawn so far is flushed first.

(window: Window_Type) -> (width: s32, height: s32)

The size of the window's framebuffer in device pixels.

get_pixel_scalesince 0.31.0
(window: Window_Type) -> float

Device pixels per window coordinate unit (2 on a Retina display).

(window: Window_Type, vsync := true)

Shows what was drawn to window. Anything still batched is drawn first.

(r: float, g: float, b: float, a: float)

Fills the current render target with one colour, and clears its depth and stencil.

set_scissor2 overloads
(p0: Vector2, p1: Vector2)

Limits drawing to a box, in the coordinates of the current render target.

(position: Vector3, color_scale: Vector4, uv: Vector2 = .{}, normal: Vector3 = .{})

Adds one corner to the batch. Every three corners make a triangle, and the batch is drawn when it fills or when something forces a flush.

(enable_blend := false)

Draws the following triangles in plain colours, with no texture.

(font: *Dynamic_Font, x: s64, y: s64, text: string, color := Vector4.{ 1, 1, 1, 1 }, effects: Font_Effects = 0) -> width: s64

Draws text in one line and returns its width in pixels.

Immediate geometry#

GL pixel read#

(source: *Texture, dest_format: Texture_Format, width: s32 = -1, height: s32 = -1, srgb := false, flip := false) -> *Pixel_Read

Starts copying the pixels of source back to the CPU without waiting for them. Poll with pixel_read_is_done, then collect them with pixel_read_end.

Types#

Texture_Filterenumsince 0.31.0
:: enum

How a texture is sampled when drawn larger or smaller than its size.

Simp_Contextstructsince 0.31.0
:: struct

Per-context Simp settings, read as context.simp.

Font_Quadstruct
:: struct

One glyph of prepared text: where it goes, the part of the glyph atlas it shows and its tint.

Constants#