gfx

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package gfx provides APIs for shaders, VAO creation, and text rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alpha

func Alpha() (alpha float32)

Alpha returns the current alpha amount.

func InitProgram

func InitProgram() error

InitProgram loads and uses the shader program.

func SetAlpha

func SetAlpha(alpha float32)

SetAlpha sets the alpha amount.

func SetModelMatrixRect

func SetModelMatrixRect(r image.Rectangle)

SetModelMatrixRect sets the model matrix to the rectangle.

func SetModelMatrixRotatedRect

func SetModelMatrixRotatedRect(r image.Rectangle, radians float32)

SetModelMatrixRotatedRect sets the model matrix to the rotated rectangle.

func SetProjectionViewMatrix

func SetProjectionViewMatrix(m matrix.Matrix4)

SetProjectionViewMatrix sets the projection view matrix.

func TextRenderMaxWidth added in v1.1.0

func TextRenderMaxWidth(w int) func(s *textRenderSettings)

TextRenderMaxWidth is an option

Types

type TextColor

type TextColor [3]float32

TextColor is a RGB color of 3 floats from 0.0 to 1.0.

type TextRenderOpt added in v1.1.0

type TextRenderOpt func(f *textRenderSettings)

TextRenderOpt is an option to pass to Render.

type TextRenderer

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

A TextRenderer measures and renders text. It is designed to render single lines of [A-Z0-9] characters.

func NewTextRenderer

func NewTextRenderer(ttfBytes []byte, size int) *TextRenderer

NewTextRenderer creates a new TextRenderer from a TTF font file and a size.

func (*TextRenderer) LineHeight

func (t *TextRenderer) LineHeight() int

LineHeight returns the line height. Useful for measurements.

func (*TextRenderer) Measure

func (t *TextRenderer) Measure(text string) image.Point

Measure returns an image.Point with the width and height of the given text.

func (*TextRenderer) Render

func (t *TextRenderer) Render(text string, pt image.Point, color TextColor, opts ...TextRenderOpt) (dx int)

Render renders color text at the given point that points at the origin (baseline).

type VAO

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

VAO is a Vertex Array Object for one element type (lines, triangles, etc).

func EmptyVAO

func EmptyVAO() *VAO

EmptyVAO creates an empty VAO that doesn't render anything.

func NewVAO

func NewVAO(data *VAOVertexData) *VAO

NewVAO creates a VAO with the given vertex data.

Since NewVAO defers the creation of the actual OpenGL VAO till the first rendering, callers may call NewVAO at the package scope to simplify code.

func NewVAOLoadData

func NewVAOLoadData(loadData func() *VAOVertexData) *VAO

NewVAOLoadData creates a VAO with a data loader function that provides vertex data.

Use this over NewVAO at the package scope if loading the vertex data requires flags to be parsed or some other requirement.

func PLYVAO

func PLYVAO(plyReader io.Reader) *VAO

PLYVAO returns a VAO decoded from a PLY Reader.

func TexturedPLYVAO

func TexturedPLYVAO(plyReader, texturedReader io.Reader) *VAO

TexturedPLYVAO returns a VAO decoded from a PLY Reader and a texture from another Reader.

func (*VAO) Delete

func (v *VAO) Delete()

Delete deletes the VAO. Don't call Render after calling this.

func (*VAO) Render

func (v *VAO) Render()

Render renders the VAO.

type VAODrawMode

type VAODrawMode int

VAODrawMode is analogous to the mode argument to gl.DrawElements.

const (
	Triangles VAODrawMode = gl.TRIANGLES
	Lines                 = gl.LINES
)

Enum values for VAODrawMode.

type VAOVertexData

type VAOVertexData struct {
	// Mode is the mode like triangles or lines.
	Mode VAODrawMode

	// Vertices is a required slice of flattened (x, y, z) vertices.
	Vertices []float32

	// TexCoords is an optional slice of flattened (s, t) coords.
	TexCoords []float32

	// Colors is an optional slice of flattened (r, g, b) values.
	Colors []float32

	// Indices is a required slice of indices into all the buffers.
	Indices []uint16

	// TextureRGBA is the optional texture to use.
	TextureRGBA *image.RGBA
}

VAOVertexData is a bunch of slices filled with vertex data to create a VAO.

Jump to

Keyboard shortcuts

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