Documentation ¶
Index ¶
- Constants
- func CheckError() error
- func Destroy()
- func ExecuteSets(sets []ChordSet, win *glfw.Window)
- func Init() error
- func OpenImages(filenames ...string) ([]*image.RGBA, error)
- func SetGLDefaults()
- func UseDefaultFramebuffer()
- type Animation
- type AnimationMap
- type Attribute
- type Character
- type CharacterDict
- type Chord
- type ChordSet
- type Cycler
- type Fbo
- type FontMap
- type GlError
- type NamedItems
- type Program
- func (prog *Program) AddShader(shaderType uint32, source string, uniformNames []string, attribs ...Attribute)
- func (prog *Program) Build() error
- func (prog *Program) Compile() error
- func (prog *Program) Compute() *Shader
- func (prog *Program) Delete()
- func (prog *Program) Fragment() *Shader
- func (prog *Program) Geometry() *Shader
- func (prog *Program) Link() error
- func (prog *Program) Use()
- func (prog *Program) Vertex() *Shader
- type Selecter
- type Shader
- func (s *Shader) Attributes() (copy []Attribute)
- func (s *Shader) SetFloat(uniformName string, count int32, val *float32)
- func (s *Shader) SetInt(uniformName string, count int32, val *int32)
- func (s *Shader) SetMat4(uniformName string, count int32, val *mgl32.Mat4)
- func (s *Shader) SetVec2(uniformName string, count int32, val *mgl32.Vec2)
- func (s *Shader) SetVec3(uniformName string, count int32, val *mgl32.Vec3)
- func (s *Shader) SetVec4(uniformName string, count int32, val *mgl32.Vec4)
- type Skybox
- type Texture2D
- type Timer
- type Vao
- func (v *Vao) CountVerts() int32
- func (v *Vao) Delete()
- func (v *Vao) Draw()
- func (v *Vao) DrawOptions(mode uint32, first, count int32)
- func (v *Vao) SetEbo(data []uint32)
- func (v *Vao) SetEboOptions(sizeInBytes int, data []uint32, usage uint32)
- func (v *Vao) SetTexture(uniformName string, texture *Texture2D)
- func (v *Vao) SetVbo(data []float32)
- func (v *Vao) SetVboOptions(sizeInBytes int, data []float32, usage uint32)
- type Window
- func (platform *Window) AddCharCallback(callback glfw.CharCallback)
- func (platform *Window) AddKeyCallback(callback glfw.KeyCallback)
- func (platform *Window) AddMouseButtonCallback(callback glfw.MouseButtonCallback)
- func (platform *Window) AddScrollCallback(callback glfw.ScrollCallback)
- func (platform *Window) Aspect() float32
- func (platform *Window) BeginFrame() (continueRendering bool)
- func (platform *Window) CanUseGui() bool
- func (platform *Window) CapturesKeyboard() bool
- func (platform *Window) CapturesMouse() bool
- func (platform *Window) ClearBuffers()
- func (platform *Window) ClipboardText() string
- func (platform *Window) DisplaySize() [2]float32
- func (platform *Window) Dispose()
- func (platform *Window) FramebufferSize() [2]float32
- func (platform *Window) Fullscreen(full bool, width, height int) (setWidth, setHeight int)
- func (platform *Window) InitLoop()
- func (platform *Window) MakeContextCurrent()
- func (platform *Window) PollEvents()
- func (platform *Window) RenderImgui(gui func())
- func (platform *Window) ScreenCapture() image.Image
- func (platform *Window) SetClipboardText(text string)
- func (platform *Window) ShouldClose() bool
- func (platform *Window) SwapBuffers()
- type WindowMetric
- type WindowOption
Constants ¶
const ( SizeOfByte = 1 SizeOfFloat = 4 * SizeOfByte SizeOfInt = 4 * SizeOfByte SizeOfV3 = 3 * SizeOfFloat SizeOfV4 = 4 * SizeOfFloat SizeOfM4 = 4 * SizeOfV4 )
Size of common types in bytes.
const ( Float32 = gl.FLOAT Int32 = gl.INT Uint32 = gl.UNSIGNED_INT Int8 = gl.BYTE Uint8 = gl.UNSIGNED_BYTE )
Common vertex attribute types.
const ( VertexShader = gl.VERTEX_SHADER FragmentShader = gl.FRAGMENT_SHADER GeometryShader = gl.GEOMETRY_SHADER ComputeShader = gl.COMPUTE_SHADER )
Aliases for common shader types to avoid slow autocomplete of gl pkg.
const ( Triangles = gl.TRIANGLES Points = gl.POINTS Lines = gl.LINES TriangleStrip = gl.TRIANGLE_STRIP TriangleFan = gl.TRIANGLE_FAN )
Easier access to gl "draw mode" types.
Variables ¶
This section is empty.
Functions ¶
func CheckError ¶
func CheckError() error
func ExecuteSets ¶
ExecuteSets calls Execute() on each ChordSet.
func Init ¶
func Init() error
Init should be called once to initalize GLFW along with a deferred call to Destroy.
func OpenImages ¶
OpenImages opens the images specified by filename and converts them to RGBA format.
func SetGLDefaults ¶
func SetGLDefaults()
SetGLDefaults sets a few opengl options that I commonly use.
func UseDefaultFramebuffer ¶
func UseDefaultFramebuffer()
UseDefaultFramebuffer unbinds other FBOs and binds the default framebuffer.
Types ¶
type Animation ¶
Animation is a function that takes a time delta and returns whether or not the animation has completed.
type AnimationMap ¶
AnimationMap holds animations keyed by some name.
func (AnimationMap) Float32 ¶
func (am AnimationMap) Float32(name string, value *float32, durationSec, from, to float32)
Float32 inserts a new animation with "name" which animates the value from "from" to "to" over "durationSec" seconds.
func (AnimationMap) Has ¶
func (am AnimationMap) Has(name string) bool
Has checks the animation map for an animation of the given name.
func (AnimationMap) Update ¶
func (am AnimationMap) Update(dt float32)
Update every animation in the map, deleting those that are completed.
type Attribute ¶
type CharacterDict ¶
type CharacterDict struct {
// contains filtered or unexported fields
}
func NewCharacterDict ¶
func NewCharacterDict(font *basicfont.Face) *CharacterDict
func (CharacterDict) Delete ¶
func (cd CharacterDict) Delete()
func (CharacterDict) DrawString ¶
func (cd CharacterDict) DrawString(text string, x, y, scale float32, color mgl32.Vec3, width, height float32)
(0, 0) are in the top left of the screen (inverted Y compared to standard opengl)
type Chord ¶
type Chord struct { Keys []glfw.Key // List of keys to be down to execute this chord Mouse []glfw.MouseButton // List of mouse buttons to be down to execute this chord Execute func() // The function to execute Wait float64 // Wait time (seconds) between sucessive allowable executions Stop bool // When set, no further chords will be executed after this one has been // contains filtered or unexported fields }
Chord is an input "gesture", which may be one or more keys (eg CTRL+ALT+T) or mouse buttons (A + left-click).
type ChordSet ¶
type ChordSet []Chord
ChordSet is a logic grouping of (related) Chords.
func CombineSets ¶
CombineSets makes a slice of ChordSets for convenience, sorting each one.
func (ChordSet) Execute ¶
Execute runs the function for each Chord that matches the current key state. Execution of chords will stop when the first chord is encountered with its "Stop" member set to true.
func (ChordSet) Less ¶
Less reports whether the element with index i should sort before the element with index j.
type Cycler ¶
Cycler lets one easily cycle through a list of "whatever". It's a simpler version of Selecter that doesn't name items and allows only relative (Next() and Previous()) selection changes.
func NewCycler ¶
func NewCycler(items ...interface{}) *Cycler
NewCycler creates a Cycler from items.
type Fbo ¶
type Fbo struct { ID uint32 Width, Height int32 ColorBuffer *Texture2D // contains filtered or unexported fields }
Fbo is a very simple Frame Buffer Object with a texture bound as a color attachment and renderbuffer for depth and stencil attachments.
type FontMap ¶
FontMap associates a friendly name (key) with info about a font loaded for use with imgui. The Filename and Size fields are used during initializtion of imgui.
type NamedItems ¶
type NamedItems []selecteritem
NamedItems is a slice of structs that pairs a Name string with any Item.
func MakeItems ¶
func MakeItems(items ...interface{}) NamedItems
MakeItems creates a NamedItems from the provided "items". Items implementing fmt.Stringer use that for Name. Most other types use their (possibly truncated) go representation, which will be annotated with its type for types such as slices, structs, etc.
func (NamedItems) Sort ¶
func (items NamedItems) Sort() NamedItems
Sort the NamedItems by Name, descending (alphabetical). Returns the NamedItems for "inline" use.
type Program ¶
func NewProgram ¶
func NewProgram() *Program
type Selecter ¶
Selecter lets someone create an indexed list of "whatever" with an associated name. The current selection can be changed absolutely (with Set()) or relatively (with Next() and Previous()). Only 1 item can be selected. This is helpful for use with imgui's combo box or list box.
func NewSelecter ¶
func NewSelecter(items NamedItems) *Selecter
NewSelecter creates a Selecter using the items to populate its Things and Names slices.
func (*Selecter) Get ¶
func (s *Selecter) Get() selecteritem
Get the current item. example:
fmt.Println(selecter.Get().Name) thing := selecter.Get().Item.(mytype)
func (*Selecter) Next ¶
func (s *Selecter) Next()
Next changes the selection to the next item, or wraps around if at the end.
func (*Selecter) Previous ¶
func (s *Selecter) Previous()
Previous changes the selection to the previous item, or wraps around if at the end.
func (*Selecter) SelectedName ¶
SelectedName performs a linear search on the Names slice for name and, if a match is found, returns true if it is the current selection.
type Shader ¶
type Shader struct { ID uint32 Type uint32 // gl.VERTEX_SHADER, gl.FRAGMENT_SHADER, etc Source string Attribs map[string]*Attribute Uniforms map[string]int32 }
func (*Shader) Attributes ¶
Attributes gets a slice of copies of the shader's attributes.
type Skybox ¶
Skybox is a complete cubemap skybox.
type Timer ¶
type Timer struct { TotalFrames uint64 TotalTime float64 DeltaT float64 // Seconds Start time.Time Now time.Time }
Timer keeps time and other similar info useful for an opengl render loop.
func (*Timer) AvgFps ¶
AvgFps gets the average framerate over the total program runtime (or since Reset() was called).
func (*Timer) IsNthFrame ¶
IsNthFrame returns true if the current frame number is on the "nth" since the timer was last reset. Just frame count mod n == 0. Example:
if timer.IsNthFrame(2) { // do something every other frame }
type Vao ¶
type Vao struct { VaoID uint32 // id for vao Vbo uint32 // id for vertex buffer object associated with this vao Ebo uint32 // id for element (vertex index) buffer associated with this vao DrawMode uint32 // "mode" for drawing, such as TRIANGLES or LINES Tex []*Texture2D // ids for all textures to be used with this vao (on draw) Prog *Program // program to load when drawing // contains filtered or unexported fields }
func (*Vao) CountVerts ¶
func (*Vao) DrawOptions ¶
DrawOptions call Vao.Prog.Use() before drawing.
func (*Vao) SetEboOptions ¶
func (*Vao) SetTexture ¶
SetTexture associates named uniform (in frag shader) with this texture, and also associates the texture with the texture "number" of the texture's index in the Tex slice. eg. TEXTURE0 is at Tex[0], TEXTURE1 at Tex[1], etc.
type Window ¶
type Window struct { // Allows direct access to some of the imgui data. Gui *imguiData // Allows direct access to the glfw window. GlfwWindow *glfw.Window // OpenGL version and driver info. GlVersion string // Basically 'read only' info about the dimensions of the window. Dimensions WindowMetric // Updated each frame. Clock Timer // contains filtered or unexported fields }
Window implements a window, opengl contenxt based on github.com/go-gl/glfw (v3.3), and (optionally) imgui context. It also has additional helpful features.
func NewWindow ¶
func NewWindow(title string, size WindowMetric, options ...WindowOption) (*Window, error)
NewWindow attempts to initialize a GLFW context/window/imgui etc.
func (*Window) AddCharCallback ¶
func (platform *Window) AddCharCallback(callback glfw.CharCallback)
func (*Window) AddKeyCallback ¶
func (platform *Window) AddKeyCallback(callback glfw.KeyCallback)
func (*Window) AddMouseButtonCallback ¶
func (platform *Window) AddMouseButtonCallback(callback glfw.MouseButtonCallback)
func (*Window) AddScrollCallback ¶
func (platform *Window) AddScrollCallback(callback glfw.ScrollCallback)
func (*Window) BeginFrame ¶
BeginFrame updates certain state for the new frame, and returns true if the render loop should continue running.
func (*Window) CapturesKeyboard ¶
CapturesKeyboard returns true if Imgui is capturing keyboard input.
func (*Window) CapturesMouse ¶
CapturesMouse returns true if Imgui is capturing mouse input.
func (*Window) ClearBuffers ¶
func (platform *Window) ClearBuffers()
ClearBuffers clears color buffer and depth buffer.
func (*Window) ClipboardText ¶
ClipboardText returns the current clipboard text, if available.
func (*Window) DisplaySize ¶
DisplaySize returns the dimension of the display.
func (*Window) FramebufferSize ¶
FramebufferSize returns the dimension of the framebuffer.
func (*Window) Fullscreen ¶
Fullscreen toggles windowed and fullscreen modes. Parameters width and height will set screen resolution only for fullscreen mode, and values of 0 will use the current resolution.
func (*Window) InitLoop ¶
func (platform *Window) InitLoop()
InitLoop should be called once at the beginning of the render loop.
func (*Window) MakeContextCurrent ¶
func (platform *Window) MakeContextCurrent()
MakeContextCurrent calls Window's MakeContextCurrent() to activate the opengl context for use.
func (*Window) PollEvents ¶
func (platform *Window) PollEvents()
PollEvents handles all pending window events.
func (*Window) RenderImgui ¶
func (platform *Window) RenderImgui(gui func())
RenderImgui will perform the beginning and ending steps of rendering the imgui constructed by calls to the imgui pkg in the 'gui' function.
func (*Window) ScreenCapture ¶
ScreenCapture saves a copy of the opengl front buffer and saves it into an image.Image.
func (*Window) SetClipboardText ¶
SetClipboardText sets the text as the current clipboard text.
func (*Window) ShouldClose ¶
ShouldClose returns true if the window is to be closed.
func (*Window) SwapBuffers ¶
func (platform *Window) SwapBuffers()
SwapBuffers performs a buffer swap.
type WindowMetric ¶
WindowMetric contains info on the window position (X, Y), size (W, H), and windowed/fullscreen status. The window position and size are only valid while the window is in windowed mode (ie W and H are not the resolution when fullscreen).
type WindowOption ¶
WindowOption sets a option during window creation.
func SetIcons ¶
func SetIcons(paths ...string) WindowOption
SetIcons offers icon candidates to the window. PNG or JPEG in 16x16, 32x32, and 48x48 are good.
func UseImgui ¶
func UseImgui(fonts FontMap) WindowOption
UseImgui is an option to setup additional bits so the window can be used with Imgui to create a user interface. Provide a key (for later reference) and the `Filename` and `Size` fields to load fonts for use with imgui. Pass nil to just use the default font. Imgui ini file disabled by default.