glh

package module
v0.0.0-...-d9d8eaf Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

glh: golang OpenGL helpers

Build Status

This package contains a number of functions useful for applications using OpenGL.

Code Reference

Features

  • Textures and Texture Atlas.
  • Easy framebuffer rendering to texture
  • Contexts
  • Basic text manipulation
  • Easy shader loading
  • Easy efficient uploading of many colour/vertices
  • Mesh buffer

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtlasRegion

type AtlasRegion struct {
	X int
	Y int
	W int
	H int
}

A region denotes an allocated chunk of space in an atlas.

type TextureAtlas

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

A texture atlas is used to tightly pack arbitrarily many small images into a single texture.

The actual implementation is based on the article by Jukka Jylänki: "A Thousand Ways to Pack the Bin - A Practical Approach to Two-Dimensional Rectangle Bin Packing", February 27, 2010.

More precisely, this is an implementation of the 'Skyline Bottom-Left' algorithm.

func NewTextureAtlas

func NewTextureAtlas(width, height, depth, filter int) *TextureAtlas

NewAtlas creates a new texture atlas.

The given width, height and depth determine the size and depth of the underlying texture.

depth should be 1, 3 or 4 and it will specify if the texture is created with Alpha, RGB or RGBA channels. The image data supplied through Atlas.Set() should be of the same format.

func (*TextureAtlas) Allocate

func (a *TextureAtlas) Allocate(width, height int) (AtlasRegion, bool)

Allocate allocates a new region of the given dimensions in the atlas. It returns false if the allocation failed. This can happen when the specified dimensions exceed atlas bounds, or the atlas is full.

func (*TextureAtlas) Bind

func (a *TextureAtlas) Bind(target uint32)

Bind binds the atlas texture, so it can be used for rendering.

func (*TextureAtlas) Clear

func (a *TextureAtlas) Clear()

Clear removes all allocated regions from the atlas. This invalidates any previously allocated regions.

func (*TextureAtlas) Commit

func (a *TextureAtlas) Commit(target uint32)

Commit creates the actual texture from the atlas image data. This should be called after all regions have been defined and set, and before you start using the texture for display.

func (*TextureAtlas) Depth

func (a *TextureAtlas) Depth() int

Depth returns the underlying texture color depth.

func (*TextureAtlas) Handle

func (a *TextureAtlas) Handle() uint32

func (*TextureAtlas) Height

func (a *TextureAtlas) Height() int

Height returns the underlying texture height in pixels.

func (*TextureAtlas) Release

func (a *TextureAtlas) Release()

Release clears all atlas resources.

func (*TextureAtlas) Save

func (a *TextureAtlas) Save(file string) (err error)

Save saves the texture as a PNG image.

func (*TextureAtlas) Set

func (a *TextureAtlas) Set(region AtlasRegion, src []byte, stride int)

Set pastes the given data into the atlas buffer at the given coordinates. It assumes there is enough space available for the data to fit.

func (*TextureAtlas) Unbind

func (a *TextureAtlas) Unbind(target uint32)

Unbind unbinds the current texture. Note that this applies to any texture currently active. If this is not the atlas texture, it will still perform the action.

func (*TextureAtlas) Width

func (a *TextureAtlas) Width() int

Width returns the underlying texture width in pixels.

Jump to

Keyboard shortcuts

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