gfx

package
v0.2.66 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gfx is a thin abstraction layer for OpenGL.

Index

Constants

This section is empty.

Variables

View Source
var AtInit []func()

AtInit is a slice of functions called at graphics context initialization.

View Source
var (
	// FrameSync is an internal variable.
	FrameSync = make(chan chan struct{}, 1)
)

GL is the OpenGL context.

Functions

func AddInit

func AddInit(f func()) struct{}

AddInit appends a function to AtInit and returns an empty struct.

func Init

func Init(ctx gl.Context)

Init is an internal function that sets up the context and then calls the functions in AtInit.

func MustLink(shaders ...gl.Shader) gl.Program

MustLink links a shader program or panics.

func MustShader

func MustShader(ty gl.Enum, source string) gl.Shader

MustShader compiles a shader or panics.

func NextFrame

func NextFrame()

NextFrame synchronizes a frame boundary.

func SetSize

func SetSize(w, h int)

SetSize is an internal function.

func Size

func Size() (int, int)

Size returns the current screen size.

Types

type Camera

type Camera struct {
	Offset      Matrix
	Rotation    Matrix
	Position    Matrix
	Perspective Matrix
	// contains filtered or unexported fields
}

Camera tracks the position and orientation of the 3D camera.

func (*Camera) Combined

func (c *Camera) Combined() Matrix

Combined returns the combined transformation matrix.

func (*Camera) PopTransform

func (c *Camera) PopTransform()

PopTransform removes the last transform added via PushTransform.

func (*Camera) PushTransform

func (c *Camera) PushTransform(m Matrix)

PushTransform adds a transform to the transform stack.

func (*Camera) SetDefaults

func (c *Camera) SetDefaults()

SetDefaults sets the Matrix fields in Camera to default values.

type Matrix

type Matrix [16]float32

Matrix is a 4x4 transformation matrix.

func Identity

func Identity() Matrix

Identity returns the identity matrix.

func MultiplyMatrix

func MultiplyMatrix(m0, m1 Matrix) Matrix

MultiplyMatrix multiplies a matrix by a matrix.

func Perspective

func Perspective(fov, aspect, nearZ, farZ float32) Matrix

Perspective constructs a perspective matrix.

func RotationX

func RotationX(r float32) Matrix

RotationX constructs a rotation matrix over the X axis.

func RotationY

func RotationY(r float32) Matrix

RotationY constructs a rotation matrix over the Y axis.

func RotationZ

func RotationZ(r float32) Matrix

RotationZ constructs a rotation matrix over the Z axis.

func Scale

func Scale(x, y, z float32) Matrix

Scale constructs a scaling matrix.

func Translation

func Translation(x, y, z float32) Matrix

Translation constructs translation matrix.

type StaticBuffer

type StaticBuffer struct {
	Data    gl.Buffer
	Element gl.Buffer
	Count   int
}

StaticBuffer is a convenience layer for OpenGL vertex buffer objects.

var (
	// Square is a StaticBuffer containing vertices for a square.
	Square *StaticBuffer
)

func NewStaticBuffer

func NewStaticBuffer(data []uint8, elements []uint16) *StaticBuffer

NewStaticBuffer creates a StaticBuffer.

func (*StaticBuffer) Delete

func (sb *StaticBuffer) Delete()

Delete frees the resources held by the StaticBuffer.

type Vector

type Vector [4]float32

Vector is a 4-component geometric vector of (x, y, z, 1).

func MultiplyVector

func MultiplyVector(m Matrix, v Vector) Vector

MultiplyVector multiplies a matrix by a vector.

Jump to

Keyboard shortcuts

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