gfx.jamo (built in)

gfx: 2D drawing in a window, with OpenGL 3.3. use "gfx.jamo"

Shapes, text and pictures collect in a batch and go to the graphics card together. Everything draws into a picture the size of the window first, which show() copies onto the window. Rectangles, circles, lines and text all come from one texture, the atlas, so they can share a batch: letters from the Segoe UI font fill the top in cells 40 wide and 48 tall, with a soft circle and a white square below them. Each letter starts 4 pixels down its cell, so its lowest parts stay clear of the letter below when text is drawn small.

structColor

struct Color
    red: float
    green: float
    blue: float
    alpha: float
end

funcrgb

func rgb(red: int, green: int, blue: int): Color

Colors take numbers from 0 to 255, like most paint programs

funcrgba

func rgba(red: int, green: int, blue: int, alpha: int): Color

structImage

struct Image
    texture: int
    width: int
    height: int
    open: bool
end

structGfx

struct Gfx
    window: Window
    dc: int
    context: int
    shader: int
    screen_place: int
    vertex_array: int
    vertex_buffer: int
    atlas: int
    glyph_widths: int
    batch: int
    vertices: int
    texture: int
    framebuffer: int
    color_buffer: int
    depth_buffer: int
    in_3d: bool
    width: int
    height: int
    images: [Image]
    open: bool
    closed_by_program: bool
end

funcstart_gfx

func start_gfx(window: Window): Gfx

funcgfx_c_text

func gfx_c_text(text: string): int

--- Setting up ---

funcgfx_compile

func gfx_compile(kind: int, source: string): int

funcGfx.make_shader

func Gfx.make_shader()

funcGfx.make_buffers

func Gfx.make_buffers()

funcgfx_texture

func gfx_texture(pixels: int, width: int, height: int, smooth: bool): int

funcGfx.make_atlas

func Gfx.make_atlas()

Windows draws each letter once, white on black, and the red of each pixel becomes how solid it is

funcGfx.fit_window

func Gfx.fit_window()

Makes the drawing picture match the window's size

funcGfx.must_be_open

func Gfx.must_be_open()

--- The batch ---

funcGfx.flush

func Gfx.flush()

funcGfx.vertex

func Gfx.vertex(x: float, y: float, u: float, v: float, color: Color)

funcGfx.back_to_2d

func Gfx.back_to_2d()

3D drawing (g3d.jamo) changes OpenGL's settings, so 2D drawing puts its own back first

funcGfx.use_texture

func Gfx.use_texture(texture: int)

funcGfx.quad

func Gfx.quad(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, x4: float, y4: float, u1: float, v1: float, u2: float, v2: float, color: Color)

Four corners, going around, with the texture's corners matching

funcGfx.clear

func Gfx.clear(color: Color)

--- Drawing ---

funcGfx.rect

func Gfx.rect(x: float, y: float, width: float, height: float, color: Color)

funcGfx.circle

func Gfx.circle(x: float, y: float, radius: float, color: Color)

funcGfx.line

func Gfx.line(x1: float, y1: float, x2: float, y2: float, thickness: float, color: Color)

funcGfx.text_width

func Gfx.text_width(words: string, size: float): float

funcGfx.text

func Gfx.text(words: string, x: float, y: float, size: float, color: Color)

size is the letters' height in pixels. Only English letters and symbols show

funcGfx.load_image

func Gfx.load_image(path: string): Image

funcGfx.image

func Gfx.image(image: Image, x: float, y: float)

funcGfx.image_sized

func Gfx.image_sized(image: Image, x: float, y: float, width: float, height: float)

funcGfx.load_pixel_image

func Gfx.load_pixel_image(path: string): Image

Like load_image, but each pixel stays a sharp square when it's drawn bigger, which pixel art wants

funcGfx.image_from_text

func Gfx.image_from_text(rows: [string], colors: [Color]): Image

Pixel art written as text, one row of letters per line, all the same length. 0 to 9 and then a to z pick a color from colors, in order, and . or a space is see-through. The pixels stay sharp when drawn bigger:

var heart = screen.image_from_text([".11.11.", "1111111", ".11111.", "..111.."], [rgb(230, 50, 70)])

funcgfx_byte

func gfx_byte(value: float): int

funcGfx.image_part

func Gfx.image_part(image: Image, part_x: int, part_y: int, part_width: int, part_height: int, x: float, y: float, width: float, height: float)

Draws the part of an image from (part_x, part_y), part_width by part_height pixels, at x, y and width by height. A sprite sheet keeps many frames in one image this way

funcGfx.image_part_turned

func Gfx.image_part_turned(image: Image, part_x: int, part_y: int, part_width: int, part_height: int, center_x: float, center_y: float, width: float, height: float, angle: float, flipped: bool)

Like image_part, but around its middle at center_x, center_y, turned by angle (in radians, clockwise on the screen), and mirrored left to right when flipped is true, for something that faces the other way

funcGfx.image_turned

func Gfx.image_turned(image: Image, center_x: float, center_y: float, width: float, height: float, angle: float, flipped: bool)

The whole image around its middle, turned and maybe mirrored

funcImage.close

func Image.close()

funcGfx.show

func Gfx.show()

Puts this frame on the window

funcGfx.read_pixel

func Gfx.read_pixel(x: int, y: int): Color

funcGfx.save_bmp

func Gfx.save_bmp(path: string)

Saves what's drawn so far as a BMP picture

funcGfx.close

func Gfx.close()