Documentation ¶
Index ¶
- Constants
- type Color
- type Context
- func (c *Context) BindShader(shader *ShaderProgram)
- func (c *Context) BindTexture(texture *Texture)
- func (c *Context) EnqueueForDrawing(drawable Drawable)
- func (c *Context) EraseDrawableList()
- func (c *Context) RenderDrawableList()
- func (c *Context) SetOrtho2DProjection(windowWidth int, windowHeight int, screenScale float32, centered bool)
- type Drawable
- type ModelMatrix
- type Primitive
- type Primitive2D
- func NewPolylinePrimitive(position mgl32.Vec3, points []mgl32.Vec2, closed bool) *Primitive2D
- func NewQuadPrimitive(position mgl32.Vec3, size mgl32.Vec2) *Primitive2D
- func NewRegularPolygonPrimitive(position mgl32.Vec3, radius float32, numSegments int, filled bool) *Primitive2D
- func NewTriangles(vertices []float32, uvCoords []float32, texture *Texture, position mgl32.Vec3, ...) *Primitive2D
- func (p *Primitive2D) Draw(context *Context)
- func (p *Primitive2D) DrawInBatch(context *Context)
- func (p *Primitive2D) EnqueueForDrawing(context *Context)
- func (p *Primitive2D) GetSize() mgl32.Vec2
- func (p *Primitive2D) ModelMatrix() *mgl32.Mat4
- func (p *Primitive2D) SetAnchor(anchor mgl32.Vec2)
- func (p *Primitive2D) SetAnchorToBottomCenter()
- 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)
- type ShaderProgram
- type ShaderType
- type Texture
Constants ¶
View Source
const ( 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 = ` #version 410 core in vec2 uv_out; out vec4 out_color; uniform vec4 color; uniform sampler2D tex; void main() { out_color = color; } ` + "\x00" FragmentShaderTexture = ` #version 410 core in vec2 uv_out; out vec4 color; uniform sampler2D tex; void main() { if(texture(tex, uv_out).a != 1.0f) { discard; } color = texture(tex, uv_out); } ` + "\x00" )
View Source
const FLOAT32_SIZE = 4
View Source
const (
VertexShaderPrimitive2D = `
#version 410 core
uniform mat4 mModel;
uniform mat4 mProjection;
layout(location=0) in vec2 vertex;
layout(location=1) in vec2 uv;
out vec2 uv_out;
void main() {
vec4 vertex_world = mModel * vec4(vertex, 0, 1);
gl_Position = mProjection * vertex_world;
uv_out = uv;
}
` + "\x00"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context ...
func (*Context) BindShader ¶
func (c *Context) BindShader(shader *ShaderProgram)
BindShader sets shader to be current chader if it isn't already
func (*Context) BindTexture ¶
BindTexture sets texture to be current texture if it isn't already
func (*Context) EnqueueForDrawing ¶
EnqueueForDrawing adds a drawable to drawing list
func (*Context) EraseDrawableList ¶
func (c *Context) EraseDrawableList()
EraseDrawableList resets primitivesToDraw to empty list
func (*Context) RenderDrawableList ¶
func (c *Context) RenderDrawableList()
RenderDrawableList binds shader and texture for each primitive and calls DrawInBatch
type Drawable ¶
type Drawable interface { Texture() *Texture Shader() *ShaderProgram Draw(context *Context) DrawInBatch(context *Context) }
Drawable ...
type ModelMatrix ¶
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 }
func NewPolylinePrimitive ¶
func NewQuadPrimitive ¶
func NewQuadPrimitive(position mgl32.Vec3, size mgl32.Vec2) *Primitive2D
func NewTriangles ¶
func NewTriangles( vertices []float32, uvCoords []float32, texture *Texture, position mgl32.Vec3, size mgl32.Vec2, shaderProgram *ShaderProgram, ) *Primitive2D
func (*Primitive2D) Draw ¶
func (p *Primitive2D) Draw(context *Context)
func (*Primitive2D) DrawInBatch ¶
func (p *Primitive2D) DrawInBatch(context *Context)
Texture and shaders are already bound when this is called
func (*Primitive2D) EnqueueForDrawing ¶
func (p *Primitive2D) EnqueueForDrawing(context *Context)
func (*Primitive2D) GetSize ¶
func (p *Primitive2D) GetSize() mgl32.Vec2
func (*Primitive2D) ModelMatrix ¶
func (p *Primitive2D) ModelMatrix() *mgl32.Mat4
func (*Primitive2D) SetAnchor ¶
func (p *Primitive2D) SetAnchor(anchor mgl32.Vec2)
func (*Primitive2D) SetAnchorToBottomCenter ¶
func (p *Primitive2D) SetAnchorToBottomCenter()
func (*Primitive2D) SetAnchorToCenter ¶
func (p *Primitive2D) SetAnchorToCenter()
func (*Primitive2D) SetAngle ¶
func (p *Primitive2D) SetAngle(radians float32)
func (*Primitive2D) SetColor ¶
func (p *Primitive2D) SetColor(color Color)
func (*Primitive2D) SetFlipX ¶
func (p *Primitive2D) SetFlipX(flipX bool)
func (*Primitive2D) SetFlipY ¶
func (p *Primitive2D) SetFlipY(flipY bool)
func (*Primitive2D) SetPosition ¶
func (p *Primitive2D) SetPosition(position mgl32.Vec3)
func (*Primitive2D) SetScale ¶
func (p *Primitive2D) SetScale(scale mgl32.Vec2)
func (*Primitive2D) SetSize ¶
func (p *Primitive2D) SetSize(size mgl32.Vec2)
func (*Primitive2D) SetSizeFromTexture ¶
func (p *Primitive2D) SetSizeFromTexture()
func (*Primitive2D) SetUVCoords ¶
func (p *Primitive2D) SetUVCoords(uvCoords []float32)
SetUVCoords uploads new UV coordinates
func (*Primitive2D) SetUniforms ¶
func (p *Primitive2D) SetUniforms()
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
}
func NewDefaultShaderProgram ¶
func NewDefaultShaderProgram() *ShaderProgram
func NewShaderProgram ¶
func NewShaderProgram(vertSource string, geomSource string, fragSource string) *ShaderProgram
func (*ShaderProgram) AttachShader ¶
func (s *ShaderProgram) AttachShader(source string, shaderType ShaderType)
func (*ShaderProgram) GetUniform ¶
func (s *ShaderProgram) GetUniform(name string) int32
func (*ShaderProgram) Id ¶
func (s *ShaderProgram) Id() uint32
func (*ShaderProgram) Link ¶
func (s *ShaderProgram) Link()
func (*ShaderProgram) Release ¶
func (s *ShaderProgram) Release()
func (*ShaderProgram) SetUniform ¶
func (s *ShaderProgram) SetUniform(name string, val interface{})
type ShaderType ¶
type ShaderType uint32
const ( VERTEX ShaderType = gl.VERTEX_SHADER GEOMETRY ShaderType = gl.GEOMETRY_SHADER FRAGMENT ShaderType = gl.FRAGMENT_SHADER )
type Texture ¶
type Texture struct {
// contains filtered or unexported fields
}
func NewTextureFromFile ¶
func NewTextureFromImage ¶
Click to show internal directories.
Click to hide internal directories.