gosigl

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: Unlicense Imports: 4 Imported by: 6

README

Gosigl

Gosigl (Go SImple openGL) is an somewhat opinionated Go wrapper for OpenGL with emphasis on simple. It's purpose is to make creating simple OpenGL programs really goddamn easy. It doesn't provide a whole lot of functionality, but it's really quick and simple to get a basic renderable world up and running.

It provides simplified functions for creating textures, VAO and VBOs, and shader objects.

Texture

Provides functions for creating and binding Texture2D and Cube_Map_Textures. Creating and binding a Texture2D can be done as follows:

buf := gosigl.CreateTexture2D(
		gosigl.TextureSlot(0),   // Assign texture slot
		width,                  // texture width
		height,                 // texture height
		pixelData,              // []byte raw colour data
		gosigl.RGB,              // colour data format
		false)                  // true = clamp to edge, false = repeat
gosigl.BindTexture2D(gosigl.TextureSlot(0), buf)

Cubemaps are very similar:

buf := gosigl.CreateTextureCubemap(
	gosigl.TextureSlot(0),   // Assign texture slot
	width,                  // texture width
    height,                 // texture height
    pixelData,              // [6][]byte raw colour data
    gosigl.RGB,              // colour data format
	true)
gosigl.BindTextureCubemap(gosigl.TextureSlot(0), buf)
Mesh

Simple methods are available for VBO and VAO generation, as follows:

mesh := gosigl.NewMesh(vertices) // vertices = []float32
gosigl.CreateVertexAttribute(mesh, uvs, 2) // uvs = []float32, 2 = numPerVertex
gosigl.CreateVertexAttribute(mesh, normals, 3)
gosigl.FinishMesh()

To draw:

gosigl.BindMesh(mesh)            // bind vbo
gosigl.DrawArray(offset, length) // draw from bound

To delete:

gosigl.DeleteMesh(mesh)
Shader

@Incomplete

Documentation

Index

Constants

View Source
const Back = opengl.BACK
View Source
const DepthTestLEqual = opengl.LEQUAL
View Source
const FragmentShader = ShaderType(opengl.FRAGMENT_SHADER)
View Source
const Front = opengl.FRONT
View Source
const FrontAndBack = opengl.FRONT_AND_BACK
View Source
const Line = uint32(opengl.LINE)
View Source
const MaskColourBufferBit = opengl.COLOR_BUFFER_BIT
View Source
const MaskDepthBufferBit = opengl.DEPTH_BUFFER_BIT
View Source
const Triangles = uint32(opengl.TRIANGLES)
View Source
const VertexShader = ShaderType(opengl.VERTEX_SHADER)
View Source
const WindingClockwise = opengl.CW
View Source
const WindingCounterClockwise = opengl.CCW

Variables

This section is empty.

Functions

func BindMesh

func BindMesh(mesh *VertexObject)

func BindTexture2D

func BindTexture2D(slot TextureSlotId, id TextureBindingId)

func BindTextureCubemap

func BindTextureCubemap(slot TextureSlotId, id TextureBindingId)

func BindVertexAttributes

func BindVertexAttributes(mesh *VertexObject)

func Clear

func Clear(bufferBits ...uint32)

func ClearColour

func ClearColour(red float32, green float32, blue float32, alpha float32)

func CreateVertexAttribute

func CreateVertexAttribute(mesh *VertexObject, bufferData []float32, stride int)

CreateVertexAttribute creates a vertex array attribute

func CreateVertexAttributeArrayBuffer

func CreateVertexAttributeArrayBuffer(mesh *VertexObject, bufferData []float32, stride int)

func DeleteMesh

func DeleteMesh(mesh *VertexObject)

func DeleteTextures

func DeleteTextures(ids ...TextureBindingId)

func DisableBlend

func DisableBlend()

func DisableDepthTest

func DisableDepthTest()

func DrawArray

func DrawArray(offset int, length int)

func DrawElements added in v0.2.0

func DrawElements(count int, offset int, indices []uint32)

func EnableBlend

func EnableBlend()

func EnableCullFace

func EnableCullFace(cullSide uint32, winding uint32)

func EnableDepthTest

func EnableDepthTest()

func FinishMesh

func FinishMesh()

func SetElementArrayAttribute added in v0.2.0

func SetElementArrayAttribute(mesh *VertexObject, bufferData []uint32)

func SetLineWidth

func SetLineWidth(width float32)

func SetVertexDrawMode

func SetVertexDrawMode(drawMode uint32)

Types

type Context

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

func NewShader

func NewShader() Context

func (*Context) AddShader

func (ctx *Context) AddShader(source string, shaderType ShaderType) error

func (*Context) Destroy

func (ctx *Context) Destroy()

func (*Context) Finalize

func (ctx *Context) Finalize()

func (*Context) GetUniform

func (ctx *Context) GetUniform(name string) int32

func (*Context) Id

func (ctx *Context) Id() uint32

func (*Context) UseProgram

func (ctx *Context) UseProgram()

type ElementArrayObject added in v0.2.0

type ElementArrayObject uint32

type PixelFormat

type PixelFormat uint32

type ShaderType

type ShaderType uint32

type TextureBindingId

type TextureBindingId uint32

func CreateTexture2D

func CreateTexture2D(slot TextureSlotId, width int, height int, pixelData []byte, pixelFormat PixelFormat, clampToEdge bool) TextureBindingId

func CreateTextureCubemap

func CreateTextureCubemap(slot TextureSlotId, width int, height int, pixelData [6][]byte, pixelFormat PixelFormat, clampToEdge bool) TextureBindingId

type TextureSlotId

type TextureSlotId uint32

func TextureSlot

func TextureSlot(index int) TextureSlotId

type VertexArrayObject

type VertexArrayObject uint32

type VertexBufferObject

type VertexBufferObject uint32

type VertexObject

type VertexObject struct {
	Id       VertexBufferObject
	AttribId [32]VertexArrayObject
	// contains filtered or unexported fields
}

func NewMesh

func NewMesh(vertices []float32) (mesh *VertexObject)

Jump to

Keyboard shortcuts

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