opengl

package
v0.0.0-...-d623aaa Latest Latest
Warning

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

Go to latest
Published: May 28, 2018 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFragmentShader = `
#version 330 core
in vec2 fragTexCoord;
out vec4 color;
void main() {
    color = vec4(fragTexCoord.xy,1.0,1.0);
}
` + "\x00"

DefaultFragmentShader is the fragment portion of the default shader

View Source
const DefaultVertexShader = `
#version 330 core
uniform mat4 transform;
in vec3 vert;
in vec2 vertTexCoord;
out vec2 fragTexCoord;
void main() {
	fragTexCoord = vertTexCoord;
	gl_Position = transform * vec4(vert, 1);
}
` + "\x00"

DefaultVertexShader is the vertex portion of the default shader

View Source
const SYSDPI = 72 //TODO Support customizable DPI

SYSDPI is the default (and currently fixed) DPI setting

Variables

View Source
var (
	ErrMissingVertexShader   = errors.New("vertex shader is missing")
	ErrMissingFragmentShader = errors.New("fragment shader is missing")
	ErrUniformInvalidType    = errors.New("uniform set value is not of a valid/supported type")
)

Shader errors

View Source
var (
	ErrTextureNotBound = errors.New("texture not bound to any texture unit")
)

Texture errors

Functions

func Clear

func Clear()

Clear clears the screen

func Init

func Init() error

Init initializes an OpenGL context

func Poll

func Poll()

Poll polls for events and updates all glfw functions

func SetBGColor

func SetBGColor(col color.Color)

SetBGColor sets the background (clear) color

func Terminate

func Terminate()

Terminate cleanly closes all the currently opened windows, frees resources etc.

Types

type Mesh

type Mesh struct {
	Shader *Shader
	// contains filtered or unexported fields
}

Mesh is a mesh that can be drawn

func MakeMesh

func MakeMesh(vertices []float32, indices []uint32, shader *Shader) *Mesh

MakeMesh creates a mesh with given vertices and an optional shader

func MakeQuad

func MakeQuad(shader *Shader) *Mesh

MakeQuad creates a quad with either a provided shader or a default one

func (*Mesh) Destroy

func (m *Mesh) Destroy()

Destroy cleans up all used resources from Mesh

func (*Mesh) Draw

func (m *Mesh) Draw()

Draw sets the quad's shader and draws it

type Shader

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

Shader is a OpenGL program with one vertex and one fragment shader

func DefaultShader

func DefaultShader() *Shader

DefaultShader returns a plain, kinda useless, shader

func MakeShader

func MakeShader() *Shader

MakeShader creates a shader object

func (*Shader) BindUniforms

func (s *Shader) BindUniforms()

BindUniforms sets all the uniforms to their current set value

func (*Shader) Destroy

func (s *Shader) Destroy()

Destroy frees up the resources used by the shader and makes it unusable

func (*Shader) GetProgram

func (s *Shader) GetProgram() (uint32, error)

GetProgram compiles (if needed) and returns an OpenGL program with the specified shaders

func (*Shader) GetUniform

func (s *Shader) GetUniform(str string) *Uniform

GetUniform returns the uniform value for a given shader uniform variable

func (*Shader) MustGetProgram

func (s *Shader) MustGetProgram() uint32

MustGetProgram calls GetProgram and panics if it gets an error

func (*Shader) SetFragmentSource

func (s *Shader) SetFragmentSource(src string) (err error)

SetFragmentSource sets (and updates) the fragment portion of the shader

func (*Shader) SetOutput

func (s *Shader) SetOutput(out string)

SetOutput sets the shader color output variable

func (*Shader) SetVertexSource

func (s *Shader) SetVertexSource(src string) (err error)

SetVertexSource sets (and updates) the vertex portion of the shader

func (*Shader) Use

func (s *Shader) Use()

Use sets the shader program as active

type Text

type Text struct {
	Shader *Shader
	Mesh   *Mesh
	// contains filtered or unexported fields
}

func MakeText

func MakeText(fnt *font.Font, text string) *Text

func (*Text) SetColor

func (t *Text) SetColor(col color.Color)

func (*Text) SetContent

func (t *Text) SetContent(text string)

type Texture

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

Texture is a single OpenGL texture

func MakeTexture

func MakeTexture(img *image.RGBA, options TextureOptions) *Texture

MakeTexture creates an OpenGL texture and returns it, if possible

func (*Texture) Bind

func (t *Texture) Bind(unit uint32)

Bind binds the texture to a hardware texture unit

func (*Texture) SetUniform

func (t *Texture) SetUniform(uloc int32) error

SetUniform sets the texture as uniform for a GL program

func (*Texture) Unbind

func (t *Texture) Unbind()

Unbind removes the texture from its current texture unit

type TextureFilter

type TextureFilter int32

TextureFilter sets what algorithm is used when a texture is scaled

const (
	TextureFilterNearest TextureFilter = gl.NEAREST
	TextureFilterLinear  TextureFilter = gl.LINEAR
)

Texture filter types

type TextureOptions

type TextureOptions struct {
	WrapS     WrapType
	WrapR     WrapType
	MinFilter TextureFilter
	MagFilter TextureFilter
	Mipmap    bool
}

TextureOptions contains extra options for setting up a texture

type Uniform

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

Uniform is a modifiable input for shaders

func (*Uniform) Bind

func (u *Uniform) Bind()

Bind binds the current value to the current program

func (*Uniform) Set

func (u *Uniform) Set(value interface{})

Set sets the value for the uniform that will applied when bound

type Window

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

Window is a system window with an OpenGL context inside it

func CreateWindow

func CreateWindow(width, height int, title string, monitor *glfw.Monitor, parent *Window, options WindowOptions) (*Window, error)

CreateWindow creates a window with an opengl context and returns it

func (*Window) Clear

func (w *Window) Clear()

Clear clears the window and its contents

func (*Window) DrawDone

func (w *Window) DrawDone()

DrawDone swaps the buffers after drawing

func (*Window) GetSize

func (w *Window) GetSize() image.Point

GetSize returns the window size

func (*Window) IsOpen

func (w *Window) IsOpen() bool

IsOpen returns wether the window is open or should not be closed

func (*Window) SetResizeCallback

func (w *Window) SetResizeCallback(fn WindowResizeCallback)

SetResizeCallback sets a callback to be called when the window is resized

type WindowOptions

type WindowOptions struct {
	Resizable       bool
	BackgroundColor color.Color
	DebugContext    bool
}

WindowOptions are extra options that can affect how the window looks or behaves

type WindowResizeCallback

type WindowResizeCallback func(width, height int)

WindowResizeCallback is a callback that can be called when the window is resized

type WrapType

type WrapType int32

WrapType sets how a texture wraps

const (
	TextureWrapRepeat WrapType = gl.REPEAT
	TextureWrapClamp  WrapType = gl.CLAMP_TO_EDGE
	TextureWrapMirror WrapType = gl.MIRRORED_REPEAT
)

Texture wrap types

Jump to

Keyboard shortcuts

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