glim

package module
v0.0.0-...-4d6435b Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: GPL-2.0 Imports: 21 Imported by: 0

README

Build Status GoDoc

glim

OpenGL IMage library - A collection of routines for common image/texture functions

glim is an OpenGL ES 2.0 utility library, providing routines to take screenshots (of your GL window), render to texture, upload textures, and render text to textures (utf-8).

It is designed to work with Golang's GoMobile library, but should require little or no changes to work with other GL libraries

Documentation

Availabe on GoDoc

Documentation

Overview

GL Image library. Routines for handling images and textures in GO OpenGL (especially with the GoMobile framework)

GL Image library. Routines for handling images and textures in GO OpenGL (especially with the GoMobile framework)

Text editor library. Routines to support a text editor

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs32

func Abs32(x int32) int32

Abs32 returns the absolute value of int32 x.

func Abs64

func Abs64(x int64) int64

Abs64 returns the absolute value of x.

func Abs8

func Abs8(x int8) int8

Abs8 returns the absolute value of int8 x.

func AbsInt

func AbsInt(x int) int

AbsInt returns the absolute value of int x.

func CalcDiff

func CalcDiff(renderPix, refImage []byte, width, height int) (int64, []byte)

Calculate the pixel difference between two images.

This does a simple pixel compare, by sutracting the RGB pixel values. Itdoes not take into account perceptual differences or gamma or anything clever like that

The higher the returned number, the more different the pictures are

func CalcDiffSq

func CalcDiffSq(renderPix, refImage []byte, width, height int) (int64, []byte)

Calculate the pixel difference between two images.

This does a simple pixel compare, by sutracting the RGB pixel values, then squaring the difference. It does not take into account perceptual differences or gamma or anything clever like that

The higher the returned number, the more different the pictures are

func ClearAllCaches

func ClearAllCaches()

Dump the rendercache, facecache and fontcache

func DrawCursor

func DrawCursor(xpos, ypos, height, clientWidth int, u8Pix []byte)

Draw a cursor shape

func DrawStringRGBA

func DrawStringRGBA(txtSize float64, fontColor RGBA, txt, fontfile string) (*image.RGBA, *font.Face)

Creates a texture and draws a string to it

FIXME some fonts might not compeletely fit in the texture (usually the decorative ones which extend into another letter)

func DumpBuff

func DumpBuff(buff []uint8, width, height uint)

Prints the contents of a 32bit RGBA byte array as ASCII text

For debugging. Any pixel with a red value over 128 will be drawn as "I", otherwise "_"

func Fixed2int

func Fixed2int(n fixed.Int26_6) int

func FlipUp

func FlipUp(srcW, srcH int, src []byte) []byte

Flips a 32bit byte array picture upside down. Creates a target array with with the correct dimensions and returns it

func GDiff

func GDiff(m, m1 image.Image) int64

Returns a number representing the graphical difference between two images.

This difference is calculated by comparing each pixel and summing the difference in colour

This difference function is used in some other programs to power some approximation functions, it doesn't actually mean anything

func GFormatToImage

func GFormatToImage(img image.Image, u8Pix []uint8, clientWidth, clientHeight int) ([]uint8, int, int)

Use width and height of 0 to use the image size

func GetGlyphSize

func GetGlyphSize(size float64, str string) (int, int)

Get the maximum pixel size needed to hold a string

func ImageToGFormat

func ImageToGFormat(texWidth, texHeight int, buff []byte) image.Image

Converts an image to google's image format, RGBA type

func ImageToGFormatRGBA

func ImageToGFormatRGBA(texWidth, texHeight int, buff []byte) *image.RGBA

Converts an image to google's image format, NRGBA format

func InBounds

func InBounds(v, min, max Vec2) bool

Is v inside the box defined by min and max?

func LoadFont

func LoadFont(fileName string) *truetype.Font

Attempts to load a font using goMobile's truetype font library

func LoadImage

func LoadImage(path string) ([]byte, int, int)

Load a image from disk, return a byte array, width, height

func MakeTransparent

func MakeTransparent(m []byte, col color.RGBA) []byte

Turn all pixels of a colour into transparent pixels

i.e. set the alpha to zero if the RGB matches the colour

The alpha value of the input colour is ignored

func MaxI

func MaxI(a, b int) int

Return the larger of two integers

func NextPo2

func NextPo2(n int) int

func PaintTexture

func PaintTexture(img image.Image, u8Pix []uint8, clientWidth int) []uint8

Copies an image to a correctly-packed texture data array, where "correctly packed" means a byte array suitable for loading into OpenGL as a 32-bit RGBA byte blob

Other formats are not currently supported, patches welcome, etc

Returns the array, modified in place. If u8Pix is nil or texWidth is 0, it creates a new texture array and returns that. Texture is assumed to be square (this used to be required for OpenGL, not sure now?).

func PasteBytes

func PasteBytes(srcWidth, srcHeight int, srcBytes []byte, xpos, ypos, dstWidth, dstHeight int, u8Pix []uint8, transparent, showBorder bool, copyAlpha bool)

PasteBytes

Takes a bag of bytes, and some dimensions, and pastes it into another bag of bytes It's the basic image combining routine

func PasteImg

func PasteImg(img *image.RGBA, xpos, ypos, clientWidth, clientHeight int, u8Pix []uint8, transparent bool)

Pastes a go format image into a bag of bytes image

func PasteText

func PasteText(tSize float64, xpos, ypos, clientWidth, clientHeight int, text string, u8Pix []uint8, transparent bool)

Write some text into a bag of bytes image.

func RGBAtoColor

func RGBAtoColor(in RGBA) color.RGBA

Convert to go's image library color

func RandPic

func RandPic(width, height int) []uint8

Make a random picture to display. Handy for debugging

func RenderPara

func RenderPara(f *FormatParams, xpos, ypos, minX, minY, maxX, maxY, clientWidth, clientHeight, cursorX, cursorY int, u8Pix []uint8, text string, transparent bool, doDraw bool, showCursor bool) (int, int, int)

Draw some text into a 32bit RGBA byte array, wrapping where needed. Supports all the options I need for a basic word processor, including vertical text, and different sized lines

This was a bad idea. Instead of all the if statements, we should just assume everything is left-to-right, top-to-bottom, and then rotate the entire block afterwards (we will also have to rotate the characters around their own center)

Return the cursor position (number of characters from start of text) that is closest to the mouse cursor (cursorX, cursorY)

xpos, ypos - The starting draw position, global minX, minY - The leftmost part of the draw subregion. To fill the whole image, set to 0,0 maxX, maxY - The rightmost edge of draw subregion. To fill the whole image, set to the image width clentWidth, clienHeight - maxX-minX? cursorX, cursorY - Mouse cursor coordinates, relative to whole image

func RenderTokenPara

func RenderTokenPara(f *FormatParams, xpos, ypos, minX, minY, maxX, maxY, clientWidth, clientHeight, cursorX, cursorY int, u8Pix []uint8, tokens [][]string, transparent bool, doDraw bool, showCursor bool) (int, int, int)

func Rotate270

func Rotate270(srcW, srcH int, src []byte) []byte

Rotate a 32bit byte array into a new byte array. The target array will be created with the correct dimensions

func Rotate90

func Rotate90(srcW, srcH int, src []byte) []byte

Rotate a 32bit byte array into a new byte array. The target array will be created with the correct dimensions

func SanityCheck

func SanityCheck(f *FormatParams, txt string)

Check and correct formatparams to make sure e.g. cursor is always on the screen

func SaveBuff

func SaveBuff(texWidth, texHeight int, buff []byte, filename string)

Saves a 32 bit RGBA format byte array to a PNG file

i.e. 1 byte for each R,B,G,A

func SaveImage

func SaveImage(picture *image.RGBA, filename string)

Dumps a go image format thing to disk

func ToChar

func ToChar(i int) rune

func Uint8ToBytes

func Uint8ToBytes(in []uint8) []byte

Convert an array of uint8 to byte, because somehow golang manages to pack them differently in memeory

Types

type FormatParams

type FormatParams struct {
	Colour            *RGBA   //Text colour
	Line              int     //The line number, i.e. the number of /n characters from the start
	Cursor            int     //The cursor position, in characters from the start of the text
	SelectStart       int     //Start of the selection box, counted from the start of document
	SelectEnd         int     //End of the selection box, counted from the start of document
	StartLinePos      int     //Updated during render, holds the closest start of line, including soft line breaks
	FontSize          float64 //Fontsize, in points or something idfk
	FirstDrawnCharPos int     //The first character to draw on the screen.  Anything before this is ignored
	LastDrawnCharPos  int     //The last character that we were able to fit on the screen
	TailBuffer        bool    //Nothing for now
	Outline           bool    //Nothing for now
	Vertical          bool    //Draw texture vertically for Chinese/Japanese rendering
	SelectColour      *RGBA   //Selection text colour
}

Holds all the configuration details for drawing a string into a texture. This structure gets written to during the draw

func CopyFormatter

func CopyFormatter(inF *FormatParams) *FormatParams

Duplicate a formatter, that can be modified without changing the original

func NewFormatter

func NewFormatter() *FormatParams

Create a new text formatter, with useful default parameters

type RGBA

type RGBA []uint8

type Thunk

type Thunk func()

type Vec2

type Vec2 struct {
	X, Y int
}

func MoveInBounds

func MoveInBounds(v, min, max, charDim, charAdv, linAdv Vec2, attempts int) (newPos Vec2)

Move v to the closest point inside the box defined by min.max

Directories

Path Synopsis
letters.go
letters.go

Jump to

Keyboard shortcuts

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