rasterion

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 5 Imported by: 0

README

rasterion

Package rasterion is a rasterization library for rendering 2D and 3D graphics to the terminal.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StaticShader = func(uv gl.Vec3) emu.Glyph {
	c := emu.EmptyGlyph()
	c.Char = '*'
	return c
}

Functions

func Interpolate

func Interpolate(bary gl.Vec3, v0, v1, v2 float32) float32

func InterpolateVec2

func InterpolateVec2(bary gl.Vec3, v0, v1, v2 gl.Vec2) gl.Vec2

func IntersectLine added in v1.6.0

func IntersectLine(p0, p1, p2, p3 gl.Vec2) (
	intersection gl.Vec2,
	intersects bool,
)

IntersectLine calculates the intersections of two lines, each of which is defined by two points. `intersects` is true if and only if the intersection of the two lines falls on those lines. In other words, the lines are treated as being of finite length.

func Sample2D

func Sample2D(texture image.Image, uv gl.Vec2) emu.Glyph

Sample2D samples a texture at the given coordinate. The members of `uv` should be in the range [0..1].

Types

type Camera

type Camera struct {
	View, Projection gl.Mat4
	// contains filtered or unexported fields
}

func NewCamera

func NewCamera(size geom.Vec2) *Camera

func (*Camera) Transform

func (c *Camera) Transform(in gl.Vec3) gl.Vec4

func (*Camera) UnProject

func (c *Camera) UnProject(in gl.Vec3) (gl.Vec3, error)

Project transforms the given point in screen-space into world-space.

func (*Camera) Viewport

func (c *Camera) Viewport() geom.Vec2

type Context

type Context struct {
	// contains filtered or unexported fields
}

func New

func New(size geom.Size) *Context

func (*Context) Camera

func (c *Context) Camera() *Camera

func (*Context) Clear

func (c *Context) Clear()

func (*Context) ClearZBuffer added in v1.6.0

func (c *Context) ClearZBuffer()

func (*Context) Image

func (c *Context) Image() image.Image

func (*Context) Line added in v1.6.0

func (c *Context) Line(s LineShader, v0, v1 gl.Vec3)

Line draws a line in world space from v0 to v1 using the given shader.

func (*Context) Lines added in v1.6.0

func (c *Context) Lines(
	s LineShader,
	verts []gl.Vec3,
	segments [][2]int,
)

Lines draws multiple line segments in world space using the given shader.

func (*Context) Resize

func (c *Context) Resize(size geom.Vec2)

func (*Context) SetTarget added in v1.6.0

func (c *Context) SetTarget(i image.Image)

func (*Context) Size added in v1.6.0

func (c *Context) Size() geom.Vec2

func (*Context) Triangle

func (c *Context) Triangle(s Shader, v0, v1, v2 gl.Vec3)

func (*Context) TriangleStrip

func (c *Context) TriangleStrip(s Shader, vertices []gl.Vec3)

func (*Context) Triangles

func (c *Context) Triangles(
	s Shader,
	verts []gl.Vec3,
	faces [][3]int,
)

type DefaultFragmentShader added in v1.6.0

type DefaultFragmentShader struct{}

func (DefaultFragmentShader) Fragment added in v1.6.0

func (f DefaultFragmentShader) Fragment(
	i0, i1, i2 int,
	bary gl.Vec3,
) (glyph emu.Glyph, discard bool)

type DefaultLineFragmentShader added in v1.6.0

type DefaultLineFragmentShader struct{}

func (DefaultLineFragmentShader) Fragment added in v1.6.0

func (f DefaultLineFragmentShader) Fragment(
	gl_FragCoord gl.Vec3,
	i0, i1 int,
	v0, v1 gl.Vec2,
	t float32,
) (glyph emu.Glyph, discard bool)

type DefaultVertexShader

type DefaultVertexShader struct{}

func (DefaultVertexShader) Vertex

func (v DefaultVertexShader) Vertex(
	camera *Camera, face, index int, vertex gl.Vec3,
) gl.Vec4

type Drawable

type Drawable interface {
	Draw(c *Context)
}

type FragmentShader

type FragmentShader interface {
	Fragment(
		i0, i1, i2 int,
		bary gl.Vec3,
	) (glyph emu.Glyph, discard bool)
}

type LineFragmentShader added in v1.6.0

type LineFragmentShader interface {
	Fragment(
		gl_FragCoord gl.Vec3,
		i0, i1 int,
		v0, v1 gl.Vec2,
		t float32,
	) (glyph emu.Glyph, discard bool)
}

type LineShader added in v1.6.0

type LineShader interface {
	VertexShader
	LineFragmentShader
}

type NoopVertexShader added in v1.6.0

type NoopVertexShader struct{}

func (*NoopVertexShader) Vertex added in v1.6.0

func (v *NoopVertexShader) Vertex(
	camera *Camera, face, index int, vertex gl.Vec3,
) gl.Vec4

type Rect

type Rect struct {
	Pos  gl.Vec2
	Size gl.Vec2
}

func (Rect) Contains added in v1.6.0

func (r Rect) Contains(other gl.Vec2) bool

Contains reports whether a Rect contains the given point.

func (Rect) Intersections added in v1.6.0

func (r Rect) Intersections(p0, p1 gl.Vec2) (
	i0, i1 gl.Vec2,
	intersects bool,
	numIntersections int,
)

func (Rect) Overlaps

func (r Rect) Overlaps(other Rect) bool

Overlaps reports whether two Rects overlap.

type Shader

type Shader interface {
	VertexShader
	FragmentShader
}

type TransformShader

type TransformShader struct {
	M gl.Mat4
}

func (TransformShader) Transform

func (t TransformShader) Transform(v gl.Vec3) gl.Vec4

func (TransformShader) Vertex

func (t TransformShader) Vertex(
	camera *Camera, face, index int, vertex gl.Vec3,
) gl.Vec4

type VertexShader

type VertexShader interface {
	Vertex(camera *Camera, face, index int, vertex gl.Vec3) gl.Vec4
}

Directories

Path Synopsis
subcell
NOTE: This file was generated by gen.py.
NOTE: This file was generated by gen.py.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL