Documentation ¶
Overview ¶
Package three provides a simple API to create and display animated 3D computer graphics.
Index ¶
- func GetTime() float64
- func MakeProgram(features ProgramFeature) gl.Program
- func MakeTextShader() gl.Program
- func TextureFromDDS(fname string) (gl.Texture, error)
- type Appearance
- type Attribute
- type BasicMaterial
- func (b BasicMaterial) Color() *Color
- func (b *BasicMaterial) Program() *Program
- func (b *BasicMaterial) SetColor(color *Color) *BasicMaterial
- func (b *BasicMaterial) SetProgram(p *Program)
- func (b *BasicMaterial) SetTexture(texture *Texture)
- func (b *BasicMaterial) SetWireframe(wireframe bool) *BasicMaterial
- func (b BasicMaterial) Texture() *Texture
- func (b BasicMaterial) Wireframe() bool
- type CameraSettings
- type Color
- type Colored
- type Face
- type Font
- type Geometry
- func (g *Geometry) ArrayCount() int
- func (g *Geometry) Faces() []*Face
- func (g *Geometry) Normals() []mgl32.Vec3
- func (g *Geometry) SetFaces(faces []*Face)
- func (g *Geometry) SetNormals(normals []mgl32.Vec3)
- func (g *Geometry) SetUVs(uvs []mgl32.Vec2)
- func (g *Geometry) SetVertices(vertices []mgl32.Vec3)
- func (g *Geometry) UVs() []mgl32.Vec2
- func (g *Geometry) Vertices() []mgl32.Vec3
- type Index
- type Line
- type Mesh
- type Object3D
- type PerspectiveCamera
- type Program
- type ProgramFeature
- type Renderer
- type Scene
- type SceneObject
- type Shape
- type Text
- type TextGeometry
- type TextMaterial
- func (b TextMaterial) Color() *Color
- func (b *TextMaterial) Program() *Program
- func (b *TextMaterial) SetColor(color *Color) *TextMaterial
- func (b *TextMaterial) SetProgram(p *Program)
- func (b *TextMaterial) SetTexture(texture *Texture) *TextMaterial
- func (b *TextMaterial) SetWireframe(wireframe bool) *TextMaterial
- func (b TextMaterial) Texture() *Texture
- func (b TextMaterial) Wireframe() bool
- type Texter
- type Texture
- type Textured
- type Transform
- func (t *Transform) LookAt(x, y, z float32)
- func (t *Transform) RotateX(angle float32)
- func (t *Transform) RotateY(angle float32)
- func (t *Transform) RotateZ(angle float32)
- func (t *Transform) Scale(x, y, z float32)
- func (t *Transform) SetPosition(x, y, z float32)
- func (t *Transform) Translate(v mgl32.Vec3)
- func (t *Transform) TranslateX(x float32)
- func (t *Transform) TranslateY(y float32)
- func (t *Transform) TranslateZ(z float32)
- type Uniform
- type Window
- type WindowSettings
- type Wireframed
- type Wrapping
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetTime ¶
func GetTime() float64
GetTime returns the number of seconds since the timer was started.
Please refer to http://www.glfw.org/docs/latest/input.html#time for more information.
func MakeProgram ¶
func MakeProgram(features ProgramFeature) gl.Program
MakeProgram loads a shader program for the given features. Features will be activated via pre-processor directives. e.g. #define USE_TEXTURE
func MakeTextShader ¶
MakeTextShader creates a new shader program for text rendering purposes.
Types ¶
type Appearance ¶
Appearance is the interface which defines the appearance of 3D objects. For example: solid color, textured, etc.
SetProgram is used to store the given program and to cache it inside the material. Program returns a program which is used to define the appearance of the 3D object. A program consists of a vertex and a fragment shader.
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
Attribute describes an attribute which is passed to a shader program.
type BasicMaterial ¶
type BasicMaterial struct {
// contains filtered or unexported fields
}
BasicMaterial describes a material with basic shading. No lights or shadows are considered.
func NewBasicMaterial ¶
func NewBasicMaterial() *BasicMaterial
NewBasicMaterial creates a new Basic material.
func (BasicMaterial) Color ¶
func (b BasicMaterial) Color() *Color
Color returns the set color for this material.
func (*BasicMaterial) Program ¶
func (b *BasicMaterial) Program() *Program
Program returns the current program which is used for this material.
func (*BasicMaterial) SetColor ¶
func (b *BasicMaterial) SetColor(color *Color) *BasicMaterial
SetColor sets a solid color for this material.
func (*BasicMaterial) SetProgram ¶
func (b *BasicMaterial) SetProgram(p *Program)
SetProgram stores the given program for further use (cache).
func (*BasicMaterial) SetTexture ¶
func (b *BasicMaterial) SetTexture(texture *Texture)
SetTexture sets the texture for this material.
func (*BasicMaterial) SetWireframe ¶
func (b *BasicMaterial) SetWireframe(wireframe bool) *BasicMaterial
SetWireframe enables or disables wireframes for the material.
func (BasicMaterial) Texture ¶
func (b BasicMaterial) Texture() *Texture
Texture returns the set texture for this material.
func (BasicMaterial) Wireframe ¶
func (b BasicMaterial) Wireframe() bool
Wireframe returns the current value for wireframe rendering.
type CameraSettings ¶
CameraSettings holds information to construct a new camera object.
type Color ¶
type Color [3]float32
Color stores color information for the red, green and blue channel.
type Colored ¶
type Colored interface {
Color() *Color
}
Colored is an interface that indicates that a material can have a solid color.
type Face ¶
type Face struct {
// contains filtered or unexported fields
}
Face stores indices to vertices and normals.
type Font ¶
type Font struct {
// contains filtered or unexported fields
}
Font defines a font with its texture
type Geometry ¶
type Geometry struct {
// contains filtered or unexported fields
}
Geometry is a base struct with fields for Vertices and UVs.
func (*Geometry) ArrayCount ¶
ArrayCount returns the number of elements to draw in the draw call. Faces * 3 if faces are used or number of vertices.
func (*Geometry) SetNormals ¶
SetNormals stores the given normals in an internal field.
func (*Geometry) SetVertices ¶
SetVertices stores the given vertices in an internal field.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index stores information about element indices
type Line ¶
type Line struct { Object3D // contains filtered or unexported fields }
Line is a representation of a line in 3D space. It consists of a geometry which defines all vertices of the lines to render and a material. Lines can be transformed.
func NewLine ¶
func NewLine(geometry Shape, material Appearance) *Line
NewLine creates a new line for the given geometry (set of vertices) and material.
func (*Line) Material ¶
func (l *Line) Material() Appearance
Material returns an objects which described the appaerance of the line.
type Mesh ¶
type Mesh struct { Object3D // contains filtered or unexported fields }
Mesh is a representation of a 3D object. It consists of a geometry and a material. Meshes can be transformed in 3D space.
func NewMesh ¶
func NewMesh(geometry Shape, material Appearance) *Mesh
NewMesh creates a new mesh for the given geometry (shape) and material (appearance).
func (*Mesh) Material ¶
func (m *Mesh) Material() Appearance
Material returns an objects which described the appaerance of the mesh.
type Object3D ¶
type Object3D struct {
// contains filtered or unexported fields
}
Object3D described an object in 3D space.
func NewObject3D ¶
func NewObject3D() Object3D
NewObject3D returns a new Object3D. It initializes the transform of the object.
func (*Object3D) NormalBuffer ¶
NormalBuffer returns the buffer object for this objects normals.
func (*Object3D) Transform ¶
Transform returns the transform object (translation, rotation, scale) for this object.
func (*Object3D) VertexBuffer ¶
VertexBuffer returns the buffer object for this objects vertices.
type PerspectiveCamera ¶
type PerspectiveCamera struct { Transform *Transform // contains filtered or unexported fields }
PerspectiveCamera has information about the transformation of the camera and it's projection matrix.
Note: The underlying matrix for the transform structure must be inverted.
func NewPerspectiveCamera ¶
func NewPerspectiveCamera(fov, aspect, near, far float32) *PerspectiveCamera
NewPerspectiveCamera creates a new perspective camera for the given values.
fov: Field of view in degrees aspect: aspect ratio near: near clip plane far: far clip plane
The cameras transform matrix will be inverted.
type Program ¶
type Program struct { Loaded bool // contains filtered or unexported fields }
Program is a GLSL shader program.
func NewProgram ¶
func NewProgram() *Program
NewProgram returns a new Program with attributes and uniforms collection initialised.
type ProgramFeature ¶
type ProgramFeature int
ProgramFeature type.
const ( // COLOR feature COLOR ProgramFeature = 1 << iota // TEXTURE feature TEXTURE // SHADING_BASIC feature SHADING_BASIC )
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer handles mesh rendering to the window.
func NewRenderer ¶
NewRenderer creates a new Renderer with the given window size and title.
func (*Renderer) OpenGLSentinel ¶
func (r *Renderer) OpenGLSentinel()
OpenGLSentinel reports any OpenGL related errors.
func (*Renderer) Render ¶
func (r *Renderer) Render(scene *Scene, camera *PerspectiveCamera)
Render renders the given scene with the given camera to the window.
type Scene ¶
type Scene struct {
// contains filtered or unexported fields
}
Scene represents a tree-like structure (graph) of 3D objects.
func (*Scene) Add ¶
func (s *Scene) Add(object SceneObject)
Add adds the given scene object to the scene tree.
type SceneObject ¶
type SceneObject interface { Geometry() Shape Material() Appearance Transform() *Transform Mode() gl.GLenum Index() *Index VertexBuffer() gl.Buffer UVBuffer() gl.Buffer NormalBuffer() gl.Buffer }
SceneObject is an interface that describes an object that can be added to the scene graph.
type Shape ¶
type Shape interface { Vertices() []mgl32.Vec3 UVs() []mgl32.Vec2 Normals() []mgl32.Vec3 Faces() []*Face ArrayCount() int }
Shape is the interface which defines the shape of a 3D object.
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text defines a 2D text geometry and its appearance.
func NewText ¶
func NewText(geometry *TextGeometry, material Texter) *Text
NewText creates a new 2D text object that can be added to the scene.
NOTE: This method overrides the texture for the given texture to the texture from the font.
func (*Text) Geometry ¶
func (t *Text) Geometry() *TextGeometry
Geometry returns the geometry object for this text object.
type TextGeometry ¶
type TextGeometry struct { Vertices []mgl32.Vec2 UVs []mgl32.Vec2 Text string Position mgl32.Vec2 Size float32 Font *Font }
TextGeometry defines the geometry of 2D text.
func NewTextGeometry ¶
NewTextGeometry creates a new 2D text geometry for the given text.
type TextMaterial ¶
type TextMaterial struct {
// contains filtered or unexported fields
}
TextMaterial describes a material for 2D text.
func NewTextMaterial ¶
func NewTextMaterial() *TextMaterial
NewTextMaterial creates a new Basic material.
func (TextMaterial) Color ¶
func (b TextMaterial) Color() *Color
Color returns the set color for this material.
func (*TextMaterial) Program ¶
func (b *TextMaterial) Program() *Program
Program returns the current program which is used for this material.
func (*TextMaterial) SetColor ¶
func (b *TextMaterial) SetColor(color *Color) *TextMaterial
SetColor sets a solid color for this material.
func (*TextMaterial) SetProgram ¶
func (b *TextMaterial) SetProgram(p *Program)
SetProgram stores the given program for further use (cache).
func (*TextMaterial) SetTexture ¶
func (b *TextMaterial) SetTexture(texture *Texture) *TextMaterial
SetTexture sets the texture for this material.
func (*TextMaterial) SetWireframe ¶
func (b *TextMaterial) SetWireframe(wireframe bool) *TextMaterial
SetWireframe enables or disables wireframes for the material.
func (TextMaterial) Texture ¶
func (b TextMaterial) Texture() *Texture
Texture returns the set texture for this material.
func (TextMaterial) Wireframe ¶
func (b TextMaterial) Wireframe() bool
Wireframe returns the current value for wireframe rendering.
type Texter ¶
type Texter interface { Appearance Textured }
Texter is an interface composition of Appaerance and Textured.
type Texture ¶
type Texture struct { WrapS Wrapping WrapT Wrapping Repeat mgl32.Vec2 // contains filtered or unexported fields }
Texture represents a graphic that can be rendered on any geometry.
func NewTexture ¶
NewTexture returns a new DDS texture loaded from the given path. WrapS and WrapT are defaultd to ClampToEdge. Repeat is set to 1,1 (no repeat)
type Transform ¶
type Transform struct { Up mgl32.Vec3 Right mgl32.Vec3 Forward mgl32.Vec3 // contains filtered or unexported fields }
Transform stores information about the position, rotation and scale of an 3D object.
func NewTransform ¶
func NewTransform() *Transform
NewTransform creates a new Transform struct with defaults. The given multiplier can be used to invert the matrix, e.g. camera matrix This value should be 1 or -1 (inverted).
Position: 0,0,0 Rotation: 0,0,0 Scale: 1,1,1
Up: 0,1,0 Right: 1,0,0 Forward: 0,0,-1
func (*Transform) LookAt ¶
LookAt changes the transformation of the 3D object to face the target's position. The model matrix will be updated accordingly.
Note: This transformation makes use of the up vector.
func (*Transform) RotateX ¶
RotateX rotates the 3D object by the given angle (in radians) around the x axis. The model matrix is updated accordingly.
func (*Transform) RotateY ¶
RotateY rotates the 3D object by the given angle (in radians) around the x axis. The model matrix is updated accordingly.
func (*Transform) RotateZ ¶
RotateZ rotates the 3D object by the given angle (in radians) around the x axis. The model matrix is updated accordingly.
func (*Transform) Scale ¶
Scale sets the scale factor of the 3D object to the given values and updates it's matrix accordingly.
func (*Transform) SetPosition ¶
SetPosition sets the position of the 3D object and updates it's matrix accordingly.
func (*Transform) Translate ¶
Translate moves the object by the given vector. The model matrix is updated accordingly.
func (*Transform) TranslateX ¶
TranslateX moves the object along the x axis by the given units. The model matrix is updated accordingly.
func (*Transform) TranslateY ¶
TranslateY moves the object along the y axis by the given units. The model matrix is updated accordingly.
func (*Transform) TranslateZ ¶
TranslateZ moves the object along the z axis by the given units. The model matrix is updated accordingly.
type Uniform ¶
type Uniform struct {
// contains filtered or unexported fields
}
Uniform describes a uniform value which is passed to the shader program.
func NewUniform ¶
NewUniform creates a new uniform using the given identifier to lookup the uniform position in the shader program.
type Window ¶
type Window struct { Settings WindowSettings // contains filtered or unexported fields }
Window holds information about the dimensions and title of a window.
func NewWindow ¶
func NewWindow(settings WindowSettings) (*Window, error)
NewWindow creates a new window for the given dimensions and title. The window is created via GLFW.
func (*Window) ShouldClose ¶
ShouldClose indicates if the OS has received a signal to close this window.
type WindowSettings ¶
WindowSettings holds information that describe how the window should constructed.
type Wireframed ¶
type Wireframed interface {
Wireframe() bool
}
Wireframed is an interface that indicates that a material can be rendered as wireframes only.
Notes ¶
Bugs ¶
Vertex and UV buffers are deleted and re-created; not updated.
Source Files ¶
- attribute.go
- basic_material.go
- color.go
- dds.go
- doc.go
- face.go
- font.go
- geometry.go
- index.go
- line.go
- material.go
- mesh.go
- object3d.go
- perspective_camera.go
- program.go
- renderer.go
- scene.go
- text.go
- text_geometry.go
- text_material.go
- text_shader.go
- texture.go
- three.go
- transform.go
- uniform.go
- utils.go
- window.go
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package logging provides basic logging features (modules, log levels).
|
Package logging provides basic logging features (modules, log levels). |