graphics

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: BSD-3-Clause Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const BytesPerRgba = 4

BytesPerRgba defines the byte count for an RGBA color value.

View Source
const ColorsPerPalette = 256

ColorsPerPalette defines how many colors are per palette. This value is 256 to cover byte-based bitmaps.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

type Bitmap struct {
	Width  int
	Height int
	Pixels []byte
}

Bitmap is a simple palette based image.

func BitmapFromRaw

func BitmapFromRaw(raw model.RawBitmap) Bitmap

BitmapFromRaw returns a bitmap instance with decoded pixel data.

type BitmapRetriever

type BitmapRetriever func() *BitmapTexture

BitmapRetriever is a thunk that retrieves a cached bitmap.

type BitmapTexture

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

BitmapTexture contains a bitmap stored as OpenGL texture.

func NewBitmapTexture

func NewBitmapTexture(gl opengl.OpenGl, width, height int, pixelData []byte) *BitmapTexture

NewBitmapTexture downloads the provided raw data to OpenGL and returns a BitmapTexture instance.

func (*BitmapTexture) Dispose

func (tex *BitmapTexture) Dispose()

Dispose implements the GraphicsTexture interface.

func (*BitmapTexture) Handle

func (tex *BitmapTexture) Handle() uint32

Handle returns the texture handle.

func (*BitmapTexture) Size

func (tex *BitmapTexture) Size() (width, height float32)

Size returns the dimensions of the bitmap, in pixels.

func (*BitmapTexture) UV

func (tex *BitmapTexture) UV() (u, v float32)

UV returns the maximum U and V values for the bitmap. The bitmap will be stored in a power-of-two texture, which may be larger than the bitmap.

type BitmapTextureRenderer

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

BitmapTextureRenderer renders bitmapped textures based on a palette.

func NewBitmapTextureRenderer

func NewBitmapTextureRenderer(renderContext *RenderContext, paletteTexture Texture) *BitmapTextureRenderer

NewBitmapTextureRenderer returns a new instance of a texture renderer for bitmaps.

func (*BitmapTextureRenderer) Dispose

func (renderer *BitmapTextureRenderer) Dispose()

Dispose clears any resources.

func (*BitmapTextureRenderer) Render

func (renderer *BitmapTextureRenderer) Render(modelMatrix *mgl.Mat4, texture Texture, textureRect Rectangle)

Render implements the TextureRenderer interface.

type BufferedTextureStore

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

BufferedTextureStore keeps textures in a buffer.

func NewBufferedTextureStore

func NewBufferedTextureStore(query TextureQuery) *BufferedTextureStore

NewBufferedTextureStore returns a new instance of a store.

func (*BufferedTextureStore) Reset

func (store *BufferedTextureStore) Reset()

Reset clears the store. It disposes any registered texture.

func (*BufferedTextureStore) SetTexture

func (store *BufferedTextureStore) SetTexture(id TextureKey, texture *BitmapTexture)

SetTexture registers a (new) texture under given ID. It disposes any previously registered texture.

func (*BufferedTextureStore) Texture

func (store *BufferedTextureStore) Texture(id TextureKey) *BitmapTexture

Texture returns the texture associated with the given ID. May be nil if not yet known/available.

type Color

type Color interface {
	// AsVector returns the color as a 4-dimensional vector.
	AsVector() *[4]float32
}

Color represents a 4-element color, ordered R, G, B, A; Range: [0..1]

func RGBA

func RGBA(r, g, b, a float32) Color

RGBA returns a new color instance with the given R, G, B and A values.

type ColorProvider

type ColorProvider func(index int) (byte, byte, byte, byte)

ColorProvider is a function to return the RGBA values for a certain palette index.

type Context

type Context interface {
	RectangleRenderer() *RectangleRenderer
	TextPainter() TextPainter
	Texturize(bmp *Bitmap) *BitmapTexture
	UITextRenderer() *BitmapTextureRenderer

	NewPaletteTexture(colorProvider ColorProvider) *PaletteTexture
	BitmapsStore() *BufferedTextureStore
	WorldTextureStore(size model.TextureSize) *BufferedTextureStore
	GameObjectBitmapsStore() *BufferedTextureStore
	GameObjectIconsStore() *BufferedTextureStore
}

Context is a provider of graphic utilities.

type PaletteTexture

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

PaletteTexture contains a palette stored as OpenGL texture.

func NewPaletteTexture

func NewPaletteTexture(gl opengl.OpenGl, colorProvider ColorProvider) *PaletteTexture

NewPaletteTexture creates a new PaletteTexture instance.

func (*PaletteTexture) Dispose

func (tex *PaletteTexture) Dispose()

Dispose implements the GraphicsTexture interface.

func (*PaletteTexture) Handle

func (tex *PaletteTexture) Handle() uint32

Handle returns the texture handle.

func (*PaletteTexture) Update

func (tex *PaletteTexture) Update()

Update reloads the palette.

type Rectangle

type Rectangle interface {
	// Left returns the left edge of the rectangle.
	Left() float32
	// Top returns the top edge of the rectangle.
	Top() float32
	// Right returns the coordinate beyond the right edge of the rectangle.
	Right() float32
	// Bottom returns the coordinate beyond the bottom edge of the rectangle.
	Bottom() float32
}

Rectangle describes a rectangular area with four points.

func RectByCoord

func RectByCoord(left, top, right, bottom float32) Rectangle

RectByCoord returns a rectangle instance by coordinates.

type RectangleRenderer

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

RectangleRenderer renders rectangular shapes.

func NewRectangleRenderer

func NewRectangleRenderer(gl opengl.OpenGl, projectionMatrix *mgl.Mat4) *RectangleRenderer

NewRectangleRenderer returns a new instance of an RectangleRenderer type.

func (*RectangleRenderer) Dispose

func (renderer *RectangleRenderer) Dispose()

Dispose clears any open resources.

func (*RectangleRenderer) Fill

func (renderer *RectangleRenderer) Fill(left, top, right, bottom float32, fillColor Color)

Fill renders a rectangle filled with a solid color.

type RenderContext

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

RenderContext provides current render properties.

func NewBasicRenderContext

func NewBasicRenderContext(gl opengl.OpenGl, projectionMatrix *mgl.Mat4, viewMatrix *mgl.Mat4) *RenderContext

NewBasicRenderContext returns a render context for the provided parameters.

func (*RenderContext) OpenGl

func (context *RenderContext) OpenGl() opengl.OpenGl

OpenGl returns the GL interface.

func (*RenderContext) ProjectionMatrix

func (context *RenderContext) ProjectionMatrix() *mgl.Mat4

ProjectionMatrix returns the current projection matrix.

func (*RenderContext) ViewMatrix

func (context *RenderContext) ViewMatrix() *mgl.Mat4

ViewMatrix returns the current view matrix.

type StandardBitmapper

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

StandardBitmapper creates bitmap images from generic images.

func NewStandardBitmapper

func NewStandardBitmapper(palette []color.Color) *StandardBitmapper

NewStandardBitmapper returns a new bitmapper instance.

func (*StandardBitmapper) Map

func (bitmapper *StandardBitmapper) Map(img image.Image) Bitmap

Map maps the provided image to a bitmap based on the internal palette.

func (*StandardBitmapper) MapColor

func (bitmapper *StandardBitmapper) MapColor(clr color.Color) (palIndex byte)

MapColor maps the provided color to the nearest index in the palette.

type TextBitmap

type TextBitmap struct {
	Bitmap
	// contains filtered or unexported fields
}

TextBitmap is a bitmap with text coordinates.

func (TextBitmap) CharOffset

func (bmp TextBitmap) CharOffset(line, char int) int

CharOffset returns the horizontal offset of given char in given line, in pixel. An unknown line results in an offset of zero, a char beyond the end results in the line's end.

func (TextBitmap) LineCount

func (bmp TextBitmap) LineCount() int

LineCount returns the number of lines in this bitmap.

func (TextBitmap) LineHeight

func (bmp TextBitmap) LineHeight() int

LineHeight returns the height of one line, in pixel.

func (TextBitmap) LineLength

func (bmp TextBitmap) LineLength(line int) int

LineLength returns the width of the given line, in pixel.

type TextPainter

type TextPainter interface {
	// Paint creates a new bitmap based on given text.
	Paint(text string, widthLimit int) TextBitmap
}

TextPainter creates bitmaps for texts.

func NewBitmapTextPainter

func NewBitmapTextPainter(font model.Font) TextPainter

NewBitmapTextPainter returns a new text painter for the given bitmap font.

type Texture

type Texture interface {
	// Dispose releases any internal resources.
	Dispose()
	// Handle returns the texture handle.
	Handle() uint32
}

Texture describes a texture in graphics memory.

type TextureKey

type TextureKey int

TextureKey is a reference identifier for textures.

func TextureKeyFromInt

func TextureKeyFromInt(value int) TextureKey

TextureKeyFromInt wraps an integer as TextureKey.

func (TextureKey) ToInt

func (key TextureKey) ToInt() int

ToInt returns the integer representation of the key.

type TextureQuery

type TextureQuery func(id TextureKey)

TextureQuery is a callback function to request the data for a specific texture.

type TextureRenderer

type TextureRenderer interface {
	// Render takes the portion defined by textureRect out of texture to
	// render it within the given display rectangle.
	// textureRect coordinates are given in fractions of the texture.
	Render(modelMatrix *mgl.Mat4, texture Texture, textureRect Rectangle)
}

TextureRenderer renders textures.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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