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 ¶
- func Abs32(x int32) int32
- func Abs64(x int64) int64
- func Abs8(x int8) int8
- func AbsInt(x int) int
- func CalcDiff(renderPix, refImage []byte, width, height int) (int64, []byte)
- func CalcDiffSq(renderPix, refImage []byte, width, height int) (int64, []byte)
- func ClearAllCaches()
- func CloneImage(src image.Image) draw.Image
- func CopyFrameBuff(glctx gl.Context, rtt_frameBuff gl.Framebuffer, clientWidth, clientHeight int) []byte
- func CopyGFormatRGBA(src image.Image) draw.Image
- func CopyPix(pix []uint8) []uint8
- func CopyScreen(glctx gl.Context, clientWidth, clientHeight int) []byte
- func CopyScreenToGFormat(glctx gl.Context, clientWidth, clientHeight int) image.Image
- func DrawBox(xpos, ypos, width, height, clientWidth, clientHeight int, u8Pix []uint8, ...)
- func DrawCursor(xpos, ypos, height, pixWidth int, u8Pix []byte, cursorColour *RGBA)
- func DrawGlyphRGBA(txtSize float64, fontColor RGBA, glyph rune, fontfile string) (*image.RGBA, *font.Face)
- func DrawStringRGBA(txtSize float64, fontColor RGBA, txt, fontfile string) (*image.RGBA, *font.Face)
- func DumpBuff(buff []uint8, width, height uint)
- func Fixed2int(n fixed.Int26_6) int
- func FlipUp(srcW, srcH int, src []byte) []byte
- func ForceAlpha(m []byte, val uint8) []byte
- func GDiff(m, m1 image.Image) int64
- func GFormatToImage(img image.Image, u8Pix []uint8, clientWidth, clientHeight int) ([]uint8, int, int)
- func GenTexture(glctx gl.Context, w, h int, format gl.Enum) gl.Texture
- func GenTextureAndFramebuffer(glctx gl.Context, w, h int, format gl.Enum) (gl.Framebuffer, gl.Texture)
- func GenTextureOnFramebuffer(glctx gl.Context, f gl.Framebuffer, w, h int, format gl.Enum) gl.Texture
- func GetGlyphSize(size float64, str string) (int, int)
- func ImageToGFormat(texWidth, texHeight int, buff []byte) image.Image
- func ImageToGFormatRGBA(texWidth, texHeight int, buff []byte) *image.RGBA
- func InBounds(v, min, max Vec2) bool
- func Invert(m []byte) []byte
- func InvertAlpha(m []byte) []byte
- func LoadFont(fileName string) *truetype.Font
- func LoadImage(path string) ([]byte, int, int)
- func MakeTransparent(m []byte, col color.RGBA) []byte
- func MaxI(a, b int) int
- func NextPo2(n int) int
- func PaintTexture(img image.Image, u8Pix []uint8, clientWidth int) []uint8
- func PasteBytes(srcWidth, srcHeight int, srcBytes []byte, ...)
- func PasteImg(img *image.RGBA, xstart, ystart, clientWidth, clientHeight int, u8Pix []uint8, ...)
- func PasteText(tSize float64, xpos, ypos, clientWidth, clientHeight int, text string, ...)
- func RGBAtoColor(in RGBA) color.RGBA
- func RandPic(width, height int) []uint8
- func RenderPara(f *FormatParams, ...) (int, int, int)
- func RenderTokenPara(f *FormatParams, ...) (int, int, int)
- func Rotate270(srcW, srcH int, src []byte) []byte
- func Rotate90(srcW, srcH int, src []byte) []byte
- func Rtt(glctx gl.Context, rtt_frameBuff gl.Framebuffer, rtt_tex gl.Texture, ...)
- func SanityCheck(f *FormatParams, txt string)
- func SaveBuff(texWidth, texHeight int, buff []byte, filename string)
- func SaveImage(picture *image.RGBA, filename string)
- func ScreenShot(glctx gl.Context, filename string)
- func ScreenSize(glctx gl.Context) (int, int)
- func String2Tex(glctx gl.Context, str string, tSize float64, glTex gl.Texture, texSize int)
- func ToChar(i int) rune
- func Uint8ToBytes(in []uint8, out []byte) []byte
- func UploadNewTex(glctx gl.Context, data []uint8, w, h int) gl.Texture
- func UploadTex(glctx gl.Context, glTex gl.Texture, w, h int, buff []uint8)
- type FormatParams
- type RGBA
- type Style
- type Thunk
- type Token
- type Vec2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcDiff ¶
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 ¶
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 CopyFrameBuff ¶
func CopyFrameBuff(glctx gl.Context, rtt_frameBuff gl.Framebuffer, clientWidth, clientHeight int) []byte
Copy frame buffer to 32bit RGBA byte array
Only useful if you are using additional framebuffers, this retrieves the contents of a framebuffer of your choice
func CopyScreen ¶
The core of ScreenShot, it copies the display into a RGBA byte array
func CopyScreenToGFormat ¶
Copy the render buffer to golangs's horrible image format. Use CopyScreen instead.
func DrawBox ¶
func DrawBox(xpos, ypos, width, height, clientWidth, clientHeight int, u8Pix []uint8, col color.RGBA)
Draws a coloured box, does not merge with existing colour
func DrawCursor ¶
Draw a cursor shape
func DrawGlyphRGBA ¶
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 ¶
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 FlipUp ¶
Flips a 32bit byte array picture upside down. Creates a target array with with the correct dimensions and returns it
func GDiff ¶
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 GenTexture ¶
Creates a new texture, with the texture attached to the current frame buffer
Formats: GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA
func GenTextureAndFramebuffer ¶
func GenTextureAndFramebuffer(glctx gl.Context, w, h int, format gl.Enum) (gl.Framebuffer, gl.Texture)
Creates a new framebuffer and texture, with the texture attached to the frame buffer
func GenTextureOnFramebuffer ¶
func GenTextureOnFramebuffer(glctx gl.Context, f gl.Framebuffer, w, h int, format gl.Enum) gl.Texture
Creates a new texture, with the texture attached to the provided frame buffer
func GetGlyphSize ¶
Get the maximum pixel size needed to hold a string
func ImageToGFormat ¶
Converts an image to google's image format, RGBA type
func ImageToGFormatRGBA ¶
Converts an image to google's image format, NRGBA format
func Invert ¶
Invert the colour of all pixels
i.e. set each RGB channel to 255-n
The alpha value is inverted
func MakeTransparent ¶
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 PaintTexture ¶
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, start, ystart, 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, xstart, ystart, 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 RenderPara ¶
func RenderPara(f *FormatParams, xpos, ypos, minX, minY, maxX, maxY, pixWidth, pixHeight, 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, in 0<=xpos<=pixWidth, 0<=y<=pixHeight minX, minY - The leftmost part of the draw subregion. To fill the whole pix, set to 0,0 maxX, maxY - The rightmost edge of draw subregion. To fill the whole pix, set to pixWidth, pixHeight pixWidth, pixHeight - the size of the bitmap (e.g. in screen coordinates) cursorX, cursorY - Mouse cursor coordinates, relative to whole image
func RenderTokenPara ¶
func Rotate270 ¶
Rotate a 32bit byte array into a new byte array. The target array will be created with the correct dimensions
func Rotate90 ¶
Rotate a 32bit byte array into a new byte array. The target array will be created with the correct dimensions
func Rtt ¶
func Rtt(glctx gl.Context, rtt_frameBuff gl.Framebuffer, rtt_tex gl.Texture, texWidth, texHeight int, filename string, thunk Thunk)
Render-to-texture
Instead of drawing to the screen, draw into a texture. You must create the framebuffer and texture first, and do whatever setup is required to make them valid.
Thunk is a function that takes no args, returns no values, but draws the gl screen ¶
Rtt does the correct setup to prepare the texture for drawing, calls thunk() to draw it, then it restores the default frambuffer ¶
If filename is not "", then Rtt will save the contents of the framebuffer to the filename, followed by a number for each frame.
i.e. frambuffer 0 will be active at the end of the call, so make sure you switch to the correct one before doing anymore drawing! I should probably take that out, and figure out how to restore the currect framebuff
func SanityCheck ¶
func SanityCheck(f *FormatParams, txt string)
Check and correct formatparams to make sure e.g. cursor is always on the screen
func ScreenShot ¶
Save the currently display to a file on disk
func String2Tex ¶
Renders a string into a openGL texture. No guarantees are made that the text will fit
func Uint8ToBytes ¶
Convert an array of uint8 to byte, because somehow golang manages to pack them differently in memeory
func UploadNewTex ¶
Takes []uint8 RGBA image data and uploads it to the graphics card as a new gl texture
Returns the gl texture handle
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 CursorColour *RGBA HighlightColour *RGBA }
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