Documentation ¶
Overview ¶
Package gfx is used largly to simplify OpenGL calls and to manage state of transformations. Anything meant to be drawn to screen will come from this pacakge.
Index ¶
- func Arc(mode string, x, y, radius, angle1, angle2 float32, points int)
- func Circle(mode string, x, y, radius float32, points int)
- func Clear(r, g, b, a float32)
- func ClearScissor()
- func ClearStencilTest()
- func Ellipse(mode string, x, y, radiusx, radiusy float32, points int)
- func GetBackgroundColor() []float32
- func GetColor() []float32
- func GetColorMask() (bool, bool, bool, bool)
- func GetDimensions() (float32, float32)
- func GetHeight() float32
- func GetLineJoin() string
- func GetLineWidth() float32
- func GetPointSize() float32
- func GetScissor() (x, y, w, h int32)
- func GetViewport() []int32
- func GetWidth() float32
- func HasFramebufferSRGB() bool
- func InitContext(window *glfw.Window)
- func Origin()
- func Points(coords []float32)
- func PolyLine(coords []float32)
- func Polygon(mode string, coords []float32)
- func Pop()
- func Present()
- func Print(strs []string, colors [][]float32, argv ...float32)
- func Printf(strs []string, colors [][]float32, wrapLimit float32, align string, ...)
- func Push()
- func Rect(mode string, x, y, width, height float32)
- func Rotate(angle float32)
- func Scale(sx, sy float32)
- func SetBackgroundColor(vals ...float32)
- func SetBlendMode(mode string)
- func SetCanvas(canvas *Canvas) error
- func SetColor(r, g, b, a float32)
- func SetColorMask(r, g, b, a bool)
- func SetFont(font *Font)
- func SetLineJoin(join string)
- func SetLineWidth(width float32)
- func SetPointSize(size float32)
- func SetScissor(x, y, width, height int32)
- func SetShader(shader *Shader)
- func SetStencilTest(compare CompareMode, value int32)
- func SetViewport(x, y, w, h int32)
- func SetViewportSize(w, h int32)
- func Shear(kx, ky float32)
- func Stencil(stencilFunc func(), action StencilAction, value int32, keepvalues bool)
- func Translate(x, y float32)
- type Canvas
- type ColorMask
- type CompareMode
- type Filter
- type FilterMode
- type Font
- func (font *Font) GetAscent() float32
- func (font *Font) GetBaseline() float32
- func (font *Font) GetDescent() float32
- func (font *Font) GetFilter() Filter
- func (font *Font) GetHeight() float32
- func (font *Font) GetLineHeight() float32
- func (font *Font) GetWidth(text string) float32
- func (font *Font) GetWrap(text string, wrapLimit float32) (float32, []string)
- func (font *Font) HasGlyph(g rune) bool
- func (font *Font) Kern(first, second rune) float32
- func (font *Font) SetFallbacks(fallbacks ...*Font)
- func (font *Font) SetFilter(min, mag FilterMode) error
- func (font *Font) SetLineHeight(height float32)
- type ITexture
- type Image
- type Quad
- type Shader
- func (shader *Shader) GetUniformType(name string) (UniformType, bool)
- func (shader *Shader) SendFloat(name string, values ...float32) error
- func (shader *Shader) SendInt(name string, values ...int32) error
- func (shader *Shader) SendMat2(name string, mat mgl32.Mat2) error
- func (shader *Shader) SendMat3(name string, mat mgl32.Mat3) error
- func (shader *Shader) SendMat4(name string, mat mgl32.Mat4) error
- func (shader *Shader) SendTexture(name string, texture ITexture) error
- type SpriteBatch
- func (spriteBatch *SpriteBatch) Add(args ...float32) error
- func (spriteBatch *SpriteBatch) Addq(quad *Quad, args ...float32) error
- func (spriteBatch *SpriteBatch) Clear()
- func (spriteBatch *SpriteBatch) ClearColor()
- func (spriteBatch *SpriteBatch) ClearDrawRange()
- func (spriteBatch *SpriteBatch) Draw(args ...float32)
- func (spriteBatch *SpriteBatch) GetBufferSize() int
- func (spriteBatch *SpriteBatch) GetColor() []float32
- func (spriteBatch *SpriteBatch) GetCount() int
- func (spriteBatch *SpriteBatch) GetDrawRange() (int, int)
- func (spriteBatch *SpriteBatch) GetTexture() ITexture
- func (spriteBatch *SpriteBatch) Set(index int, args ...float32) error
- func (spriteBatch *SpriteBatch) SetBufferSize(newsize int) error
- func (spriteBatch *SpriteBatch) SetColor(vals ...float32)
- func (spriteBatch *SpriteBatch) SetDrawRange(min, max int) error
- func (spriteBatch *SpriteBatch) SetTexture(newtexture ITexture)
- func (spriteBatch *SpriteBatch) Setq(index int, quad *Quad, args ...float32) error
- type StencilAction
- type Text
- type Texture
- func (texture *Texture) Draw(args ...float32)
- func (texture *Texture) Drawq(quad *Quad, args ...float32)
- func (texture *Texture) GetDimensions() (int32, int32)
- func (texture *Texture) GetFilter() Filter
- func (texture *Texture) GetHeight() int32
- func (texture *Texture) GetWidth() int32
- func (texture *Texture) GetWrap() Wrap
- func (texture *Texture) SetFilter(min, mag FilterMode) error
- func (texture *Texture) SetWrap(wrapS, wrapT WrapMode)
- type UniformType
- type Usage
- type Wrap
- type WrapMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Arc ¶
Arc is like Arc except that you can define how many points you want to generate the arc. If it is lower it will look jagged. If it is higher it will hit performace. The drawmode specifies either a fill or line draw
func Circle ¶
Circle will draw a circle at x, y with a radius as specified. points specifies how many points should be generated in the arc. If it is lower it will look jagged. If it is higher it will hit performace. The drawmode specifies either a fill or line draw
func Clear ¶
func Clear(r, g, b, a float32)
Clear will clear everything already rendered to the screen and set is all to the r, g, b, a provided.
func ClearStencilTest ¶
func ClearStencilTest()
ClearStencilTest stops the stencil test from operating
func Ellipse ¶
Ellipse will draw a circle at x, y with a radius as specified. radiusx and radiusy will specify how much the width will be along those axis points specifies how many points should be generated in the arc. If it is lower it will look jagged. If it is higher it will hit performace. The drawmode specifies either a fill or line draw
func GetBackgroundColor ¶
func GetBackgroundColor() []float32
GetBackgroundColor gets the background color.
func GetColorMask ¶
GetColorMask will return the current color mask
func GetDimensions ¶
GetDimensions will return the width and height of screen
func GetHeight ¶
func GetHeight() float32
GetHeight will return the height of the rendering context.
func GetLineJoin ¶
func GetLineJoin() string
GetLineJoin will return the current line join. Default line join is miter.
func GetLineWidth ¶
func GetLineWidth() float32
GetLineWidth will return the current line width. Default line width is 1
func GetScissor ¶
func GetScissor() (x, y, w, h int32)
GetScissor will return the current scissor rectangle
func GetViewport ¶
func GetViewport() []int32
GetViewport will return the x, y, w, h of the opengl viewport. This is interfaced directly with opengl and used by the framework. Only use this if you know what you are doing
func HasFramebufferSRGB ¶
func HasFramebufferSRGB() bool
HasFramebufferSRGB will return true if standard RGB color space is suporrted on this system. Only supported on non ES environments.
func InitContext ¶
InitContext will initiate the opengl context with a viewport in the size of w x h. This is generally called from the game loop and wont generally need to be called unless you are rolling your own game loop.
func Origin ¶
func Origin()
Origin will reset all translations and transformations back to defaults. This function is always used to reverse any previous calls to Rotate, Scale, Shear or Translate.
func Points ¶
func Points(coords []float32)
Points will draw a point on the screen at x, y position. The size of the point is dependant on the point size set with SetPointSize.
func PolyLine ¶
func PolyLine(coords []float32)
PolyLine will draw a line with an array in the form of x1, y1, x2, y2, x3, y3, ..... xn, yn
func Polygon ¶
Polygon will draw a closed polygon with an array in the form of x1, y1, x2, y2, x3, y3, ..... xn, yn The drawmode specifies either a fill or line draw
func Pop ¶
func Pop()
Pop pops the current coordinate transformation from the transformation stack. This function is always used to reverse a previous push operation. It returns the current transformation state to what it was before the last preceding push.
func Present ¶
func Present()
Present is used at the end of the game loop to swap the frame buffers and display the next rendered frame. This is normally used by the game loop and should not be used unless rolling your own game loop.
func Printf ¶
Printf will print out a string with a wrap limit and alignment. It accepts the normal drawable arguments
func Push ¶
func Push()
Push copies and pushes the current coordinate transformation to the transformation stack. This function is always used to prepare for a corresponding pop operation later. It stores the current coordinate transformation state into the transformation stack and keeps it active. Later changes to the transformation can be undone by using the pop operation, which returns the coordinate transform to the state it was in before calling push.
func Rect ¶
Rect draws a rectangle with the top left corner at x, y with the specified width and height The drawmode specifies either a fill or line draw
func Rotate ¶
func Rotate(angle float32)
Rotate rotates the coordinate system in two dimensions. Calling this function affects all future drawing operations by rotating the coordinate system around the origin by the given amount of radians. This change lasts until drawing completes
func Scale ¶
func Scale(sx, sy float32)
Scale scales the coordinate system in two dimensions. By default the coordinate system / in amore corresponds to the display pixels in horizontal and vertical directions one-to-one, and the x-axis increases towards the right while the y-axis increases downwards. Scaling the coordinate system changes this relation. After scaling by sx and sy, all coordinates are treated as if they were multiplied by sx and sy. Every result of a drawing operation is also correspondingly scaled, so scaling by (2, 2) for example would mean making everything twice as large in both x- and y-directions. Scaling by a negative value flips the coordinate system in the corresponding direction, which also means everything will be drawn flipped or upside down, or both. Scaling by zero is not a useful operation. Scale and translate are not commutative operations, therefore, calling them in different orders will change the outcome. Scaling lasts until drawing completes
func SetBackgroundColor ¶
func SetBackgroundColor(vals ...float32)
SetBackgroundColor sets the background color.
func SetBlendMode ¶
func SetBlendMode(mode string)
SetBlendMode sets the blending mode. Blending modes are different ways to do color blending. See BlendMode constants to see how they operate.
func SetCanvas ¶
SetCanvas will set the render target to a specified Canvas. All drawing operations until the next SetCanvas call will be redirected to the Canvas and not shown on the screen. Call with a no params to enable drawing to screen again.
func SetColorMask ¶
func SetColorMask(r, g, b, a bool)
SetColorMask will set a mask for each r, g, b, and alpha component.
func SetLineJoin ¶
func SetLineJoin(join string)
SetLineJoin will change how each line joins. options are None, Bevel or Miter.
func SetLineWidth ¶
func SetLineWidth(width float32)
SetLineWidth changes the width in pixels that the lines will render when using Line or PolyLine
func SetPointSize ¶
func SetPointSize(size float32)
SetPointSize will set the size of points drawn by Point
func SetScissor ¶
func SetScissor(x, y, width, height int32)
SetScissor Sets or disables scissor. The scissor limits the drawing area to a specified rectangle. This affects all graphics calls, including Clear. The dimensions of the scissor is unaffected by graphical transformations (translate, scale, ...). if no arguments are given it will disable the scissor. if x, y, w, h are given it will enable the scissor
func SetShader ¶
func SetShader(shader *Shader)
SetShader sets or resets a Shader as the current pixel effect or vertex shaders. All drawing operations until the next SetShader will be drawn using the Shader object specified.
func SetStencilTest ¶
func SetStencilTest(compare CompareMode, value int32)
SetStencilTest configures or disables stencil testing. When stencil testing is enabled, the geometry of everything that is drawn afterward will be clipped/stencilled out based on a comparison between the arguments of this function and the stencil value of each pixel that the geometry touches. The stencil values of pixels are affected via Stencil/StencilEXT.
func SetViewport ¶
func SetViewport(x, y, w, h int32)
SetViewport will set the viewport to x, y, w, h. This is interfaced directly with opengl and used by the framework. Only use this if you know what you are doing
func SetViewportSize ¶
func SetViewportSize(w, h int32)
SetViewportSize will set the viewport to 0, 0, w, h. This is interfaced directly with opengl and used by the framework. Only use this if you know what you are doing
func Stencil ¶
func Stencil(stencilFunc func(), action StencilAction, value int32, keepvalues bool)
Stencil operates like stencil but with access to change the stencil action, value, and keepvalues.
action: How to modify any stencil values of pixels that are touched by what's drawn in the stencil function.
value: The new stencil value to use for pixels if the "replace" stencil action is used. Has no effect with other stencil actions. Must be between 0 and 1.
keepvalues: True to preserve old stencil values of pixels, false to re-set every pixel's stencil value to 0 before executing the stencil function. Clear will also re-set all stencil values.
func Translate ¶
func Translate(x, y float32)
Translate will translate the rendering origin to the point x, y. When this function is called with two numbers, dx, and dy, all the following drawing operations take effect as if their x and y coordinates were x+dx and y+dy. Scale and translate are not commutative operations, therefore, calling them in different orders will change the outcome. This change lasts until drawing completes or else a Pop reverts to a previous graphics state. Translating using whole numbers will prevent tearing/blurring of images and fonts draw after translating.
Types ¶
type Canvas ¶
type Canvas struct { *Texture // contains filtered or unexported fields }
Canvas is an off-screen render target.
type ColorMask ¶
type ColorMask struct {
// contains filtered or unexported fields
}
ColorMask contains an rgba color mask
type CompareMode ¶
type CompareMode uint32
CompareMode defines different types of per-pixel stencil test comparisons. The pixels of an object will be drawn if the comparison succeeds, for each pixel that the object touches.
const ( CompareGreater CompareMode = 0x0201 CompareEqual CompareMode = 0x0202 CompareGequal CompareMode = 0x0203 CompareLess CompareMode = 0x0204 CompareNotequal CompareMode = 0x0205 CompareLequal CompareMode = 0x0206 CompareAlways CompareMode = 0x0207 )
stenicl test modes
func GetStencilTest ¶
func GetStencilTest() (CompareMode, int32)
GetStencilTest will return the current compare mode and the stencil test value.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is a representation of texture filtering that contains both min and mag filter modes
type FilterMode ¶
type FilterMode int
FilterMode is used for setting texture/image/canvas filters
const ( FilterNone FilterMode = 0 FilterNearest FilterMode = 0x2600 FilterLinear FilterMode = 0x2601 )
texture filter
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
Font is a rasterized font data
func GetFont ¶
func GetFont() *Font
GetFont will return the currenly bound font or the frameworks font if none has be bound.
func NewImageFont ¶
NewImageFont rasterizes an image using the glyphHints. The glyphHints should list all characters in the image. The characters should all have equal width and height. Using the glyphHints, the image is split up into equal rectangles for rasterization. The function will return a pointer to a new Font
func (*Font) GetBaseline ¶
GetBaseline returns the position of the base line.
func (*Font) GetDescent ¶
GetDescent gets the height of the font below the base line
func (*Font) GetLineHeight ¶
GetLineHeight will return the current line height of the font
func (*Font) GetWrap ¶
GetWrap will split a string given a wrap limit. It will return the max width of the longest string and it will return the string split into the strings that are smaller than the wrap limit.
func (*Font) SetFallbacks ¶
SetFallbacks will add extra fonts in case some characters are not available in this font. If the character is not available it will be rendered with one of the fallback characters
func (*Font) SetFilter ¶
func (font *Font) SetFilter(min, mag FilterMode) error
SetFilter sets the filtering on the font.
func (*Font) SetLineHeight ¶
SetLineHeight sets the height between lines
type ITexture ¶
type ITexture interface { GetWidth() int32 GetHeight() int32 // contains filtered or unexported methods }
ITexture is an interface for any object that can be used like a texture.
type Image ¶
type Image struct { *Texture // contains filtered or unexported fields }
Image is an image that is drawable to the screen
func NewImage ¶
NewImage will create a new texture for this image and return the *Image. If the file does not exist or cannot be decoded it will return an error.
func NewScreenshot ¶
func NewScreenshot() *Image
NewScreenshot will take a screenshot of the screen and convert it to an image.Image
type Quad ¶
type Quad struct {
// contains filtered or unexported fields
}
Quad is essentially a crop of an image/texture
func NewQuad ¶
NewQuad will generate a new *Quad with the dimensions given x, y are position on the texture w, h are the size of the quad sw, sh are references on how large the texture is. image.GetWidth(), image.GetHeight()
func (*Quad) GetViewport ¶
GetViewport gets the current viewport of this Quad.
func (*Quad) SetViewport ¶
SetViewport sets the texture coordinates according to a viewport.
type Shader ¶
type Shader struct {
// contains filtered or unexported fields
}
Shader is a glsl program that can be applied while drawing.
func NewShader ¶
NewShader will create a new shader program. It takes in either paths to glsl files or shader code directly
func (*Shader) GetUniformType ¶
func (shader *Shader) GetUniformType(name string) (UniformType, bool)
GetUniformType will return the type and count if it exists and false if it doesn't
func (*Shader) SendFloat ¶
SendFloat allows you to pass in float32 values into your shader, by the name of the variable
func (*Shader) SendInt ¶
SendInt allows you to pass in integer values into your shader, by the name of the variable
func (*Shader) SendMat2 ¶
SendMat2 allows you to pass in a 2x2 matrix value into your shader, by the name of the variable
func (*Shader) SendMat3 ¶
SendMat3 allows you to pass in a 3x3 matrix value into your shader, by the name of the variable
type SpriteBatch ¶
type SpriteBatch struct {
// contains filtered or unexported fields
}
SpriteBatch is a collection of images/quads/textures all drawn with a single draw call
func NewSpriteBatch ¶
func NewSpriteBatch(texture ITexture, size int, usage Usage) *SpriteBatch
NewSpriteBatch is like NewSpriteBatch but allows you to set the usage.
func (*SpriteBatch) Add ¶
func (spriteBatch *SpriteBatch) Add(args ...float32) error
Add adds a sprite to the batch. Sprites are drawn in the order they are added. x, y The position to draw the object r rotation of the object sx, sy scale of the object ox, oy offset of the object kx, ky shear of the object
func (*SpriteBatch) Addq ¶
func (spriteBatch *SpriteBatch) Addq(quad *Quad, args ...float32) error
Addq adds a Quad to the batch. This is very useful for something like a tilemap.
func (*SpriteBatch) Clear ¶
func (spriteBatch *SpriteBatch) Clear()
Clear will remove all the sprites from the batch
func (*SpriteBatch) ClearColor ¶
func (spriteBatch *SpriteBatch) ClearColor()
ClearColor will reset the color back to white
func (*SpriteBatch) ClearDrawRange ¶
func (spriteBatch *SpriteBatch) ClearDrawRange()
ClearDrawRange will reset the draw range if you want to draw the whole batch again.
func (*SpriteBatch) Draw ¶
func (spriteBatch *SpriteBatch) Draw(args ...float32)
Draw satisfies the Drawable interface. Inputs are as follows x, y, r, sx, sy, ox, oy, kx, ky x, y are position r is rotation sx, sy is the scale, if sy is not given sy will equal sx ox, oy are offset kx, ky are the shear. If ky is not given ky will equal kx
func (*SpriteBatch) GetBufferSize ¶
func (spriteBatch *SpriteBatch) GetBufferSize() int
GetBufferSize will return the limit of sprites you can add to this batch.
func (*SpriteBatch) GetColor ¶
func (spriteBatch *SpriteBatch) GetColor() []float32
GetColor will return the currently used color.
func (*SpriteBatch) GetCount ¶
func (spriteBatch *SpriteBatch) GetCount() int
GetCount will return the amount of sprites already added to the batch
func (*SpriteBatch) GetDrawRange ¶
func (spriteBatch *SpriteBatch) GetDrawRange() (int, int)
GetDrawRange will return the min, max range set on the batch. If no range is set the range will return -1, -1
func (*SpriteBatch) GetTexture ¶
func (spriteBatch *SpriteBatch) GetTexture() ITexture
GetTexture will return the currently bound texture of this sprite batch.
func (*SpriteBatch) Set ¶
func (spriteBatch *SpriteBatch) Set(index int, args ...float32) error
Set changes a sprite in the batch with the same arguments as add
func (*SpriteBatch) SetBufferSize ¶
func (spriteBatch *SpriteBatch) SetBufferSize(newsize int) error
SetBufferSize will resize the buffer, change the limit of sprites you can add to this batch.
func (*SpriteBatch) SetColor ¶
func (spriteBatch *SpriteBatch) SetColor(vals ...float32)
SetColor will set the color that will be used for the next add or set operations.
func (*SpriteBatch) SetDrawRange ¶
func (spriteBatch *SpriteBatch) SetDrawRange(min, max int) error
SetDrawRange will set a range in the points to draw. This is useful if you only need to render a portion of the batch.
func (*SpriteBatch) SetTexture ¶
func (spriteBatch *SpriteBatch) SetTexture(newtexture ITexture)
SetTexture will change the texture of the batch to a new one
type StencilAction ¶
type StencilAction uint32
StencilAction is how a stencil function modifies the stencil values of pixels it touches.
const ( StencilReplace StencilAction = 0x1E01 StencilIncrement StencilAction = 0x1E02 StencilDecrement StencilAction = 0x1E03 StencilIncrementWrap StencilAction = 0x8507 StencilDecrementWrap StencilAction = 0x8508 StencilInvert StencilAction = 0x150A )
stencil actions
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is a container of text, color and text formatting.
func NewText ¶
NewText will create a colored text object with the provided font and text. A wrap and alignment can be provided as well. If wrapLimit is < 0 it will not wrap
func (*Text) Draw ¶
Draw satisfies the Drawable interface. Inputs are as follows x, y, r, sx, sy, ox, oy, kx, ky x, y are position r is rotation sx, sy is the scale, if sy is not given sy will equal sx ox, oy are offset kx, ky are the shear. If ky is not given ky will equal kx
func (*Text) GetDimensions ¶
GetDimensions will return the width and height of the text object
type Texture ¶
type Texture struct {
Width, Height int32
// contains filtered or unexported fields
}
Texture is a struct to wrap the opengl texture object
func (*Texture) Draw ¶
Draw satisfies the Drawable interface. Inputs are as follows x, y, r, sx, sy, ox, oy, kx, ky x, y are position r is rotation sx, sy is the scale, if sy is not given sy will equal sx ox, oy are offset kx, ky are the shear. If ky is not given ky will equal kx
func (*Texture) Drawq ¶
Drawq satisfies the QuadDrawable interface. Inputs are as follows quad is the quad to crop the texture x, y, r, sx, sy, ox, oy, kx, ky x, y are position r is rotation sx, sy is the scale, if sy is not given sy will equal sx ox, oy are offset kx, ky are the shear. If ky is not given ky will equal kx
func (*Texture) GetDimensions ¶
GetDimensions will return the width and height of the texture.
func (*Texture) GetWrap ¶
GetWrap will return the wrapping for how the texture behaves on a plane that is larger than itself
func (*Texture) SetFilter ¶
func (texture *Texture) SetFilter(min, mag FilterMode) error
SetFilter will set the min, mag filters for the texture filtering.
type UniformType ¶
type UniformType int
UniformType is the data type of a uniform
const ( UniformFloat UniformType = iota UniformInt UniformBool UniformSampler UniformUnknown UniformBase UniformType = iota UniformVec UniformMat )
uniform types for shaders
type Usage ¶
type Usage uint32
Usage is used for sprite batch usage, and specifies if it is static, dynamic, or stream