Documentation ¶
Index ¶
- Constants
- Variables
- type BatchRenderer
- type Camera
- type Drawable
- type FrameBuffer
- type Hinting
- type OrgPosition
- type Point
- type Region
- type Renderer
- type Screen
- type TextDrawer
- func (d *TextDrawer) BoundBytes(s []byte) (dot image.Point, size image.Point, advance float32)
- func (d *TextDrawer) BoundString(s string) (dot image.Point, size image.Point, advance float32)
- func (d *TextDrawer) DrawBytes(batch Renderer, s []byte, dp, scale Point, c color.Color) (advance float32)
- func (d *TextDrawer) DrawString(batch Renderer, s string, dp, scale Point, c color.Color) (advance float32)
- func (d *TextDrawer) Face() font.Face
- func (d *TextDrawer) Glyph(dot fixed.Point26_6, r rune) (dp image.Point, gr *Region, advance fixed.Int26_6)
- func (d *TextDrawer) MeasureBytes(s []byte) (advance float32)
- func (d *TextDrawer) MeasureString(s string) (advance float32)
- type Texture
- func (t *Texture) Bind()
- func (t *Texture) Delete()
- func (t *Texture) GLCoords(pt Point) Point
- func (t *Texture) NativeID() uint32
- func (t *Texture) Origin() image.Point
- func (t *Texture) Parameters(params ...TextureParameter)
- func (t *Texture) Region(bounds image.Rectangle, origin image.Point) *Region
- func (t *Texture) SetSubImage(dr image.Rectangle, src image.Image, sp image.Point)
- func (t *Texture) Size() image.Point
- func (t *Texture) UV() [4]float32
- type TextureFilter
- type TextureParameter
- type TextureWrap
- type View
- func (v *View) GLRect() image.Rectangle
- func (v *View) Pan(p Point)
- func (v *View) ProjectionMatrix() [16]float32
- func (v *View) ScreenToView(p Point) Point
- func (v *View) ScreenToWorld(p Point) Point
- func (v *View) ScreenVecToWorld(p Point) Point
- func (v *View) Size() image.Point
- func (v *View) ViewToScreen(p Point) Point
- func (v *View) ViewToWorld(p Point) Point
- func (v *View) WorldToScreen(p Point) Point
- func (v *View) WorldToView(p Point) Point
- func (v *View) WorldVecToScreen(p Point) Point
Constants ¶
const ( // see subPixels() in https://github.com/golang/freetype/blob/master/truetype/face.go FontSubPixelsX = 8 FontSubPixelsY = 1 )
const ( HintingNone Hinting = Hinting(font.HintingNone) HintingVertical = Hinting(font.HintingVertical) HintingFull = Hinting(font.HintingFull) )
const ( Repeat TextureWrap = gl.GL_REPEAT MirroredRepeat = gl.GL_MIRRORED_REPEAT ClampToEdge = gl.GL_CLAMP_TO_EDGE )
WrapMode values map directly to their OpenGL equivalents.
Variables ¶
var FontTextureSize int = 1024
Texture size for font glyph texture atlas. This value should be adjusted to be no larger than gl.GL_MAX_TEXTURE_SIZE:
var mts int32 gl.GetIntegerv(gl.GL_MAX_TEXTURE_SIZE, &mts) if mts > int(TextureSize) || mts == 0 { TextureSize = int(mts) }
Functions ¶
This section is empty.
Types ¶
type BatchRenderer ¶
type BatchRenderer interface { Renderer Begin() Flush() End() Close() }
func NewBatch ¶
func NewBatch(concurrent bool) (BatchRenderer, error)
type Drawable ¶
type Drawable interface { Bind() // Bind calls gl.BindTexture(gl.GL_TEXTURE_2D, ...) NativeID() uint32 // OpenGL handle of the associated texture Origin() image.Point // Point of origin Size() image.Point // Drawable size UV() [4]float32 // UV coordinates of the drawable in the associated texture }
Drawable wraps the methods of drawable objects like texture.Texture and texture.Region.
type FrameBuffer ¶
FrameBuffer represents a render target framebuffer.
type Hinting ¶
type Hinting int
Hinting selects how to quantize a vector font's glyph nodes.
Not all fonts support hinting.
This is a convenience duplicate of golang.org/x/image/font#Hinting
type OrgPosition ¶
type OrgPosition int
OrgPosition determines the on-screen position of the point of origin of the view.
const ( OrgTopLeft OrgPosition = iota OrgCenter )
type Point ¶
func FbToGL ¶
func FbToGL(fb FrameBuffer, p Point) Point
FbToGL converts framebuffer pixel coordinates to GL coordinates in range [-1, 1].
func GLToFb ¶
func GLToFb(fb FrameBuffer, p Point) Point
GLToFb converts GL coordinates in range [-1, 1] to framebuffer pixel coordinates.
type Region ¶
type Region struct { *Texture // contains filtered or unexported fields }
Region is a Drawable that represents a sub-region in a Texture or another Region.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
A Screen is a FrameBuffer implementation for a physical display screen.
func NewScreen ¶
NewScreen returns a new screen of the requested size. The size should be updated whenever the size of the associated frame buffer changes.
type TextDrawer ¶
type TextDrawer struct {
// contains filtered or unexported fields
}
TextDrawer draws text.
A Drawer is not safe for concurrent use by multiple goroutines, since its Face is not.
func NewTextDrawer ¶
func NewTextDrawer(f font.Face, magFilter TextureFilter) *TextDrawer
NewTextDrawer returns a new TextDrawer using the given font face. The magFilter is the texture filter used when up-scaling.
func (*TextDrawer) BoundBytes ¶
BoundBytes returns the draw point and pixel size of s, as well as the advance.
It is equivalent to BoundString(string(s)) but may be more efficient.
func (*TextDrawer) BoundString ¶
BoundString returns the draw point and pixel size of s, as well as the advance.
func (*TextDrawer) DrawBytes ¶
func (d *TextDrawer) DrawBytes(batch Renderer, s []byte, dp, scale Point, c color.Color) (advance float32)
DrawBytes uses the provided batch to draw s at coordinates x, y with the given color. It returns the advance.
It is equivalent to DrawString(b, x, y, string(s), c) but may be more efficient.
func (*TextDrawer) DrawString ¶
func (d *TextDrawer) DrawString(batch Renderer, s string, dp, scale Point, c color.Color) (advance float32)
DrawString uses the provided batch to draw s at coordinates x, y with the given color. It returns the advance.
func (*TextDrawer) Face ¶
func (d *TextDrawer) Face() font.Face
func (*TextDrawer) Glyph ¶
func (d *TextDrawer) Glyph(dot fixed.Point26_6, r rune) (dp image.Point, gr *Region, advance fixed.Int26_6)
Glyph returns the glyph texture Region for rune r drawn at dot, the draw point (for batch.Draw) as well as the advance.
func (*TextDrawer) MeasureBytes ¶
func (d *TextDrawer) MeasureBytes(s []byte) (advance float32)
MeasureBytes returns how far dot would advance by drawing s.
func (*TextDrawer) MeasureString ¶
func (d *TextDrawer) MeasureString(s string) (advance float32)
MeasureString returns how far dot would advance by drawing s.
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
A Texture is a Drawable that represents an OpenGL texture.
func NewTexture ¶
func NewTexture(width, height int, params ...TextureParameter) *Texture
NewTexture Returns a new uninitialized texture of the given width and height.
func TextureFromImage ¶
func TextureFromImage(src image.Image, params ...TextureParameter) *Texture
TextureFromImage creates a new texture of the same dimensions as the source image. Regardless of the source image type, the resulting texture is always in RGBA format.
func (*Texture) GLCoords ¶
GLCoords return the coordinates of the point pt mapped to the range [0, 1].
func (*Texture) Parameters ¶
func (t *Texture) Parameters(params ...TextureParameter)
Parameters sets the given texture parameters.
func (*Texture) SetSubImage ¶
SetSubImage draws src to the texture. It works identically to draw.Draw with op set to draw.Src.
type TextureFilter ¶
type TextureFilter int32
TextureFilter selects how to filter textures when minifying or magnifying.
const ( Nearest TextureFilter = gl.GL_NEAREST Linear = gl.GL_LINEAR )
FilterMode values map directly to their OpenGL equivalents.
type TextureParameter ¶
type TextureParameter interface {
// contains filtered or unexported methods
}
TextureParameter is implemented by functions setting texture parameters. See New.
func Filter ¶
func Filter(min, mag TextureFilter) TextureParameter
Filter sets the GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER texture parameters.
func Wrap ¶
func Wrap(wrapS, wrapT TextureWrap) TextureParameter
Wrap sets the GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T texture parameters.
type TextureWrap ¶
type TextureWrap int32
TextureWrap selects how textures wrap when texture coordinates get outside of the range [0, 1].
When used in conjunction with github.com/db47h/grog/batch, the only settings that make sense are ClampToEdge (the default) and ClampToBorder.
type View ¶
type View struct { // Parent FrameBuffer Fb FrameBuffer // View rectangle in framebuffer pixel coordinates. Rect image.Rectangle // World coordinates of the point of origin of the view. Origin Point // On-screen position of the view's point of origin. View rotation and // scaling will preserve this property. OrgPos OrgPosition // View scaling factor. Scale float32 // View angle. Due to Y axis pointing down, positive angles correspond to a // clockwise rotation. Angle float32 }
A View converts world coordinates to screen coordinates.
// keep track of frame buffer size in event handlers s := NewScreen(fbWidth, fbHeight) v := s.RootView() // mapView will display a minimap in the bottom right corner mv :=&grog.View{Fb: s, Scale: 1.0} // draw loop for { batch.Begin() v.Origin = player.Pos() batch.SetView(v) // draw commands // ... // switch to minimap view mv.Rect = image.Rectangle{Min: s.Size().Sub(image.Pt(200,200), Max: s.Size()} batch.SetView(mv) // draw minimap // ... }
FrameBuffer and View coordinates have the y axis pointing downwards (y = 0 is the top line of the screen).
func (*View) GLRect ¶
GLRect returns an image.Rectangle for gl.Scissor (y axis upwards, 0,0 in the bottom left corner).
r := v.GLRect() gl.Scissor(int32(r.Min.X), int32(r.Min.Y), int32(r.Dx()), int32(r.Dy()))
func (*View) Pan ¶
Pan pans the view by p.X, p.Y screen pixels.
This is a shorthand for
v.Origin = v.Origin.Add(v.ScreenVecToWorld(dv))
func (*View) ProjectionMatrix ¶
ProjectionMatrix returns a 4x4 projection matrix suitable for Batch.SetProjectionMatrix.
func (*View) ScreenToView ¶
ScreenToView converts screen coordinates to view coordinates. It is equivalent to p.Sub(v.Rect.Min).
func (*View) ScreenToWorld ¶
ScreenToWorld converts screen coordinates to world coordinates.
func (*View) ScreenVecToWorld ¶
ScreenVecToWorld converts the vector represented by p in screen coordinates to world coordinates.
This is an optimized version of v.ScreenToWorld(p).Sub(v.ScreenToWorld(Point{}))
func (*View) ViewToScreen ¶
ViewToScreen converts view coordinates to screen coordinates. It is equivalent to p.Add(v.Rect.Min).
func (*View) ViewToWorld ¶
ViewToWorld converts view coordinates to world coordinates.
func (*View) WorldToScreen ¶
WorldToScreen converts world coordinates to screen coordinates.
func (*View) WorldToView ¶
WorldToView converts world coordinates to view coordinates.
func (*View) WorldVecToScreen ¶
WorldVecToScreen converts the vector represented by p in world coordinates to screen coordinates.
This is an optimized version of v.WorldToScreen(p).Sub(v.WorldToScreen(Point{}))