structVec3
struct Vec3
x: float
y: float
z: float
endg3d: 3D drawing with a camera, lights, fog, textures and meshes, on top of gfx. use "g3d.jamo"
g3d draws into gfx's picture, which has a depth buffer, so 2D drawing like text can go on top afterward. It switches OpenGL to its own settings when it draws, and gfx switches them back. A mesh is a list of triangles, each corner 8 floats: place x, y and z, the normal's x, y and z, and the texture spot's u and v. Matrices are 16 32-bit floats, a column at a time, as OpenGL takes them.
struct Vec3
x: float
y: float
z: float
endstruct Mesh
vertex_array: int
buffer: int
count: int
open: bool
endstruct Texture
id: int
width: int
height: int
open: bool
endstruct G3d
gfx: Gfx
shader: int
places: [int]
eye: Vec3
target: Vec3
field: float
near: float
far: float
sun_direction: Vec3
sun_color: Color
ambient_color: Color
fog_color: Color
fog_start: float
fog_end: float
fog_on: bool
lamp_places: [Vec3]
lamp_colors: [Color]
lamp_reaches: [float]
changed: bool
seen_width: int
seen_height: int
matrices: int
white: Texture
meshes: [Mesh]
textures: [Texture]
open: bool
closed_by_program: bool
endfunc vec3(x: float, y: float, z: float): Vec3
func start_3d(g: Gfx): G3d
func G3d.must_be_open()
func G3d.enter()
Switches OpenGL to g3d's settings, after drawing what gfx has waiting
func G3d.camera(eye: Vec3, target: Vec3)
Puts the camera at eye, looking at target
func G3d.lens(field: float, near: float, far: float)
How wide the camera sees, in degrees, and the nearest and farthest it draws
func G3d.sun(direction: Vec3, color: Color)
Sunlight shining in a direction, like vec3(0.0, -1.0, 0.0) for straight down
func G3d.ambient(color: Color)
The light that reaches everything, even in shade
func G3d.lamp(number: int, place: Vec3, color: Color, reach: float)
One of 4 lamps, 0 to 3, lighting things nearer than reach
func G3d.lamp_off(number: int)
func G3d.fog(color: Color, start: float, end_at: float)
Things fade into the fog color from start to end, counting from the camera
func G3d.no_fog()
func G3d.send_scene()
Sends the camera, lights and fog to the graphics card, when they've changed
func G3d.draw(mesh: Mesh, place: Vec3, turn: Vec3, size: Vec3, color: Color)
Draws a mesh at a place, turned by degrees around x, y and z, and stretched by size
func G3d.draw_textured(mesh: Mesh, texture: Texture, place: Vec3, turn: Vec3, size: Vec3)
func G3d.draw_with(mesh: Mesh, texture: Texture, place: Vec3, turn: Vec3, size: Vec3, color: Color)
func g3d_set(matrix: int, row: int, column: int, value: float)
func g3d_get(matrix: int, row: int, column: int): float
func g3d_clear(matrix: int)
func g3d_multiply(result: int, a: int, b: int)
func g3d_normalize(v: Vec3): Vec3
func g3d_cross(a: Vec3, b: Vec3): Vec3
func g3d_look(matrix: int, eye: Vec3, target: Vec3)
The camera's matrix. Looking straight up or down, the top of the screen points along -z or +z
func g3d_perspective(matrix: int, field: float, aspect: float, near: float, far: float)
func g3d_model(model: int, normals: int, place: Vec3, turn: Vec3, size: Vec3)
Moves, turns (around y, then x, then z) and stretches. The normals turn the same way but stretch the other way, so lighting stays right on stretched meshes
func g3d_column(model: int, normals: int, column: int, x: float, y: float, z: float, stretch: float)
One turned column of both matrices, stretched one way for the model and the other for normals
func G3d.mesh(points: [float]): Mesh
A mesh from triangles: every 3 corners make one, and each corner is 8 floats (see the top)
func G3d.make_mesh(data: int, count: int): Mesh
func Mesh.close()
func g3d_corner(points: [float], x: float, y: float, z: float, nx: float, ny: float, nz: float, u: float, v: float)
func g3d_side(points: [float], c: Vec3, a: Vec3, b: Vec3, n: Vec3)
One side of a cube, as two triangles: a corner, then the two directions across the side
func G3d.cube(): Mesh
A cube 1 wide, centered on its place
func G3d.plane(tiles: float): Mesh
A flat square 1 wide on the ground, facing up, with its texture repeated tiles times each way
func G3d.sphere(detail: int): Mesh
A ball 1 wide. More detail makes it rounder, from 3 to 64
func G3d.load_texture(path: string): Texture
Loads a PNG picture to wrap onto meshes. It repeats past the edges
func G3d.make_texture(pixels: int, width: int, height: int): Texture
func Texture.close()
func g3d_bad_obj(path: string, line: int, why: string)
func g3d_number(data: string, place: int, finish: int, path: string, line: int): float
Reads a number written from place up to finish, like 12, -0.5 or 1.5e-3
func g3d_part(words: string, from: int, to: int): string
func g3d_index(data: string, place: int, finish: int, count: int, kind: string, path: string, line: int): int
One face corner's number for a list of this many, counting from 1, or from the end when below 0
func G3d.load_obj(path: string): Mesh
Reads an OBJ model: its points (v), texture spots (vt), normals (vn) and faces (f). Faces with more than 3 corners are cut into triangles, and faces without normals get flat ones
func G3d.close()