render

package
v0.0.0-...-f678c33 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

package render implements OpenGL rendering logic and wrappers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShaderNotLinked is returned when the program attempts to use a shader
	// program that was not properly compiled and linked.
	ErrShaderNotLinked = errors.New("shader: invalid state: uniform called before Link()")

	// ErrNotImplemented indicates that the rendering layer in use has
	// functionality that is not yet implemented.
	ErrNotImplemented = errors.New("not implemented")
)
View Source
var (
	// BgColor is the default rendering background color used by OpenGL.
	BgColor = Color("#87CEEB")
)

Functions

func Color

func Color(s string) (c color.RGBA)

Color parses the provided web color string and returns a color.RGBA value. It panics if the provided string is not in the format #RRGGBB or #RGB.

func F

func F[X int | int32 | int64 | uint | uint32 | uint64 | float32](i X) float64

F is a syntax suggar to cast any number to float64

func Time

func Time() float64

Time returns the time in miliseconds since the window was initialized.

func Version

func Version() string

Version returns the OpengGL version as reported by the driver.

Types

type Camera

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

func NewCamera

func NewCamera() (c *Camera)

type Scene

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

Scene represents a graph of elements to be drawn on screen by the OpenGL driver.

func NewScene

func NewScene() *Scene

NewScene initializes an empty scene with the proper memory allocations.

func (*Scene) AddTexture

func (s *Scene) AddTexture(tex *Texture)

func (*Scene) AddTriangles

func (s *Scene) AddTriangles(vertices []float32, indices []uint32)

AddTriangles adds the provided vertices and indices to the current scene.

func (*Scene) AddVertices

func (s *Scene) AddVertices(vertices []float32)

func (*Scene) BgColor

func (s *Scene) BgColor(c color.Color)

func (*Scene) Clear

func (s *Scene) Clear()

func (*Scene) Draw

func (s *Scene) Draw(shader *Shader)

Draw calls the underlying driver to render the scene graph on the current buffer.

If the provided Shader program is not nil, it will be registered to be used before rendering anything on screen.

type Shader

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

Shader abstracts raw GLSL shader compilation, linking and usage.

func (*Shader) FragmentShader

func (s *Shader) FragmentShader(src string) *Shader

FragmentShader appends the provided shader file to the pipeline. This method returns the Shader reference to allow for chaining.

func (s *Shader) Link() error

Link creates an OpenGL shader program linking all previously compiled shaders. It reports an error if no shaders where compiled, or if there were an error linking them.

func (*Shader) UniformFloats

func (s *Shader) UniformFloats(name string, v ...float32) error

UniformFloat adds the provided float value as a GLSL uniform with the given name. Returns an error if the program was not linked.

func (*Shader) UniformInts

func (s *Shader) UniformInts(name string, v ...int32) error

UniformInt adds the provided int value as a GLSL uniform with the given name. Returns an error if the shader was not linked.

func (*Shader) UniformTransformation

func (s *Shader) UniformTransformation(name string, model glm.Mat4) error

func (*Shader) Use

func (s *Shader) Use()

Use attempt to use the linked program by calling gl.UseProgram. It will panic if no shaders were compiled and linked previously.

func (*Shader) VertexShader

func (s *Shader) VertexShader(src string) *Shader

VertexShader appends the provider shader file to the pipeline. This method returns the Shader reference to allow for chaining.

type Texture

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

func NewTexture

func NewTexture(path string) (t *Texture, err error)

func NewTextureFromBytes

func NewTextureFromBytes(b []byte) (t *Texture, err error)

type Window

type Window struct {
	Width  int
	Height int
	// contains filtered or unexported fields
}

Window handles the basic GUI and Input event handling.

Window must be created using NewWindow, which will load all the required components of OpenGL and GLFW, as well as initializing a Scene object that can be used to draw elements on. To add elements call the Scene() method.

During the app main event loop, callers must make sure to call the PollEvents() method to receive any window/input changes from the Operating System.

func NewWindow

func NewWindow(width, height int, title string) (*Window, error)

NewWindow initializes the program window and OpenGL backend.

func (*Window) Close

func (w *Window) Close()

Close frees any used resources and close the underlying GLFW window.

func (*Window) PollEvents

func (w *Window) PollEvents()

PoolEvents listen to any window/input events to be passed to the input callbacks.

func (*Window) Scene

func (w *Window) Scene() *Scene

Scene returns the Scene Graph used to draw on screen.

func (*Window) ShouldClose

func (w *Window) ShouldClose() bool

ShouldClose returns true when the window must be closed. Before it should be closed, it is safe to call any drawing operations. Once the window should be closed is flipped to true, then callers must call Close() method to ensure resources are properly freed.

func (*Window) SwapBuffers

func (w *Window) SwapBuffers()

SwapBuffers will flip the drawing buffer to the visible buffer on the display.

Jump to

Keyboard shortcuts

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