graphics

package
v0.0.0-...-33f8f51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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 Color

type Color mgl32.Vec4

func NewColor

func NewColor(r, g, b, a float32) *Color

func (*Color) A

func (c *Color) A() float32

func (*Color) B

func (c *Color) B() float32

func (*Color) G

func (c *Color) G() float32

func (*Color) R

func (c *Color) R() float32

func (*Color) Set

func (c *Color) Set(r, g, b, a float32)

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

func (c *Context) BindTexture(texture *Texture)

BindTexture sets texture to be current texture if it isn't already

func (*Context) EnqueueForDrawing

func (c *Context) EnqueueForDrawing(drawable Drawable)

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

func (*Context) SetOrtho2DProjection

func (c *Context) SetOrtho2DProjection(windowWidth int, windowHeight int, screenScale float32, centered bool)

SetOrtho2DProjection sets up orthogonal projection matrix

type Drawable

type Drawable interface {
	Texture() *Texture
	Shader() *ShaderProgram
	Draw(context *Context)
	DrawInBatch(context *Context)
}

Drawable ...

type ModelMatrix

type ModelMatrix struct {
	mgl32.Mat4
	// contains filtered or unexported fields
}

type Primitive

type Primitive struct {
	// contains filtered or unexported fields
}

func (*Primitive) Draw

func (p *Primitive) Draw(context *Context)

func (*Primitive) DrawInBatch

func (p *Primitive) DrawInBatch(context *Context)

func (*Primitive) SetShader

func (p *Primitive) SetShader(shader *ShaderProgram)

func (*Primitive) SetTexture

func (p *Primitive) SetTexture(texture *Texture)

func (*Primitive) Shader

func (p *Primitive) Shader() *ShaderProgram

func (*Primitive) Texture

func (p *Primitive) Texture() *Texture

type Primitive2D

type Primitive2D struct {
	Primitive
	// contains filtered or unexported fields
}

func NewPolylinePrimitive

func NewPolylinePrimitive(position mgl32.Vec3, points []mgl32.Vec2, closed bool) *Primitive2D

func NewQuadPrimitive

func NewQuadPrimitive(position mgl32.Vec3, size mgl32.Vec2) *Primitive2D

func NewRegularPolygonPrimitive

func NewRegularPolygonPrimitive(position mgl32.Vec3, radius float32, numSegments int, filled bool) *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 (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

type Texture

type Texture struct {
	// contains filtered or unexported fields
}

func NewEmptyTexture

func NewEmptyTexture(width int, height int) (*Texture, error)

func NewTextureFromFile

func NewTextureFromFile(filePath string) *Texture

func NewTextureFromImage

func NewTextureFromImage(imageData image.Image) *Texture

func (*Texture) Id

func (t *Texture) Id() uint32

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL