gogl

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 12 Imported by: 1

README

GoGL utils

Go Reference

A set of utilities for using openGl with go in the context of 3d games

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindTexture

func BindTexture(id TextureID)

binds a texture to gl.TEXTURE_2D from its texture id

func BindVertexArray

func BindVertexArray(id BufferID)

func BufferData

func BufferData[T any](target uint32, data []T, usage uint32)

used for initialising the target with the go array at data a more go-esque wrapper for the gl.BufferData function

func Cos32

func Cos32(x float32) float32

func Cos32Deg

func Cos32Deg(x float32) float32

func GetVersion

func GetVersion() string

func Mod32

func Mod32(a, b float32) float32

func SetupFPSWindow

func SetupFPSWindow(title string, width, height int32) (window *sdl.Window, cleanup func())

sets up a window with openGL and sdl this window behaves like an fps game where the mouse is in relative mode

func Sin32

func Sin32(x float32) float32

func Sin32Deg

func Sin32Deg(x float32) float32

func TriangleNormal

func TriangleNormal(p1, p2, p3 mgl32.Vec3) mgl32.Vec3

func UseProgram

func UseProgram(id ProgramID)

Types

type BufferID

type BufferID uint32

func GenBindBuffer

func GenBindBuffer(target uint32) BufferID

used for generating and binding general buffers e.g. VertexBufferObject or NormalArrayObject

func GenBindVertexArray

func GenBindVertexArray() BufferID

used for generating and binding vertex buffers

type BufferLayout

type BufferLayout[T any] struct {
	// contains filtered or unexported fields
}

func NewBufferLayout

func NewBufferLayout[T any](segments []int32, data []T) BufferLayout[T]

type BufferLoader

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

func NewBufferLoader

func NewBufferLoader() *BufferLoader

func (*BufferLoader) BuildFloatBuffer

func (b *BufferLoader) BuildFloatBuffer(id BufferID, layout BufferLayout[float32])

type Camera

type Camera struct {
	Pos mgl32.Vec3

	Up      mgl32.Vec3
	Right   mgl32.Vec3
	Forward mgl32.Vec3

	WorldUp mgl32.Vec3

	Yaw   float32
	Pitch float32

	MovementSpeed    float32
	MouseSensitivity float32
	Zoom             float32
}

func NewCamera

func NewCamera(pos, worldUp mgl32.Vec3, yaw, pitch, speed, sensitivity float32) *Camera

func (*Camera) GetViewMatrix

func (c *Camera) GetViewMatrix() mgl32.Mat4

func (*Camera) UpdateCamera

func (c *Camera) UpdateCamera(dir MovementDirs, deltaTime, mouseDx, mouseDy float32)

type EmbeddedShader added in v1.1.0

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

func NewEmbeddedShader added in v1.1.0

func NewEmbeddedShader(vertShader string, fragShader string) *EmbeddedShader

func (*EmbeddedShader) CheckShadersForChanges added in v1.1.0

func (s *EmbeddedShader) CheckShadersForChanges()

func (*EmbeddedShader) SetFloat added in v1.1.0

func (s *EmbeddedShader) SetFloat(name string, value float32)

func (*EmbeddedShader) SetMatrix4 added in v1.1.0

func (s *EmbeddedShader) SetMatrix4(name string, value mgl32.Mat4)

func (*EmbeddedShader) SetVec3 added in v1.1.0

func (s *EmbeddedShader) SetVec3(name string, value mgl32.Vec3)

func (*EmbeddedShader) Use added in v1.1.0

func (s *EmbeddedShader) Use()

type MovementDirs

type MovementDirs struct {
	Forward int
	Right   int
	Up      int
}

func NewMoveDirs

func NewMoveDirs(f, b, r, l, u, d bool) MovementDirs

type Object

type Object struct {
	Type         string
	Verticies    []float32 //in XYZ UV
	VertexStride int       // 5 if using XYZ UV
	// contains filtered or unexported fields
}

func Cube

func Cube(size float32) Object

func Pentahedron

func Pentahedron(size float32) Object

func (*Object) CalcNormals added in v1.1.1

func (o *Object) CalcNormals(triangleCount int)

func (Object) Draw

func (o Object) Draw(shader Shader, drawMatrix mgl32.Mat4)

func (Object) DrawMultiple

func (o Object) DrawMultiple(shader Shader, num int, drawMatrix func(int) mgl32.Mat4)

func (*Object) FillBuffers added in v1.1.1

func (o *Object) FillBuffers()

type ProgramID

type ProgramID uint32

func CreateProgram

func CreateProgram(vertPath string, fragPath string) ProgramID

func CreateProgramFromShaders added in v1.1.0

func CreateProgramFromShaders(vertShader string, fragShader string) ProgramID

type Shader

type Shader interface {
	CheckShadersForChanges()
	Use()

	SetFloat(name string, value float32)
	SetVec3(name string, value mgl32.Vec3)
	SetMatrix4(name string, value mgl32.Mat4)
}

type ShaderID

type ShaderID uint32

func CreateShader

func CreateShader(shaderSource string, shaderType uint32) ShaderID

func LoadShader

func LoadShader(path string, shaderType uint32) ShaderID

type ShaderWithPaths added in v1.1.0

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

func NewShaderFromFilePaths added in v1.1.0

func NewShaderFromFilePaths(vertPath string, fragPath string) *ShaderWithPaths

func (*ShaderWithPaths) CheckShadersForChanges added in v1.1.0

func (s *ShaderWithPaths) CheckShadersForChanges()

func (*ShaderWithPaths) SetFloat added in v1.1.0

func (s *ShaderWithPaths) SetFloat(name string, value float32)

func (*ShaderWithPaths) SetMatrix4 added in v1.1.0

func (s *ShaderWithPaths) SetMatrix4(name string, value mgl32.Mat4)

func (*ShaderWithPaths) SetVec3 added in v1.1.0

func (s *ShaderWithPaths) SetVec3(name string, value mgl32.Vec3)

func (*ShaderWithPaths) Use added in v1.1.0

func (s *ShaderWithPaths) Use()

type TextureID

type TextureID uint32

func GenBindTexture

func GenBindTexture() TextureID

generates a new nexture ID and binds it to gl.TEXTURE_2D

func LoadTexture

func LoadTexture(filename string) TextureID

func LoadTextureFromImage added in v1.1.0

func LoadTextureFromImage(img image.Image) TextureID

Jump to

Keyboard shortcuts

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