Documentation ¶
Index ¶
- Constants
- type Camera2D
- func (c *Camera2D) ProjectionMatrix() mgl64.Mat4
- func (c *Camera2D) ProjectionMatrix32() mgl32.Mat4
- func (c *Camera2D) ScreenToWorld(vec mgl64.Vec2) mgl64.Vec3
- func (c *Camera2D) SetCentered(centered bool)
- func (c *Camera2D) SetFlipVertical(flip bool)
- func (c *Camera2D) SetPosition(x float64, y float64)
- func (c *Camera2D) SetVisibleArea(x1 float32, y1 float32, x2 float32, y2 float32)
- func (c *Camera2D) SetZoom(zoom float64)
- func (c *Camera2D) Translate(x float64, y float64)
- func (c *Camera2D) WorldToScreen(vec mgl64.Vec3) mgl64.Vec2
- func (c *Camera2D) Zoom() float64
- type Color
- type Context
- type Drawable
- type ModelMatrix
- type Primitive
- type Primitive2D
- func NewPolylinePrimitive(center mgl64.Vec3, points []mgl64.Vec2, closed bool) *Primitive2D
- func NewQuadPrimitive(position mgl64.Vec3, size mgl64.Vec2) *Primitive2D
- func NewRegularPolygonPrimitive(center mgl64.Vec3, radius float64, numSegments int, filled bool) *Primitive2D
- func NewTriangles(vertices []float32, uvCoords []float32, texture *Texture, position mgl64.Vec3, ...) *Primitive2D
- func (p *Primitive2D) Angle() float64
- func (p *Primitive2D) Draw(context *Context)
- func (p *Primitive2D) DrawInBatch(context *Context)
- func (p *Primitive2D) ModelMatrix() *mgl64.Mat4
- func (p *Primitive2D) ModelMatrix32() *mgl32.Mat4
- func (p *Primitive2D) Position() mgl64.Vec3
- func (p *Primitive2D) SetAnchor(anchor mgl64.Vec2)
- func (p *Primitive2D) SetAnchorToCenter()
- func (p *Primitive2D) SetAngle(radians float64)
- func (p *Primitive2D) SetColor(color Color)
- func (p *Primitive2D) SetFlipX(flipX bool)
- func (p *Primitive2D) SetFlipY(flipY bool)
- func (p *Primitive2D) SetPosition(position mgl64.Vec3)
- func (p *Primitive2D) SetScale(scale mgl64.Vec2)
- func (p *Primitive2D) SetSize(size mgl64.Vec2)
- func (p *Primitive2D) SetSizeFromTexture()
- func (p *Primitive2D) SetUVCoords(uvCoords []float32)
- func (p *Primitive2D) SetUniforms()
- func (p *Primitive2D) SetVertices(vertices []float32)
- func (p *Primitive2D) Size() mgl64.Vec2
- type ShaderProgram
- type ShaderType
- type Texture
- type TextureStorage
Constants ¶
const ( // VertexShaderBase is the simplest vertex shader you can have. It uses only the model and the projection matrix VertexShaderBase = ` #version 410 core uniform mat4 model; uniform mat4 projection; layout(location=0) in vec2 vertex; layout(location=1) in vec2 uv; out vec2 uv_out; void main() { vec4 vertex_world = model * vec4(vertex, 0, 1); gl_Position = projection * vertex_world; uv_out = uv; } ` + "\x00" // FragmentShaderSolidColor used to have a solid color shape/primitive FragmentShaderSolidColor = ` #version 410 core in vec2 uv_out; out vec4 out_color; uniform vec4 color; uniform sampler2D tex; void main() { out_color = color; } ` + "\x00" // FragmentShaderTexture implements a basic texture mapping FragmentShaderTexture = ` #version 410 core in vec2 uv_out; out vec4 color; uniform sampler2D tex; void main() { color = texture(tex, uv_out); } ` + "\x00" )
const (
// Float32Size is the size (in bytes) of a float32
Float32Size = 4
)
const MaxZoom float64 = 20
const MinZoom float64 = 0.01
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camera2D ¶
type Camera2D struct {
// contains filtered or unexported fields
}
Camera2D a Camera based on an orthogonal projection
func NewCamera2D ¶
NewCamera2D sets up an orthogonal projection camera
func (*Camera2D) ProjectionMatrix ¶
ProjectionMatrix returns the projection matrix of the camera
func (*Camera2D) ProjectionMatrix32 ¶
ProjectionMatrix32 returns the projection matrix of the camera as mgl32.Mat4
func (*Camera2D) SetCentered ¶
SetCentered sets the center of the camera to the center of the screen
func (*Camera2D) SetFlipVertical ¶
SetFlipVertical sets the orientation of the vertical axis. Pass true to have a cartesian coordinate system
func (*Camera2D) SetPosition ¶
SetPosition sets the current position of the camera. If the camera is centered, the center will be moving
func (*Camera2D) SetVisibleArea ¶
SetVisibleArea configures the camera to make the specified area completely visible, position and zoom are changed accordingly
type Context ¶
type Context struct { Camera2D *Camera2D // contains filtered or unexported fields }
Context ...
func (*Context) BindShader ¶
func (c *Context) BindShader(shader *ShaderProgram)
BindShader sets shader to be current shader if it isn't already
func (*Context) BindTexture ¶
BindTexture sets texture to be current texture if it isn't already
type Drawable ¶
type Drawable interface { Texture() *Texture Shader() *ShaderProgram Draw(context *Context) DrawInBatch(context *Context) }
Drawable ...
type ModelMatrix ¶
ModelMatrix matrix representing the primitive transformation
type Primitive ¶
type Primitive struct {
// contains filtered or unexported fields
}
func (*Primitive) DrawInBatch ¶
func (*Primitive) SetShader ¶
func (p *Primitive) SetShader(shader *ShaderProgram)
func (*Primitive) SetTexture ¶
func (*Primitive) Shader ¶
func (p *Primitive) Shader() *ShaderProgram
type Primitive2D ¶
type Primitive2D struct { Primitive // contains filtered or unexported fields }
Primitive2D a drawing primitive on the XY plane
func NewPolylinePrimitive ¶
NewPolylinePrimitive creates a primitive from a sequence of points. The points coordinates are relative to the passed center
func NewQuadPrimitive ¶
func NewQuadPrimitive(position mgl64.Vec3, size mgl64.Vec2) *Primitive2D
NewQuadPrimitive creates a rectangular primitive
func NewRegularPolygonPrimitive ¶
func NewRegularPolygonPrimitive(center mgl64.Vec3, radius float64, numSegments int, filled bool) *Primitive2D
NewRegularPolygonPrimitive creates a primitive from a regular polygon
func NewTriangles ¶
func NewTriangles( vertices []float32, uvCoords []float32, texture *Texture, position mgl64.Vec3, size mgl64.Vec2, shaderProgram *ShaderProgram, ) *Primitive2D
NewTriangles creates a primitive as a collection of triangles
func (*Primitive2D) DrawInBatch ¶
func (p *Primitive2D) DrawInBatch(context *Context)
DrawInBatch draws the primitive assuming that the correct texture and shader are already bound
func (*Primitive2D) ModelMatrix ¶
func (p *Primitive2D) ModelMatrix() *mgl64.Mat4
ModelMatrix returns the current model matrix
func (*Primitive2D) ModelMatrix32 ¶
func (p *Primitive2D) ModelMatrix32() *mgl32.Mat4
ModelMatrix returns the current model matrix as mgl32.Mat4
func (*Primitive2D) Position ¶
func (p *Primitive2D) Position() mgl64.Vec3
Position gets X,Y,Z of the primitive.
func (*Primitive2D) SetAnchor ¶
func (p *Primitive2D) SetAnchor(anchor mgl64.Vec2)
SetAnchor sets the anchor point of the primitive, this will be the point placed at Position
func (*Primitive2D) SetAnchorToCenter ¶
func (p *Primitive2D) SetAnchorToCenter()
SetAnchorToCenter sets the anchor at the center of the primitive
func (*Primitive2D) SetAngle ¶
func (p *Primitive2D) SetAngle(radians float64)
SetAngle sets the rotation angle around the Z axis
func (*Primitive2D) SetColor ¶
func (p *Primitive2D) SetColor(color Color)
SetColor sets the color passed to the shader
func (*Primitive2D) SetFlipX ¶
func (p *Primitive2D) SetFlipX(flipX bool)
SetFlipX flips the primitive around the Y axis
func (*Primitive2D) SetFlipY ¶
func (p *Primitive2D) SetFlipY(flipY bool)
SetFlipY flips the primitive around the X axis
func (*Primitive2D) SetPosition ¶
func (p *Primitive2D) SetPosition(position mgl64.Vec3)
SetPosition sets the X,Y,Z position of the primitive. Z is used for the drawing order
func (*Primitive2D) SetScale ¶
func (p *Primitive2D) SetScale(scale mgl64.Vec2)
SetScale sets the scaling factor on X and Y for the primitive. The scaling respects the anchor and the rotation
func (*Primitive2D) SetSize ¶
func (p *Primitive2D) SetSize(size mgl64.Vec2)
SetSize sets the size (in pixels) of the current primitive
func (*Primitive2D) SetSizeFromTexture ¶
func (p *Primitive2D) SetSizeFromTexture()
SetSizeFromTexture sets the size of the current primitive to the pixel size of the texture
func (*Primitive2D) SetUVCoords ¶
func (p *Primitive2D) SetUVCoords(uvCoords []float32)
SetUVCoords uploads new UV coordinates
func (*Primitive2D) SetUniforms ¶
func (p *Primitive2D) SetUniforms()
SetUniforms sets the shader's uniform variables
func (*Primitive2D) SetVertices ¶
func (p *Primitive2D) SetVertices(vertices []float32)
SetVertices uploads new set of vertices into opengl buffer
type ShaderProgram ¶
type ShaderProgram struct {
// contains filtered or unexported fields
}
ShaderProgram a representation of an OpenGL shader program
func NewDefaultShaderProgram ¶
func NewDefaultShaderProgram() *ShaderProgram
NewDefaultShaderProgram creates a base shader that can render solid color pixels
func NewShaderProgram ¶
func NewShaderProgram(vertSource string, geomSource string, fragSource string) *ShaderProgram
NewShaderProgram creates a new program using the shaders source code passed as plain text
func (*ShaderProgram) AttachShader ¶
func (s *ShaderProgram) AttachShader(source string, shaderType ShaderType)
AttachShader attaches a shader to this program
func (*ShaderProgram) GetUniform ¶
func (s *ShaderProgram) GetUniform(name string) int32
GetUniform returns a uniform from the shader. Uses a uniform's location cache to speed up the look up
func (*ShaderProgram) ID ¶
func (s *ShaderProgram) ID() uint32
ID returns the OpenGL ID assigned to this shader program
func (*ShaderProgram) Link ¶
func (s *ShaderProgram) Link()
Link links together all the shaders into a shader program
func (*ShaderProgram) Release ¶
func (s *ShaderProgram) Release()
Release releases all the resources associated with this program
func (*ShaderProgram) SetUniform ¶
func (s *ShaderProgram) SetUniform(name string, val interface{})
SetUniform sets the shader's uniforms based on the type of the value passed
type ShaderType ¶
type ShaderType uint32
ShaderType Type of the shader
const ( VERTEX ShaderType = gl.VERTEX_SHADER GEOMETRY ShaderType = gl.GEOMETRY_SHADER FRAGMENT ShaderType = gl.FRAGMENT_SHADER )
Types of shaders supported
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
Texture a representation of an image file in memory
func NewEmptyTexture ¶
NewEmptyTexture creates an empty texture with a specified size
func NewTextureFromFile ¶
NewTextureFromFile loads the image from a file into a texture
func NewTextureFromImage ¶
NewTextureFromImage uses the data from an Image struct to create a texture
type TextureStorage ¶
type TextureStorage struct {
// contains filtered or unexported fields
}
TextureStorage handles multiple textures, each one with its own id
func MakeTextureStorage ¶
func MakeTextureStorage(path string) *TextureStorage
MakeTextureStorage creates a new initialized instance
func (*TextureStorage) LoadTexture ¶
func (ts *TextureStorage) LoadTexture(fileName string, textureId string)
LoadTexture loads a texture from file and assigns an id to it
func (*TextureStorage) TextureForId ¶
func (ts *TextureStorage) TextureForId(textureId string) *Texture
TextureForId returns the texture associated with the id