glf

package module
v0.0.0-...-18ab565 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

README

Go gl helper functions

Documentation

Overview

Camera helper functions

GL Helper Functions

Shader GL Helper Functions

Index

Constants

This section is empty.

Variables

View Source
var Verbose bool = ghf.Verbose

Functions

func BindBufferSubData

func BindBufferSubData[T mgl32.Mat4 | mgl32.Vec3](data []T, buffer uint32)

Sends a generic slice to a uniform buffer (UBO) for use in a shader block.

func BindTexture

func BindTexture(texID uint32)

Binds a 2D texture ID via a uint32 ID

func BufferData

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

Create and initialize buffer via generic slice (only takes float32 for now)

func CheckShadersforChanges

func CheckShadersforChanges()

Checks to see if any of the loaded shaders have been modified, and if so recreates the program for that shader.

func CreateComputeShader

func CreateComputeShader(source, sourceFile string) uint32

func CreateFragmentShader

func CreateFragmentShader(shaderFile string) (uint32, error)

Create fragment shader from path to glsl fragment shader source

  • Returns shader ID as a uint32 if no errors
  • Returns error if shader creation fails

func CreateNewUniformBuffer

func CreateNewUniformBuffer[T mgl64.Mat4 | mgl64.Vec3](data []T, n int) uint32

Makes a new uniform buffer on binding (n) set to the type and size of the (data)

Returns the uint32 ID of the created buffer

func CreateProgram

func CreateProgram(vertPath, fragPath string) (uint32, error)

Create and bind shader program via a vertex and fragment glsl source file path in that order.

  • Returns shader ID as a uint32 if no errors
  • Returns error if shader creation fails

func CreateShader

func CreateShader(ShaderSource string, ShaderType uint32) (uint32, error)

Create shader via shader source file and shader type.

  • Returns shader ID as a uint32 if no errors
  • Returns error if shader creation fails

func CreateVertexShader

func CreateVertexShader(shaderFile string) (uint32, error)

Create vertex shader from path to glsl vertex shader source

  • Returns shader ID as a uint32 if no errors
  • Returns error if shader creation fails

func GenBindBuffers

func GenBindBuffers(target uint32) uint32

Generate and bind buffers, and return the ID as a uint32

func GenBindTexture

func GenBindTexture() uint32

Creates and binds a texture ID via a uint32 ID

func GenBindVertexArrays

func GenBindVertexArrays() uint32

Generate and bind vertex arrays, and returns the ID as a uint32.

func InitSdlNoWindow

func InitSdlNoWindow() (*sdl.Window, sdl.GLContext)

func LoadTexture

func LoadTexture(filePath string) uint32

Load a RGBA texture file via path, and returns a uint32 as texture ID

func PrintVersionGL

func PrintVersionGL()

Prints OpenGL version information

func SetUBO

func SetUBO[T mgl64.Mat4 | mgl64.Vec3](data []T, UBOn uint32)

Sets the (data) for a given uniform buffer (UBOn)

func TriangleNormalCalc

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

Calculates the normal direction via 3 points in order as Vec3s, and returns it as a Vec3.

Types

type Camera

type Camera struct {
	Position mgl64.Vec3
	Front    mgl64.Vec3
	Up       mgl64.Vec3
	Right    mgl64.Vec3

	WorldUp mgl64.Vec3

	Yaw           float64
	Pitch         float64
	MovementAccel float64
	MouseSens     float64
	Zoom          float64
}

func NewCamera

func NewCamera(camPosition, worldUp mgl64.Vec3, camYaw, camPitch, camAccel, mouseSens float64) *Camera

Setup camera

Inputs are as follows in order:

  • Camera position as a Vec3
  • World up direction as a Vec3
  • Camera yaw as a float64 in degrees
  • Camera pitch as a float64 in degrees
  • Camera acceleration as a float64 as a multiplier
  • Camera mouse sensitivity as a float64 as a multiplier

Returns a pointer to the camera struct

func (*Camera) GetViewMatrix

func (camera *Camera) GetViewMatrix() mgl64.Mat4

Get the matrix of the object your looking at, and return it as a Mat4

func (*Camera) UpdateCamera

func (camera *Camera) UpdateCamera(direction Direction, deltaT, xoffset, yoffset float64)

Update the rotation and position of the camera

Inputs are as follows in order:

  • Direction in which the camera should be going (Forward, Backward, Left, Right)
  • The delta of the time or in other words the time of the frame as a float64
  • The X offset in degrees as a float64
  • The Y offset in degrees as a float64

type Direction

type Direction int
const (
	Forward Direction = iota
	Backward
	Left
	Right
	NoWhere
)

type ShaderInfo

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

func NewShaderProgram

func NewShaderProgram(vertexPath, fragmentPath string) (*ShaderInfo, error)

Creates a new shader program with a path to a glsl vertex shader, and fragment shader source, in that order

This is only meant to be used at start up

  • Returns a pointer to the ShaderInfo struct or nil if error
  • Returns a error or nil if none

func (*ShaderInfo) Use

func (shader *ShaderInfo) Use()

Simply uses the given shader program

type ShaderManager

type ShaderManager[T int32 | float64 | uint32 | mgl32.Vec4] struct {
	Window        *sdl.Window
	GLContext     sdl.GLContext
	ShaderProgram uint32
}

ShaderManager holds reusable resources for compute shader execution

func InitShaderManager

func InitShaderManager(shaderSource, sourceFile string) *ShaderManager[int32]

InitShaderManager initializes SDL, OpenGL, and compiles the shader

func InitShaderManagerFloat

func InitShaderManagerFloat(shaderSource, sourceFile string) *ShaderManager[float64]

InitShaderManager initializes SDL, OpenGL, and compiles the shader

func InitShaderManagerUint

func InitShaderManagerUint(shaderSource, sourceFile string) *ShaderManager[uint32]

InitShaderManager initializes SDL, OpenGL, and compiles the shader

func InitShaderManagerVec3

func InitShaderManagerVec3(shaderSource, sourceFile string) *ShaderManager[mgl32.Vec4]

InitShaderManager initializes SDL, OpenGL, and compiles the shader

func (*ShaderManager[T]) Cleanup

func (sm *ShaderManager[T]) Cleanup()

Cleanup releases all resources used by the ShaderManager

func (*ShaderManager[T]) Execute

func (sm *ShaderManager[T]) Execute(data []T, sizeWorkGP ...int) []T

Execute runs the compute shader with the provided data

Jump to

Keyboard shortcuts

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