Documentation ¶
Index ¶
- Constants
- func CircleToPolygon(center mgl32.Vec2, radius float32, numSegments int, startAngle float32) ([]mgl32.Vec2, error)
- func GetBoundingBox(points []mgl32.Vec2) (mgl32.Vec2, mgl32.Vec2)
- func Mat4From64to32Bits(mat mgl64.Mat4) mgl32.Mat4
- type Camera2D
- func (c *Camera2D) Height() float32
- func (c *Camera2D) MaxZoom() float32
- func (c *Camera2D) MinZoom() float32
- func (c *Camera2D) ProjectionMatrix() *mgl32.Mat4
- func (c *Camera2D) ScreenToWorld(vec mgl32.Vec2) mgl32.Vec3
- func (c *Camera2D) SetCentered(centered bool)
- func (c *Camera2D) SetFlipVertical(flip bool)
- func (c *Camera2D) SetPosition(x float32, y float32)
- func (c *Camera2D) SetVisibleArea(x1 float32, y1 float32, x2 float32, y2 float32)
- func (c *Camera2D) SetZoom(zoom float32)
- func (c *Camera2D) SetZoomRange(minZoom float32, maxZoom float32)
- func (c *Camera2D) Translate(x float32, y float32)
- func (c *Camera2D) Width() float32
- func (c *Camera2D) WorldToScreen(vec mgl32.Vec3) mgl32.Vec2
- func (c *Camera2D) Zoom() float32
- type Color
- type ModelMatrix
- type Primitive
- type Primitive2D
- func NewGridPrimitive(center mgl32.Vec3, width int, height int, gridSize int) *Primitive2D
- func NewPolylinePrimitive(center mgl32.Vec3, points []mgl32.Vec2, closed bool) *Primitive2D
- func NewQuadPrimitive(position mgl32.Vec3, size mgl32.Vec2) *Primitive2D
- func NewQuadPrimitiveExt(position mgl32.Vec3, size mgl32.Vec2, shader *ShaderProgram, ...) *Primitive2D
- func NewRectPrimitive(position mgl32.Vec3, size mgl32.Vec2, filled bool) *Primitive2D
- func NewRegularPolygonPrimitive(center mgl32.Vec3, radius float32, numSegments int, filled bool) *Primitive2D
- func NewTriangles(vertices []float32, uvCoords []float32, texture *Texture, position mgl32.Vec3, ...) *Primitive2D
- func (p *Primitive2D) Angle() float32
- func (p *Primitive2D) Color() Color
- func (p *Primitive2D) Draw(projectionMatrix *mgl32.Mat4)
- func (p *Primitive2D) ModelMatrix() *mgl32.Mat4
- func (p *Primitive2D) Position() mgl32.Vec3
- func (p *Primitive2D) SetAnchor(anchor mgl32.Vec2)
- func (p *Primitive2D) SetAnchorToCenter()
- func (p *Primitive2D) SetAngle(radians float32)
- func (p *Primitive2D) SetColor(color Color)
- func (p *Primitive2D) SetFlipX(flipX bool)
- func (p *Primitive2D) SetFlipY(flipY bool)
- func (p *Primitive2D) SetPosition(position mgl32.Vec3)
- func (p *Primitive2D) SetScale(scale mgl32.Vec2)
- func (p *Primitive2D) SetSize(size mgl32.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() mgl32.Vec2
- type ShaderProgram
- type ShaderType
- type Texture
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
)
Variables ¶
This section is empty.
Functions ¶
func CircleToPolygon ¶
func CircleToPolygon(center mgl32.Vec2, radius float32, numSegments int, startAngle float32) ([]mgl32.Vec2, error)
CircleToPolygon approximate a circle shape with a regular polygon
func GetBoundingBox ¶
GetBoundingBox returns the top left and the bottom right points of the 2D box bounding all the points passed.
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) 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
func (*Camera2D) SetZoomRange ¶
SetZoomRange sets the minimum and maximum zoom factors allowed
type ModelMatrix ¶
ModelMatrix matrix representing the primitive transformation
type Primitive ¶
type Primitive struct {
// contains filtered or unexported fields
}
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 NewGridPrimitive ¶
Creates a grid of lines with a distance of gridSize and filling the area 0,0 -> width,height
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 mgl32.Vec3, size mgl32.Vec2) *Primitive2D
NewQuadPrimitive creates a rectangular primitive filled with a texture
func NewQuadPrimitiveExt ¶
func NewQuadPrimitiveExt(position mgl32.Vec3, size mgl32.Vec2, shader *ShaderProgram, vertices []float32, uvCoords []float32) *Primitive2D
NewQuadPrimitiveExt creates a rectangular primitive filled with a texture. It accepts custom shader and coordinates
func NewRectPrimitive ¶
NewRectPrimitive creates a rectangular primitive
func NewRegularPolygonPrimitive ¶
func NewRegularPolygonPrimitive(center mgl32.Vec3, radius float32, numSegments int, filled bool) *Primitive2D
NewRegularPolygonPrimitive creates a primitive from a regular polygon
func NewTriangles ¶
func NewTriangles( vertices []float32, uvCoords []float32, texture *Texture, position mgl32.Vec3, size mgl32.Vec2, shaderProgram *ShaderProgram, ) *Primitive2D
NewTriangles creates a primitive as a collection of triangles
func (*Primitive2D) Color ¶
func (p *Primitive2D) Color() Color
Color return the color passed to the shader
func (*Primitive2D) Draw ¶
func (p *Primitive2D) Draw(projectionMatrix *mgl32.Mat4)
Draw draws the primitive
func (*Primitive2D) ModelMatrix ¶
func (p *Primitive2D) ModelMatrix() *mgl32.Mat4
ModelMatrix returns the current model matrix
func (*Primitive2D) Position ¶
func (p *Primitive2D) Position() mgl32.Vec3
Position gets X,Y,Z of the primitive.
func (*Primitive2D) SetAnchor ¶
func (p *Primitive2D) SetAnchor(anchor mgl32.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 float32)
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 mgl32.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 mgl32.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 mgl32.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