Documentation ¶
Index ¶
- func Initialize()
- func TriangleNormals(triangles [][3]mgl32.Vec3) []mgl32.Vec3
- type Mesh
- func NewCircle(col *color.NRGBA, texture gl.Texture) Mesh
- func NewCircleOutline(col *color.NRGBA) Mesh
- func NewCube(col *color.NRGBA, texture gl.Texture) Mesh
- func NewIcosahedron(col *color.NRGBA, texture gl.Texture) Mesh
- func NewLine(p1, p2 mgl32.Vec3, col *color.NRGBA) Mesh
- func NewMesh(vertices, vertexIndices, normals gl.Buffer, vboMode gl.Enum, itemCount int, ...) Mesh
- func NewMeshFromArrays(vertices, normals []mgl32.Vec3, textureCoords []mgl32.Vec2) (Mesh, error)
- func NewRect(col *color.NRGBA, texture gl.Texture) Mesh
- func NewRectOutline(col *color.NRGBA) Mesh
- func NewSphere(detail int, col *color.NRGBA, texture gl.Texture) Mesh
- func NewSubdividedIcosahedron(divisions int, col *color.NRGBA, texture gl.Texture) Mesh
- func (m *Mesh) ItemCount() int
- func (m *Mesh) NormalVBO() gl.Buffer
- func (m *Mesh) SetNormalVBO(normals gl.Buffer)
- func (m *Mesh) SetTexture(texture gl.Texture)
- func (m *Mesh) SetTextureCoords(coords gl.Buffer)
- func (m *Mesh) SetVBOMode(mode gl.Enum)
- func (m *Mesh) Texture() gl.Texture
- func (m *Mesh) TextureCoords() gl.Buffer
- func (m *Mesh) VBOMode() gl.Enum
- func (m *Mesh) VertexIndices() gl.Buffer
- func (m *Mesh) VertexVBO() gl.Buffer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
func Initialize()
Loads models into buffers on the GPU. glfw.Init() must be called before calling this.
func TriangleNormals ¶
TriangleNormals takes triangles that presumably make up mesh and returns a slice of normals. There will be one normal per vertex, for a total of 3 * len(triangles). All normals for a single triangle are the same. Note that the direction of the normals is based on the right hand rule, so the order by which the vertices are defined can flip the direction of the normal. If you need it in the other direction, just negate each normal:
for i := range normals { normals[i] = normals[i].Mul(-1) }
Types ¶
type Mesh ¶
type Mesh struct { // Color is 32-bit non-premultiplied RGBA. It is optional, but leaving it nil is the same as setting it to pure white. // Note that the color.Color interface's Color() function returns weird values (between 0 and 0xFFFF for avoiding overflow). // I recommend just accessing the RGBA fields directly. Color *color.NRGBA // BaseRotation is a rotation applied to the mesh. // This is intended to be used to orient the mesh so Up toward {0,1,0}, and Forward is towards {1,0,0}, since not all // meshes will be created in this orientation. Note that if you don't want to modify the default rotation, this must // be set to mgl32.QuatIdent(). // Encouraging a consistent orientation for all meshes makes dealing with them much easier, but it is not absolutely // required. BaseRotation mgl32.Quat // contains filtered or unexported fields }
var ( // Axes are the X,Y,Z axes in a mesh. All axes are of length 1, so they should be scaled before being drawn in most cases. // The XYZ axes are colored RGB respectively. Axes Mesh )
func NewCircleOutline ¶
func NewIcosahedron ¶
NewIcosahedron returns a mesh for a 20 sided figure. TODO: Implement texture coordinates for this figure. For now only color is supported.
func NewLine ¶
TODO: Line is an odd case. Other meshes can be easily scaled and rotated while still using the same basic built in model, but that doesn't work for lines. The way this is, each line requires creating a buffer on the GPU which is never deleted. Adding a delete method just for line meshes is odd, since none of the other models do it, but it's probably necessary.
func NewMesh ¶
func NewMesh(vertices, vertexIndices, normals gl.Buffer, vboMode gl.Enum, itemCount int, color *color.NRGBA, texture gl.Texture, textureCoords gl.Buffer) Mesh
NewMesh combines the input buffers and rendering information into a Mesh struct. Using this method requires loading OpenGL buffers yourself. It's not recommended for general use. Most standard use of meshes can be done via the standard ones (i.e. NewCube(), NewSphere(), NewRect()) or by loading an model from file via the `asset` package.
func NewMeshFromArrays ¶
NewMeshFromArrays copies the input vertices, normals, and texture coordinates into buffers on the GPU.
func NewRectOutline ¶
func NewSphere ¶
NewSphere returns a sphere mesh. The higher the detail, the more triangles that make up the mesh. Making this number too large will very quickly make you run out of memory. Detail 0 is an icosahedron with 20 triangular faces. Each detail level has (detail ^ 4) * 3 * 20 vertices, so by detail 5 it's up to 37500 faces. Recommended value for a decently smooth sphere is 4.
func NewSubdividedIcosahedron ¶
NewSubdividedIcosahedron returns a mesh for an n sided figure created by recursively dividing each face of an icosahedron (20 sided figure). Note that this recursive division of each triangular face grows very quickly and may cause unexpected crashes due to running out of memory if the number of divisions is too large.
func (*Mesh) SetNormalVBO ¶
func (*Mesh) SetTexture ¶
func (*Mesh) SetTextureCoords ¶
func (*Mesh) SetVBOMode ¶
SetVBOMode allows changing what mode a mesh is rendered in. It's recommended not to use this on the built in meshes as they are created with the VBO Mode they expect to be rendered with. The VBO modes include gl.TRIANGLES, gl.LINES, gl.LINE_LOOP, etc.