Documentation ¶
Index ¶
- Constants
- Variables
- func AddKeyboardListener(listener KeyboardListener)
- func AddLoader(loader ResLoader) bool
- func AddMouseListener(listener MouseListener)
- func AddScene(scene Scene) bool
- func AddSystem(system System) bool
- func CheckGLError()
- func ClearColorBuffer(do bool)
- func ClearDepthBuffer(do bool)
- func CreateCubeMesh() (*VBO, *VBO, *VBO)
- func CreateRectMesh(flip bool) (*VBO, *VBO, *VBO)
- func DistanceVec2(a, b Vec2) float64
- func DistanceVec3(a, b Vec3) float64
- func DistanceVec4(a, b Vec4) float64
- func Drop(objects []Dropable)
- func EnableAlphaBlending(enable bool)
- func EnableDepthTest(enable bool)
- func GetHeight() int
- func GetWidth() int
- func LoadResFromFolder(path string) error
- func NewFBOWithTex2D(width, height, filter int32) (*FBO, *Tex)
- func RemoveActor(actor *Actor) bool
- func RemoveActorById(id ActorId) bool
- func RemoveAllKeyboardListener()
- func RemoveAllLoaders()
- func RemoveAllMouseListener()
- func RemoveAllRes()
- func RemoveAllScenes()
- func RemoveAllSystems()
- func RemoveKeyboardListener(listener KeyboardListener)
- func RemoveLoader(loader ResLoader) bool
- func RemoveLoaderByExt(ext string) bool
- func RemoveMouseListener(listener MouseListener)
- func RemoveResByName(name string) bool
- func RemoveResByPath(path string) bool
- func RemoveScene(scene Scene) bool
- func RemoveSystem(system System) bool
- func Run(game Game, options *RunOptions)
- func SetClearColor(r, g, b, a float64)
- func SetViewport(x, y, width, height int32)
- func Stop()
- func SwitchScene(scene Scene)
- func SwitchSceneByName(name string) bool
- type Actor
- type ActorId
- type AnimatedSprite
- type Camera
- type Cullable
- type Culling2D
- func (c *Culling2D) Add(actor *Actor, pos *Pos2D) bool
- func (c *Culling2D) Cleanup()
- func (c *Culling2D) GetName() string
- func (c *Culling2D) Len() int
- func (c *Culling2D) Remove(actor *Actor) bool
- func (c *Culling2D) RemoveAll()
- func (c *Culling2D) RemoveById(id ActorId) bool
- func (c *Culling2D) SetViewport(x, y, width, height int)
- func (c *Culling2D) Update(delta float64)
- type Dropable
- type FBO
- func (f *FBO) Bind()
- func (f *FBO) ClearAttachments()
- func (f *FBO) Complete() bool
- func (f *FBO) DrawBuffer(mode uint32)
- func (f *FBO) DrawBuffers(mode uint32)
- func (f *FBO) Drop()
- func (f *FBO) GetId() uint32
- func (f *FBO) GetStatus() uint32
- func (f *FBO) GetTarget() uint32
- func (f *FBO) ReadBuffer(mode uint32)
- func (f *FBO) Texture(attachment, texId uint32, level int32)
- func (f *FBO) Texture1D(attachment, texId uint32, level int32)
- func (f *FBO) Texture2D(attachment, texId uint32, level int32)
- func (f *FBO) Texture3D(attachment, texId uint32, level, layer int32)
- func (f *FBO) Unbind()
- type Font
- type Game
- type KeyboardListener
- type Keyframe
- type KeyframeAnimation
- type KeyframeRenderer
- func (s *KeyframeRenderer) Add(actor *Actor, pos *Pos2D, tex *Tex, set *KeyframeSet, ...) bool
- func (s *KeyframeRenderer) Cleanup()
- func (s *KeyframeRenderer) GetName() string
- func (s *KeyframeRenderer) Len() int
- func (s *KeyframeRenderer) Remove(actor *Actor) bool
- func (s *KeyframeRenderer) RemoveAll()
- func (s *KeyframeRenderer) RemoveById(id ActorId) bool
- func (s *KeyframeRenderer) Update(delta float64)
- type KeyframeSet
- type Mat3
- func (m *Mat3) Clear()
- func (m *Mat3) Copy() *Mat3
- func (m *Mat3) Determinate() float64
- func (m *Mat3) Identity()
- func (m *Mat3) Inverse()
- func (m *Mat3) Mult(mat *Mat3)
- func (m *Mat3) MultVec(v Vec3) Vec3
- func (m *Mat3) Ortho(viewport Vec4)
- func (m *Mat3) Rotate(angle float64)
- func (m *Mat3) Scale(v Vec2)
- func (m *Mat3) Translate(v Vec2)
- func (m *Mat3) Transpose()
- type Mat4
- func (m *Mat4) Clear()
- func (m *Mat4) Copy() *Mat4
- func (m *Mat4) Determinate() float64
- func (m *Mat4) Identity()
- func (m *Mat4) Inverse()
- func (m *Mat4) LookAt(pos, lookAt, up Vec3)
- func (m *Mat4) Mult(mat *Mat4)
- func (m *Mat4) MultVec(v Vec3) Vec3
- func (m *Mat4) Ortho(viewport Vec4, znear, zfar float64)
- func (m *Mat4) Perspective(fov, ratio, znear, zfar float64)
- func (m *Mat4) Rotate(angle float64, axis Vec3)
- func (m *Mat4) Scale(v Vec3)
- func (m *Mat4) Translate(v Vec3)
- func (m *Mat4) Transpose()
- type Mesh
- type Model
- type ModelRenderer
- func (s *ModelRenderer) Add(actor *Actor, pos *Pos3D, tex *Tex, mesh *Mesh) bool
- func (s *ModelRenderer) Cleanup()
- func (s *ModelRenderer) GetName() string
- func (s *ModelRenderer) Len() int
- func (s *ModelRenderer) Prepare(model *Model)
- func (s *ModelRenderer) Remove(actor *Actor) bool
- func (s *ModelRenderer) RemoveAll()
- func (s *ModelRenderer) RemoveById(id ActorId) bool
- func (s *ModelRenderer) Update(delta float64)
- type MouseListener
- type Ply
- type PlyLoader
- type PngLoader
- type Pos2D
- type Pos3D
- type Res
- type ResLoader
- type ResizeCallback
- type RunOptions
- type Scene
- type Shader
- func (s *Shader) Bind()
- func (s *Shader) BindAttrib(name string)
- func (s *Shader) BindAttribIndex(name string, index uint32)
- func (s *Shader) DisableVertexAttribArrays()
- func (s *Shader) Drop()
- func (s *Shader) EnableVertexAttribArrays()
- func (s *Shader) GetAttribLocation(name string) int32
- func (s *Shader) GetFragmentId() uint32
- func (s *Shader) GetProgramId() uint32
- func (s *Shader) GetUniformLocation(name string) int32
- func (s *Shader) GetVertexId() uint32
- func (s *Shader) SendMat3(name string, m Mat3)
- func (s *Shader) SendMat4(name string, m Mat4)
- func (s *Shader) SendUniform1f(name string, v float32)
- func (s *Shader) SendUniform1fv(name string, count int32, data *float32)
- func (s *Shader) SendUniform1i(name string, v int32)
- func (s *Shader) SendUniform1iv(name string, count int32, data *int32)
- func (s *Shader) SendUniform2f(name string, v0, v1 float32)
- func (s *Shader) SendUniform2fv(name string, count int32, data *float32)
- func (s *Shader) SendUniform2i(name string, v0, v1 int32)
- func (s *Shader) SendUniform2iv(name string, count int32, data *int32)
- func (s *Shader) SendUniform2x2(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform2x3(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform2x4(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform3f(name string, v0, v1, v2 float32)
- func (s *Shader) SendUniform3fv(name string, count int32, data *float32)
- func (s *Shader) SendUniform3i(name string, v0, v1, v2 int32)
- func (s *Shader) SendUniform3iv(name string, count int32, data *int32)
- func (s *Shader) SendUniform3x2(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform3x3(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform3x4(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform4f(name string, v0, v1, v2, v3 float32)
- func (s *Shader) SendUniform4fv(name string, count int32, data *float32)
- func (s *Shader) SendUniform4i(name string, v0, v1, v2, v3 int32)
- func (s *Shader) SendUniform4iv(name string, count int32, data *int32)
- func (s *Shader) SendUniform4x2(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform4x3(name string, data *float32, count int32, transpose bool)
- func (s *Shader) SendUniform4x4(name string, data *float32, count int32, transpose bool)
- func (s *Shader) Unbind()
- type Sprite
- type SpriteRenderer
- func (s *SpriteRenderer) Add(actor *Actor, pos *Pos2D, tex *Tex) bool
- func (s *SpriteRenderer) Cleanup()
- func (s *SpriteRenderer) GetName() string
- func (s *SpriteRenderer) Len() int
- func (s *SpriteRenderer) Remove(actor *Actor) bool
- func (s *SpriteRenderer) RemoveAll()
- func (s *SpriteRenderer) RemoveById(id ActorId) bool
- func (s *SpriteRenderer) Update(delta float64)
- type System
- type Tex
- func (t *Tex) Bind()
- func (t *Tex) Drop()
- func (t *Tex) GetExt() string
- func (t *Tex) GetId() uint32
- func (t *Tex) GetName() string
- func (t *Tex) GetPath() string
- func (t *Tex) GetRGBA() *image.RGBA
- func (t *Tex) GetSize() Vec3
- func (t *Tex) GetTarget() uint32
- func (t *Tex) Parameterf(name uint32, param float32)
- func (t *Tex) Parameteri(name uint32, param int32)
- func (t *Tex) SetActiveTexture(activeTexture uint32)
- func (t *Tex) SetDefaultParams(filter int32)
- func (t *Tex) SetExt(ext string)
- func (t *Tex) SetName(name string)
- func (t *Tex) SetPath(path string)
- func (t *Tex) SetRGBA(rgba *image.RGBA)
- func (t *Tex) Texture1D(level, internalFormat, width int32, format, ttype uint32, data []uint8)
- func (t *Tex) Texture2D(level, internalFormat, width, height int32, format, ttype uint32, data []uint8)
- func (t *Tex) Texture3D(level, internalFormat, width, height, depth int32, format, ttype uint32, ...)
- func (t *Tex) Unbind()
- type Text
- type TextComponent
- type TextRenderer
- func (r *TextRenderer) Add(actor *Actor, pos *Pos2D, text *TextComponent) bool
- func (r *TextRenderer) Cleanup()
- func (r *TextRenderer) GetName() string
- func (r *TextRenderer) Len() int
- func (r *TextRenderer) Prepare(text *Text)
- func (r *TextRenderer) Remove(actor *Actor) bool
- func (r *TextRenderer) RemoveAll()
- func (r *TextRenderer) RemoveById(id ActorId) bool
- func (r *TextRenderer) Update(delta float64)
- type VAO
- type VBO
- func (v *VBO) AttribPointer(attribLocation int32, size int32, btype uint32, normalized bool, stride int32)
- func (v *VBO) Bind()
- func (v *VBO) Drop()
- func (v *VBO) Fill(data unsafe.Pointer, elements, size int, use uint32)
- func (v *VBO) GetId() uint32
- func (v *VBO) GetTarget() uint32
- func (v *VBO) Size() int32
- func (v *VBO) Unbind()
- func (v *VBO) Update(data unsafe.Pointer, elements, offset, size int)
- type Vec2
- type Vec3
- func (v *Vec3) Add(vec Vec3)
- func (v *Vec3) Copy() Vec3
- func (v *Vec3) Cross(vec Vec3)
- func (v *Vec3) Div(vec Vec3)
- func (v *Vec3) Dot() float64
- func (v *Vec3) DotVec(vec Vec3) float64
- func (v *Vec3) Length() float64
- func (v *Vec3) Mult(vec Vec3)
- func (v *Vec3) Normalize()
- func (v *Vec3) Sub(vec Vec3)
- type Vec4
Constants ¶
const ( // constants for default 2D shader Default_shader_2D_vertex_attrib = "vertex" Default_shader_2D_texcoord_attrib = "texCoord" Default_shader_2D_ortho = "o" Default_shader_2D_model = "m" Default_shader_2D_tex = "tex" // constants for default 3D shader Default_shader_3D_vertex_attrib = "vertex" Default_shader_3D_texcoord_attrib = "texCoord" Default_shader_3D_pv = "pv" Default_shader_3D_model = "m" Default_shader_3D_tex = "tex" // constants for default text shader Default_shader_text_vertex_attrib = "vertex" Default_shader_text_texcoord_attrib = "texCoord" Default_shader_text_ortho = "o" Default_shader_text_model = "m" Default_shader_text_tex = "tex" Default_shader_text_color = "color" )
const NullTerminator = "\x00"
Variables ¶
var ( // Default resources DefaultCamera *Camera Default2DShader *Shader Default3DShader *Shader DefaultTextShader *Shader )
Functions ¶
func AddKeyboardListener ¶
func AddKeyboardListener(listener KeyboardListener)
Adds a new keyboard listener.
func AddLoader ¶
Adds a loader. If a loader with the same file extension exists already, false will be returned.
func AddScene ¶
Adds a scene to game. Returns false if the scene exists already. The first scene added will be set active.
func ClearColorBuffer ¶
func ClearColorBuffer(do bool)
Adds color buffer to list of buffers to be cleared. If parameter is false, it will be removed.
func ClearDepthBuffer ¶
func ClearDepthBuffer(do bool)
Adds depth buffer to list of buffers to be cleared. If parameter is false, it will be removed.
func CreateCubeMesh ¶
Creates three VBOs for a 3D cube mesh. Texture coordinates won't map properly. This function is supposed to be used for 3D testing.
func CreateRectMesh ¶
Creates three VBOs for a 2D rectangle.
func DistanceVec2 ¶
Returns the distance between two 2D vectors.
func DistanceVec3 ¶
Returns the distance between two 3D vectors.
func DistanceVec4 ¶
Returns the distance between two 4D vectors.
func Drop ¶
func Drop(objects []Dropable)
Drops given GL objects. Objects must implement the Dropable interface.
func EnableAlphaBlending ¶
func EnableAlphaBlending(enable bool)
Enables/Disables alpha blending by source alpha channel. BLEND = SRC_ALPHA | ONE_MINUS_SRC_ALPHA
func LoadResFromFolder ¶
Loads all files from given folder path. If a loader is missing or fails to load the resource, an error will be returned. All resources will be kept until an error occures.
func NewFBOWithTex2D ¶
Creates a new FBO with given target and 2D texture. Used to render to texture.
func RemoveActor ¶
Removes an actor from all systems. This maybe not as performant as directly removing it from the right system. Returns true if it could be removed from at least one system, else false.
func RemoveActorById ¶
Removes an actor from all systems by ID. This maybe not as performant as directly removing it from the right system. Returns true if it could be removed from at least one system, else false.
func RemoveAllKeyboardListener ¶
func RemoveAllKeyboardListener()
Removes all registered keyboard listeners.
func RemoveKeyboardListener ¶
func RemoveKeyboardListener(listener KeyboardListener)
Removes given keyboard listener if found.
func RemoveLoader ¶
Removes a loader. Returns false if loader could not be found.
func RemoveLoaderByExt ¶
Removes a loader by file extension. Returns false if loader could not be found.
func RemoveMouseListener ¶
func RemoveMouseListener(listener MouseListener)
Removes given mouse listener if found.
func RemoveResByName ¶
Removes a resource by name. Returns false if resource could not be found.
func RemoveResByPath ¶
Removes a resource by path. Returns false if resource could not be found.
func RemoveScene ¶
Removes a given scene. Returns false if it could not be found.
func RemoveSystem ¶
Removes the given system. Returns false if it could not be found.
func Run ¶
func Run(game Game, options *RunOptions)
Creates a new window with given options and starts the game. The game struct must implement the Game interface. If options is nil, the default options will be used. This function will panic on error.
func SetViewport ¶
func SetViewport(x, y, width, height int32)
Sets GL viewport and updates default resources and systems.
func SwitchScene ¶
func SwitchScene(scene Scene)
Switches to given scene. This will pause the currently active scene.
func SwitchSceneByName ¶
Switches to given existing scene by name. Returns false if the scene does not exist.
Types ¶
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
A basic actor, having a unique ID. Use NewActor() to create new actors.
type ActorId ¶
type ActorId uint64
An actor ID is a unique integer, which can be used to reference an actor.
type AnimatedSprite ¶
type AnimatedSprite struct { *Actor *Pos2D *Tex *KeyframeSet *KeyframeAnimation }
An animated sprite is a sprite with keyframe animation information. It will be updated and rendered by the KeyframeRenderer.
func NewAnimatedSprite ¶
func NewAnimatedSprite(tex *Tex, set *KeyframeSet, width, height int) *AnimatedSprite
Creates a new animated sprite.
type Camera ¶
type Camera struct { Viewport Vec4 Position, LookAt, Up Vec3 Fov, Ratio, Znear, Zfar float64 Projection, Ortho3D, View Mat4 Ortho Mat3 }
func (*Camera) CalcOrtho3D ¶
Calculates 3D orthogonal projection matrix and returns it.
func (*Camera) CalcProjection ¶
Calculates projection matrix and returns it.
func (*Camera) SetViewport ¶
Updates viewport.
type Culling2D ¶
type Culling2D struct {
// contains filtered or unexported fields
}
func GetCulling2DSystem ¶
func GetCulling2DSystem() *Culling2D
func NewCulling2D ¶
Creates a new sprite culling system. To update the viewport, call SetViewport().
func (*Culling2D) RemoveById ¶
Removes actor with Pos2D from system by ID.
func (*Culling2D) SetViewport ¶
Sets the culling outer bounds. Actors outside of this box won't be rendered.
type Dropable ¶
type Dropable interface {
Drop()
}
The dropable interface is used to clean up GL objects. Use the Drop() function to drop a range of objects.
type FBO ¶
type FBO struct {
// contains filtered or unexported fields
}
Frame Buffer Object.
func (*FBO) ClearAttachments ¶
func (f *FBO) ClearAttachments()
Removes all attached textures from FBO.
func (*FBO) DrawBuffers ¶
type Font ¶
type Font struct { Tex *Tex CharPadding Vec2 Space, Tab, Line float64 // contains filtered or unexported fields }
Font represents a texture mapped font. It can be loaded from JSON together with a texture.
func NewFont ¶
Creates a new font for given texture. The tile size specifies the size of one character tile on texture. Characters must be added afterwards.
func (*Font) FromJson ¶
Loads characters from JSON file. Format:
[
{ "char": "a", "x": 0, "y": 0, "offset": 0 }, ...
]
Where x and y start in the upper left corner of the texture, both of type int. Offset is optional and can be used to move a character up or down (relative to others). If cut is set to true, the characters will be true typed.
type Game ¶
type Game interface { Setup() Update(float64) }
Main game object. Setup will be called before the main loop and after GL context has been created. Update will be called each frame. This can be used to switch scenes or end game on win state. For game logic, System should be used.
type KeyboardListener ¶
Interface for keyboard input events. Implement and register to receive keyboard input.
type Keyframe ¶
type Keyframe struct {
Min, Max Vec2
// contains filtered or unexported fields
}
A single keyframe within a keyframe set.
func NewKeyframe ¶
Creates a new single keyframe with texture VBO.
type KeyframeAnimation ¶
type KeyframeAnimation struct {
Start, End int
Loop bool
Speed float64
Current int
Interpolation float64
}
Keyframe animation component. It has a start and an end frame, a play speed and option to loop.
func NewKeyframeAnimation ¶
func NewKeyframeAnimation(start, end int, loop bool, speed float64) *KeyframeAnimation
Creates a new keyframe animation with given start, end and loop.
type KeyframeRenderer ¶
type KeyframeRenderer struct { Pos2D Shader *Shader Camera *Camera // contains filtered or unexported fields }
The keyframe renderer renders animated sprites. It has a 2D position component, to move all sprites at once.
func GetKeyframeRenderer ¶
func GetKeyframeRenderer() *KeyframeRenderer
func NewKeyframeRenderer ¶
func NewKeyframeRenderer(shader *Shader, camera *Camera) *KeyframeRenderer
Creates a new keyframe renderer using given shader and camera. If shader and/or camera are nil, the default one will be used.
func (*KeyframeRenderer) Add ¶
func (s *KeyframeRenderer) Add(actor *Actor, pos *Pos2D, tex *Tex, set *KeyframeSet, animation *KeyframeAnimation) bool
Adds animated sprite to the renderer.
func (*KeyframeRenderer) Cleanup ¶
func (s *KeyframeRenderer) Cleanup()
Frees recources created by keyframe renderer. This is called automatically when system gets removed.
func (*KeyframeRenderer) GetName ¶
func (s *KeyframeRenderer) GetName() string
func (*KeyframeRenderer) Remove ¶
func (s *KeyframeRenderer) Remove(actor *Actor) bool
Removes animated sprite from renderer.
func (*KeyframeRenderer) RemoveAll ¶
func (s *KeyframeRenderer) RemoveAll()
Removes all animated sprites.
func (*KeyframeRenderer) RemoveById ¶
func (s *KeyframeRenderer) RemoveById(id ActorId) bool
Removes sprite from renderer by ID.
func (*KeyframeRenderer) Update ¶
func (s *KeyframeRenderer) Update(delta float64)
Updates animation state and renders sprites.
type KeyframeSet ¶
type KeyframeSet struct {
Keyframes []Keyframe
}
A set of keyframes making up an animation.
func NewKeyframeSet ¶
func NewKeyframeSet() *KeyframeSet
Creates a new empty keyframe set with given size.
func (*KeyframeSet) Add ¶
func (s *KeyframeSet) Add(frame *Keyframe) int
Adds a new keyframe to set and returns new length.
type Mat3 ¶
type Mat3 struct {
Values [9]float64
}
3x3 column major matrix.
func (*Mat3) Determinate ¶
Returns the determinate of actual matrix.
type Mat4 ¶
type Mat4 struct {
Values [16]float64
}
4x4 column major matrix.
func NewMat4 ¶
func NewMat4(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33 float64) *Mat4
Creates a new 4x4 matrix with initial values.
func (*Mat4) Determinate ¶
Returns the determinate of actual matrix.
func (*Mat4) Perspective ¶
Sets actual matrix to perspective projection with given viewport.
type Mesh ¶
Component representing a 3D mesh.
type ModelRenderer ¶
type ModelRenderer struct { Pos3D Shader *Shader Camera *Camera // contains filtered or unexported fields }
The model renderer is a system rendering models. It has a 3D position component, to move all models at once.
func GetModelRenderer ¶
func GetModelRenderer() *ModelRenderer
func NewModelRenderer ¶
func NewModelRenderer(shader *Shader, camera *Camera, ortho bool) *ModelRenderer
Creates a new model renderer using given shader and camera. If shader and/or camera are nil, the default one will be used. Orth can be set to true, to use orthogonal projection.
func (*ModelRenderer) Cleanup ¶
func (s *ModelRenderer) Cleanup()
func (*ModelRenderer) GetName ¶
func (s *ModelRenderer) GetName() string
func (*ModelRenderer) Prepare ¶
func (s *ModelRenderer) Prepare(model *Model)
Prepares a model to be rendered by setting up its VAO.
func (*ModelRenderer) Remove ¶
func (s *ModelRenderer) Remove(actor *Actor) bool
Removes model from renderer.
func (*ModelRenderer) RemoveById ¶
func (s *ModelRenderer) RemoveById(id ActorId) bool
Removes model from renderer by ID.
type MouseListener ¶
type MouseListener interface { OnMouseButton(glfw.MouseButton, glfw.Action, glfw.ModifierKey) OnMouseMove(float64, float64) OnMouseScroll(float64, float64) }
Interface for mouse input events. Implement and register to receive mouse input.
type Ply ¶
type Ply struct {
IndexBuffer, VertexBuffer, TexCoordBuffer, NormalBuffer *VBO
// contains filtered or unexported fields
}
Standford ply file resource.
type PlyLoader ¶
type PlyLoader struct {
VboUsage uint32
}
Loads ply files and creates VBOs within the Ply resource. The indices must be present as triangles. Expected type is float32. If it fails to parse, it will panic.
type PngLoader ¶
Loads textures from png files. If keepData is set to true, pixel data will be stored inside the texture (additionally to VRAM).
type Pos2D ¶
Position component for 2D objects.
func (*Pos2D) GetCenter ¶
Returns the center of object. Assumes y = 0 is bottom left corner, if not you have to subtract height of object.
func (*Pos2D) PointInRect ¶
Returns true when given point is within rectangle of this object.
type Pos3D ¶
Position component for 3D objects
type Res ¶
type Res interface { GetName() string SetName(string) GetPath() string SetPath(string) GetExt() string SetExt(string) }
A generic resource. Must be cast to appropriate type. The name is the file name and must be unique.
func GetResByName ¶
Returns a resource by name or nil, if not found.
func GetResByPath ¶
Returns a resource by path or nil, if not found.
func LoadRes ¶
Loads a resource by file path. If no loader is present for given file, an error will be returned. If the loader fails to load the resource, an error will be returned. If the resource name exists already, an error AND the resource will be returned. This is allows to cleanup on failure.
type ResLoader ¶
Resource loader interface. The loader accepts files by file extension. and loads them if accepted.
func GetLoaderByExt ¶
Returns a loader by file extension. If not found, nil will be returned.
type ResizeCallback ¶
type ResizeCallback func(width, height int)
If set in RunOptions, the function will be called on window resize.
type RunOptions ¶
type RunOptions struct { Title string Width uint32 Height uint32 ClearColor Vec4 Resizable bool SetViewportOnResize bool ResizeCallbackFunc ResizeCallback ExitOnClose bool RefreshRate int Fullscreen bool MonitorId uint // index }
Run options allow to set some parameters on startup.
type Scene ¶
A scene used to switch between game states. The Cleanup() method is called when a scene is removed or the program is stopped. It can be used to cleanup open resources (like GL objects). On switch, Pause() and Resume() are called. The name returned by GetName() must be unique. A scene must only be registered once.
func GetActiveScene ¶
func GetActiveScene() Scene
Returns the currently active scene. Can be nil if no scene was set.
func GetSceneByName ¶
Finds and returns a scene by name, or nil if not found.
type Shader ¶
type Shader struct {
// contains filtered or unexported fields
}
Combination of shaders and shader program.
func NewShader ¶
Creates a new shader program by given vertex and fragment shader source code. The shaders itself will be deleted when compiled, only the program ID will be kept.
func (*Shader) BindAttrib ¶
Binds an attribute to this shader (with default index), name must be present in shader source.
func (*Shader) BindAttribIndex ¶
Binds an attribute to this shader, name must be present in shader source.
func (*Shader) DisableVertexAttribArrays ¶
func (s *Shader) DisableVertexAttribArrays()
Disables all bound attributes.
func (*Shader) EnableVertexAttribArrays ¶
func (s *Shader) EnableVertexAttribArrays()
Enables all bound attributes.
func (*Shader) GetAttribLocation ¶
Returns the location of an attribute. The name must be present in the shader source.
func (*Shader) GetFragmentId ¶
Returns the fragment shader GL ID.
func (*Shader) GetUniformLocation ¶
Returns the uniform location of a variable. The name must be present in the shader source.
func (*Shader) SendUniform1f ¶
func (*Shader) SendUniform1fv ¶
func (*Shader) SendUniform1i ¶
func (*Shader) SendUniform1iv ¶
func (*Shader) SendUniform2f ¶
func (*Shader) SendUniform2fv ¶
func (*Shader) SendUniform2i ¶
func (*Shader) SendUniform2iv ¶
func (*Shader) SendUniform2x2 ¶
func (*Shader) SendUniform2x3 ¶
func (*Shader) SendUniform2x4 ¶
func (*Shader) SendUniform3f ¶
func (*Shader) SendUniform3fv ¶
func (*Shader) SendUniform3i ¶
func (*Shader) SendUniform3iv ¶
func (*Shader) SendUniform3x2 ¶
func (*Shader) SendUniform3x3 ¶
func (*Shader) SendUniform3x4 ¶
func (*Shader) SendUniform4f ¶
func (*Shader) SendUniform4fv ¶
func (*Shader) SendUniform4i ¶
func (*Shader) SendUniform4iv ¶
func (*Shader) SendUniform4x2 ¶
func (*Shader) SendUniform4x3 ¶
func (*Shader) SendUniform4x4 ¶
type SpriteRenderer ¶
type SpriteRenderer struct { Pos2D Shader *Shader Camera *Camera // contains filtered or unexported fields }
The sprite renderer is a system rendering sprites. It has a 2D position component, to move all sprites at once.
func GetSpriteRenderer ¶
func GetSpriteRenderer() *SpriteRenderer
func NewSpriteRenderer ¶
func NewSpriteRenderer(shader *Shader, camera *Camera, flip bool) *SpriteRenderer
Creates a new sprite renderer using given shader and camera. If shader and/or camera are nil, the default one will be used.
func (*SpriteRenderer) Add ¶
func (s *SpriteRenderer) Add(actor *Actor, pos *Pos2D, tex *Tex) bool
Adds sprite to the renderer.
func (*SpriteRenderer) Cleanup ¶
func (s *SpriteRenderer) Cleanup()
Frees recources created by sprite renderer. This is called automatically when system gets removed.
func (*SpriteRenderer) GetName ¶
func (s *SpriteRenderer) GetName() string
func (*SpriteRenderer) Remove ¶
func (s *SpriteRenderer) Remove(actor *Actor) bool
Removes sprite from renderer.
func (*SpriteRenderer) RemoveAll ¶
func (s *SpriteRenderer) RemoveAll()
Removes all sprites from renderer.
func (*SpriteRenderer) RemoveById ¶
func (s *SpriteRenderer) RemoveById(id ActorId) bool
Removes sprite from renderer by ID.
type System ¶
type System interface { Update(float64) Cleanup() Remove(*Actor) bool RemoveById(ActorId) bool RemoveAll() Len() int GetName() string }
A system provides logic for actors satisfying required components. They are automatically updated on each frame. When a system is removed from systems, the Cleanup() method will be called. This will also happen on program stop. It can be used to cleanup open resources (like GL objects).
func GetSystemByName ¶
Finds and returns a system by name, or nil if not found.
type Tex ¶
type Tex struct {
// contains filtered or unexported fields
}
Texture object.
func GetTex ¶
Finds and returns a Tex resource. If not found or when the resource is of wrong type, an error will be returned.
func (*Tex) SetActiveTexture ¶
Sets which texture boundary is used when bound for rendering. Can be GL_TEXTURE0, GL_TEXTURE1, ... GL_TEXTUREn.
func (*Tex) SetDefaultParams ¶
Sets the default parameters, which are passed filter and CLAMP_TO_EDGE.
func (*Tex) Texture2D ¶
func (t *Tex) Texture2D(level, internalFormat, width, height int32, format, ttype uint32, data []uint8)
Creates a new 2D texture.
type Text ¶
type Text struct { *Actor *Pos2D *TextComponent }
Text is an actor representing text rendered as texture mapped font. Each Text has a position and its own buffers.
type TextComponent ¶
type TextComponent struct { Color Vec4 // contains filtered or unexported fields }
Renderable text component. Use together with Text and create using NewText().
func (*TextComponent) Drop ¶
func (t *TextComponent) Drop()
Deletes GL buffers bound to this text component.
type TextRenderer ¶
type TextRenderer struct { Pos2D Shader *Shader Camera *Camera Font *Font // contains filtered or unexported fields }
The text renderer is a system rendering 2D texture mapped font. It has a 2D position component, to move all texts at once.
func GetTextRenderer ¶
func GetTextRenderer() *TextRenderer
func NewTextRenderer ¶
func NewTextRenderer(shader *Shader, camera *Camera, font *Font) *TextRenderer
Creates a new text renderer using given shader, camera and font. If shader and/or camera are nil, the default one will be used.
func (*TextRenderer) Add ¶
func (r *TextRenderer) Add(actor *Actor, pos *Pos2D, text *TextComponent) bool
Adds text to the renderer.
func (*TextRenderer) Cleanup ¶
func (r *TextRenderer) Cleanup()
Frees recources created by text component. This is called automatically when system gets removed.
func (*TextRenderer) GetName ¶
func (r *TextRenderer) GetName() string
func (*TextRenderer) Prepare ¶
func (r *TextRenderer) Prepare(text *Text)
Prepares given text for rendering.
func (*TextRenderer) Remove ¶
func (r *TextRenderer) Remove(actor *Actor) bool
Removes text from renderer.
func (*TextRenderer) RemoveById ¶
func (r *TextRenderer) RemoveById(id ActorId) bool
Removes text from renderer by ID.
type VBO ¶
type VBO struct {
// contains filtered or unexported fields
}
Vertex Buffer Object.
func (*VBO) AttribPointer ¶
func (v *VBO) AttribPointer(attribLocation int32, size int32, btype uint32, normalized bool, stride int32)
Sets the attribute pointer for rendering. Used together with shader.
type Vec2 ¶
type Vec2 struct {
X, Y float64
}
A 2D vector.
func (*Vec2) DotVec ¶
Calculates and returns the dot product of combination of given vector and actual vector.
type Vec3 ¶
type Vec3 struct {
X, Y, Z float64
}
A 3D vector.
func (*Vec3) DotVec ¶
Calculates and returns the dot product of combination of given vector and actual vector.
type Vec4 ¶
type Vec4 struct {
X, Y, Z, W float64
}
A 4D vector.
func (*Vec4) DotVec ¶
Calculates and returns the dot product of combination of given vector and actual vector.