Documentation ¶
Index ¶
- func AddNormal(vertices []float32) []float32
- func AfterDrawing(window *glfw.Window)
- func BeforeDrawing()
- func BeforeMainLoop(window *glfw.Window, vp *Viewpoint)
- func Init(windowWidth int, windowHeight int, windowTitle string) *glfw.Window
- func InitGlfwAndOpenGL(width int, height int, title string) *glfw.Window
- func MakeProgram(vertexShaderSource, fragmentShaderSource string) uint32
- func MakeProgramFromFile(vertPath string, fragPath string) uint32
- func NewCube(l float32) *[]float32
- func NewPlane(l float32) *[]float32
- func NewUniTexCube(l float32) *[]float32
- func ReadBinaryStlFile(file string) []float32
- func ReadBinaryStlFileRaw(file string) []float32
- func ReadBinaryStlFileWithCenter(file string, centerX float32, centerY float32, centerZ float32) []float32
- func Terminate()
- type BaseObj
- func (obj *BaseObj) GetModel() mgl32.Mat4
- func (obj *BaseObj) GetProgVar() interface{}
- func (obj *BaseObj) GetProgram() uint32
- func (obj *BaseObj) GetVertices() *[]float32
- func (obj *BaseObj) Render()
- func (obj *BaseObj) SetModel(model mgl32.Mat4)
- func (obj *BaseObj) SetProgVar(progVar interface{})
- func (obj *BaseObj) SetProgram(program uint32)
- func (obj *BaseObj) SetVertices(vertices *[]float32)
- type BaseObjVar
- type Group
- type LightSrc
- type Material
- type Object
- type SimpleObj
- type SimpleObjVar
- type Viewpoint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterDrawing ¶
func BeforeDrawing ¶
func BeforeDrawing()
func BeforeMainLoop ¶
func MakeProgram ¶
func MakeProgramFromFile ¶
func NewUniTexCube ¶
NewUniTexCube will return vertices of a cube with side length l. The vertices contains custom data (texture vector)
func ReadBinaryStlFile ¶
func ReadBinaryStlFileRaw ¶
Types ¶
type BaseObj ¶
type BaseObj struct { // Program is the shader program of the object. Program uint32 // Vao stands for "Vertex Array Object", and it contains // one or more "Vertex Buffer Object" which is a memory // buffer that contains the data of vertices Vao uint32 // Vertices are points that form the shape of the object. Vertices *[]float32 // Model keeps translation/rotation info of the object. Model mgl32.Mat4 // Uniform is the map of the name of uniform variables in // shader program and itself. Uniform map[string]int32 // ProgVar is the customizes struct that contains all the uniform // variables that will be used in the shader program of a certain object. // Developer should implement their own ProgVar and put it here to shadow // this BaseObjVar type of ProgVar ProgVar BaseObjVar }
BaseObj is an Object that keeps the basic info of a Object which will render a wireframe object. BaseObj could be embedded into other Object struct to provide common methods like GetProgram(), GetProgVar(), GetVertices(), GetModel() and SetProgram(). So when we're developing a new Object struct, we only need to implement SetProgVar(), SetVertices() and Render().
func (*BaseObj) GetProgVar ¶
func (obj *BaseObj) GetProgVar() interface{}
func (*BaseObj) GetProgram ¶
func (*BaseObj) GetVertices ¶
func (*BaseObj) SetProgVar ¶
func (obj *BaseObj) SetProgVar(progVar interface{})
func (*BaseObj) SetProgram ¶
func (*BaseObj) SetVertices ¶
type BaseObjVar ¶
type BaseObjVar struct {
Vp *Viewpoint
}
BaseObjVar is the program variable struct for BaseObj. Every Object struct will have it's own program variable struct.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
func (*Group) SetGroupModel ¶
type LightSrc ¶
func NewLightSrc ¶
func NewLightSrc() LightSrc
type Material ¶
type Material struct { Ambient mgl32.Vec3 Diffuse mgl32.Vec3 Specular mgl32.Vec3 Shininess float32 }
func NewMaterial ¶
func NewMaterial() Material
type Object ¶
type Object interface { // GetProgram gets the program of the object. GetProgram() uint32 // SetProgram sets the program of the object using an existing program. SetProgram(program uint32) // GetProgram gets the program variables of the object. // The return value should be a program variable struct. // Program variable struct is the customizes struct that contains all // the uniform variables that will be used in the shader program of a // certain object. GetProgVar() interface{} // SetProgram sets the program variables of the object. // The binding of uniform variables to the program should be set here. SetProgVar(progVar interface{}) // GetVertices gets the vertices of the object. GetVertices() *[]float32 // SetVertices sets the vertices of the object. // VAO, VBO and EBO should be set here if needed. SetVertices(vertices *[]float32) // GetModel gets the model of the object. GetModel() mgl32.Mat4 // SetModel sets the model of the object. SetModel(model mgl32.Mat4) // Render refreshes uniform variables and draw the object. // All references of the variables that would change the // object's states in the main loop (i.e. uniform variables) // should have already been prepared when calling SetProgVar(). Render() }
Object is the basic interface of every renderable object.
func NewBaseObj ¶
func NewBaseObj() Object
NewBaseObj return a BaseObj instance with its program. Each Object usually only be able to use one kind of program, so it's a nice practice to use NewXXX() to create an Object instance that contains the default program. However, we could always use SetProgram() to set the program if there is an existing program which is already been compiled.
func NewSimpleObj ¶
func NewSimpleObj() Object
NewSimpleObj returns a SimpleObj instance with its program.
type SimpleObj ¶
type SimpleObj struct { BaseObj // contains filtered or unexported fields }
SimpleObj is the Object struct that will render a mono color object which has certain material properties. The mono color object will reflect the light from a single light source.
func (*SimpleObj) SetProgVar ¶
func (obj *SimpleObj) SetProgVar(progVar interface{})