gravity

package module
v0.0.0-...-ea655a8 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 17 Imported by: 0

README

Gravity

3D OpenGL engine for Go

Building

Under the developing directory is the project code I use to test as I work on the engine itself. I keep it always buildable when commiting. To try it out, run the command gdt rundevapp or ./gdt.bash rundevapp

Current Development

The very latest progress demo can be viewed on youtube: https://www.youtube.com/watch?v=sHncnFAnDek

Summary: Terrain generated by World Machine loaded into engine. I am still working out exactly how to texture the terrain mesh correctly with the splat maps and height maps.

View more screenshots at doc/progress.md

Next Development

Next on the todo list is bolting on a physics engine. Currently I have a prototype of bullet3 working well enough and if nothing changes, I plan to integrated bullet3 very soon.

On the horizon is to begin implementing a proper scene graph which will pave way for ECS implementation.

Gravity Development Tools

For consistent tooling purposes across platforms all common Gravity development tooling is being put into ./developing/tools as go source files. You can run these tools by using go run ./developing/tools <command>

Currently available GDT commands:
apitrace - trace full opengl state and opens qapitrace gui (requires apitrace)
depgraph - graphs package dependency relationships of Gravity (requires graphiz)
genversion - generate the version.go source file for Gravity (requires git) rundevapp - go run's the developing/experimenting program under ./developing

Documentation

Overview

Code generated by gravity-development-toolkit. DO NOT EDIT.

Index

Constants

View Source
const (
	MouseButton1 = Button(0)
	MouseButton2 = Button(1)
	MouseButton3 = Button(2)
	MouseButton4 = Button(3)
	MouseLeft    = Button(MouseButton1)
	MouseRight   = Button(MouseButton2)
)

List of all mouse buttons.

View Source
const (
	KeySpace        = Button(32)
	KeyApostrophe   = Button(39)
	KeyComma        = Button(44)
	KeyMinus        = Button(45)
	KeyPeriod       = Button(46)
	KeySlash        = Button(47)
	Key0            = Button(48)
	Key1            = Button(49)
	Key2            = Button(50)
	Key3            = Button(51)
	Key4            = Button(52)
	Key5            = Button(53)
	Key6            = Button(54)
	Key7            = Button(55)
	Key8            = Button(56)
	Key9            = Button(57)
	KeySemicolon    = Button(59)
	KeyEqual        = Button(61)
	KeyA            = Button(65)
	KeyB            = Button(66)
	KeyC            = Button(67)
	KeyD            = Button(68)
	KeyE            = Button(69)
	KeyF            = Button(70)
	KeyG            = Button(71)
	KeyH            = Button(72)
	KeyI            = Button(73)
	KeyJ            = Button(74)
	KeyK            = Button(75)
	KeyL            = Button(76)
	KeyM            = Button(77)
	KeyN            = Button(78)
	KeyO            = Button(79)
	KeyP            = Button(80)
	KeyQ            = Button(81)
	KeyR            = Button(82)
	KeyS            = Button(83)
	KeyT            = Button(84)
	KeyU            = Button(85)
	KeyV            = Button(86)
	KeyW            = Button(87)
	KeyX            = Button(88)
	KeyY            = Button(89)
	KeyZ            = Button(90)
	KeyLeftBracket  = Button(91)
	KeyBackSlash    = Button(92)
	KeyRightBracket = Button(93)
	KeyGrave        = Button(96)
	KeyEscape       = Button(256)
	KeyEnter        = Button(257)
	KeyTab          = Button(258)
	KeyBackspace    = Button(259)
	KeyInsert       = Button(260)
	KeyDelete       = Button(261)
	KeyRight        = Button(262)
	KeyLeft         = Button(263)
	KeyDown         = Button(264)
	KeyUp           = Button(265)
	KeyPageUp       = Button(266)
	KeyPageDown     = Button(267)
	KeyHome         = Button(268)
	KeyEnd          = Button(269)
	KeyCaps         = Button(280)
	KeyScroll       = Button(281)
	KeyNumlock      = Button(282)
	KeyPrintScreen  = Button(283)
	KeyPause        = Button(284)
	KeyF1           = Button(290)
	KeyF2           = Button(291)
	KeyF3           = Button(292)
	KeyF4           = Button(293)
	KeyF5           = Button(294)
	KeyF6           = Button(295)
	KeyF7           = Button(296)
	KeyF8           = Button(297)
	KeyF9           = Button(298)
	KeyF10          = Button(299)
	KeyF11          = Button(300)
	KeyF12          = Button(301)
	KeyF13          = Button(302)
	KeyF14          = Button(303)
	KeyF15          = Button(304)
	KeyF16          = Button(305)
	KeyF17          = Button(306)
	KeyF18          = Button(307)
	KeyF19          = Button(308)
	KeyF20          = Button(309)
	KeyF21          = Button(310)
	KeyF22          = Button(311)
	KeyF23          = Button(312)
	KeyF24          = Button(313)
	KeyF25          = Button(314)
	KeyKP0          = Button(320)
	KeyKP1          = Button(321)
	KeyKP2          = Button(322)
	KeyKP3          = Button(323)
	KeyKP4          = Button(324)
	KeyKP5          = Button(325)
	KeyKP6          = Button(326)
	KeyKP7          = Button(327)
	KeyKP8          = Button(328)
	KeyKP9          = Button(329)
	KeyDecimal      = Button(330)
	KeyDivide       = Button(331)
	KeyMultiply     = Button(332)
	KeySubtract     = Button(333)
	KeyAdd          = Button(334)
	KeyKPEnter      = Button(335)
	KeyKPEqual      = Button(336)
	KeyLeftShift    = Button(340)
	KeyLeftControl  = Button(341)
	KeyLeftAlt      = Button(342)
	KeyLeftSuper    = Button(343)
	KeyRightShift   = Button(344)
	KeyRightControl = Button(345)
	KeyRightAlt     = Button(346)
	KeyRightSuper   = Button(347)
	KeyMenu         = Button(348)

	LastKey = KeyMenu
)

List of all keyboard buttons.

Primitive types

View Source
const Version = "ep05-cea49a (expirimental/prototyping)"

Version ...

Variables

View Source
var Callbacks = struct {
	CaptureModeOnChange func(bool)
}{
	CaptureModeOnChange: func(b bool) {},
}

Callbacks ...

View Source
var OnMouseMove = func(_ *glfw.Window, x, y float64) {
	_x, _y := float32(x), window.Height-float32(y)

	_mouse.Delta[0] = _x - Mouse.Position[0]
	_mouse.Delta[1] = _y - Mouse.Position[1]
	_mouse.Position[0] = _x
	_mouse.Position[1] = _y
}

OnMouseMove ...

View Source
var OnMouseScroll = func(_ *glfw.Window, xoff float64, yoff float64) {
	_mouse.Scroll[0] += float32(xoff)
	_mouse.Scroll[1] += float32(yoff)
}

OnMouseScroll ...

Functions

func Abs

func Abs(f float32) float32

Abs ...

func Asin

func Asin(x float32) float32

Asin ...

func Atan2

func Atan2(y, x float32) float32

Atan2 ...

func Captured

func Captured() bool

Captured ...

func Cos

func Cos(f float32) float32

Cos ...

func D2R

func D2R(d float32) float32

D2R ...

func Deg2Quat

func Deg2Quat(yaw, pitch float32) mgl32.Quat

Deg2Quat ...

func GetMaterialProgram

func GetMaterialProgram(name string) *gravitygl.Program

GetMaterialProgram ...

func Init

func Init(cfg Config)

Init ...

func JustPressed

func JustPressed(btn Button) bool

JustPressed ...

func Max

func Max(a, b float32) float32

Max ...

func Min

func Min(a, b float32) float32

Min ...

func Mod

func Mod(x, y float32) float32

Mod ...

func Norm

func Norm(q mgl32.Quat) float32

Norm ...

func Pressed

func Pressed(btn Button) bool

Pressed ...

func PrintVec3

func PrintVec3(v mgl32.Vec3) string

PrintVec3 ...

func QuatToEuler

func QuatToEuler(q mgl32.Quat) (float32, float32, float32)

QuatToEuler ...

func QuatToEulerDeg

func QuatToEulerDeg(q mgl32.Quat) (float32, float32, float32)

QuatToEulerDeg ...

func R2D

func R2D(r float32) float32

R2D ...

func Run

func Run(run func())

Run ...

func Running

func Running() bool

Running ...

func ScreenToGLCoords

func ScreenToGLCoords(width, height, x, y float32) (float32, float32)

ScreenToGLCoords ...

func SetCaptureMode

func SetCaptureMode(b bool)

SetCaptureMode ...

func SetQuatFromEuler

func SetQuatFromEuler(q *mgl32.Quat, v mgl32.Vec3) *mgl32.Quat

SetQuatFromEuler ...

func Sin

func Sin(f float32) float32

Sin ...

func Sincos

func Sincos(x float32) (sin, cos float32)

Sincos ...

func Stop

func Stop()

Stop ...

func TextureDataFromImage

func TextureDataFromImage(img image.Image) *image.RGBA

TextureDataFromImage ... GL texture data really should aways be 4 wide (rgba). Fix this function to convert it if necessary.

func TextureImageFromFile

func TextureImageFromFile(filename string) image.Image

TextureImageFromFile ...

func TextureRGBAFromFile

func TextureRGBAFromFile(filename string) *image.RGBA

TextureRGBAFromFile ...

func Unit

func Unit(q mgl32.Quat) mgl32.Quat

Unit ...

func Unpress

func Unpress(btn Button)

Unpress ...

func Update

func Update()

Update ...

func UpdateInput

func UpdateInput()

UpdateInput ...

func UploadToGPU

func UploadToGPU(t *Texture)

UploadToGPU ...

Types

type BaseMaterial

type BaseMaterial struct {
	ID        uint32
	Primitive PrimitiveType
	Program   *gravitygl.Program
}

BaseMaterial ...

func NewBaseMaterial

func NewBaseMaterial(programName string) *BaseMaterial

NewBaseMaterial ...

func (*BaseMaterial) SubmitUniforms

func (mat *BaseMaterial) SubmitUniforms(ulist []UniformSubmission)

SubmitUniforms ...

type BaseObject

type BaseObject struct {
	*Transformer

	Primitive PrimitiveType
	// contains filtered or unexported fields
}

BaseObject ...

func NewBaseObject

func NewBaseObject() *BaseObject

NewBaseObject ...

func (*BaseObject) LinkVAO

func (obj *BaseObject) LinkVAO(vao *gravitygl.VertexArray)

LinkVAO ...

func (*BaseObject) Prepare

func (obj *BaseObject) Prepare()

Prepare ...

func (*BaseObject) SetTag

func (obj *BaseObject) SetTag(tag string)

SetTag ...

func (*BaseObject) Tag

func (obj *BaseObject) Tag() string

Tag ...

type Button

type Button int

Button ...

func (Button) String

func (b Button) String() string

String ...

type Camera

type Camera struct {
	*Transformer

	ProjectionMatrix mgl32.Mat4
	ViewMatrix       mgl32.Mat4
	// contains filtered or unexported fields
}

Camera ...

func NewCamera

func NewCamera(options ...CameraOption) *Camera

NewCamera ...

func (*Camera) ChangePerspective

func (cam *Camera) ChangePerspective(fovy, aspect, near, far float32)

ChangePerspective ...

func (*Camera) GetViewMatrix

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

GetViewMatrix ...

func (*Camera) GetYawPitch

func (cam *Camera) GetYawPitch() (float32, float32)

func (*Camera) MoveBackward

func (cam *Camera) MoveBackward(speed float32)

MoveBackward ...

func (*Camera) MoveDown

func (cam *Camera) MoveDown(speed float32)

MoveDown ...

func (*Camera) MoveForward

func (cam *Camera) MoveForward(speed float32)

MoveForward ...

func (*Camera) MoveLeft

func (cam *Camera) MoveLeft(speed float32)

MoveLeft ...

func (*Camera) MoveRight

func (cam *Camera) MoveRight(speed float32)

MoveRight ...

func (*Camera) MoveUp

func (cam *Camera) MoveUp(speed float32)

MoveUp ...

func (*Camera) Push

func (cam *Camera) Push(pitch, yaw float32)

Push ...

func (*Camera) Update

func (cam *Camera) Update()

Update ...

type CameraOption

type CameraOption func(c *Camera)

CameraOption ...

func Position

func Position(x, y, z float32) CameraOption

Position ...

func Rotate

func Rotate(yaw, pitch float32) CameraOption

Rotate ...

type Config

type Config struct {
	Title         string
	Width, Height int
	VSync         bool
}

Config ...

type ImageData

type ImageData struct {
	Pix    []uint8
	Width  int32
	Height int32
	Stride int
}

ImageData ...

func NewImageDataFromFile

func NewImageDataFromFile(filename string) *ImageData

NewImageDataFromFile ...

func NewImageDataFromImage

func NewImageDataFromImage(img image.Image) *ImageData

NewImageDataFromImage ...

type Material

type Material interface {
	GetBaseMaterial() *BaseMaterial
	PreRender()
	Render()
}

Material ...

type Model

type Model struct {
	*BaseObject

	Mesh *mesh.Mesh
	Mat  Material
	// contains filtered or unexported fields
}

Model ...

func NewModel

func NewModel(m *mesh.Mesh, material Material, cam *Camera) *Model

NewModel ...

func (*Model) AddUniform

func (model *Model) AddUniform(name string, data interface{})

AddUniform ...

func (*Model) Base

func (model *Model) Base() *BaseObject

Base ...

func (*Model) Prepare

func (model *Model) Prepare()

Prepare ...

func (*Model) Renderable

func (model *Model) Renderable() bool

Renderable ...

type MouseInfo

type MouseInfo struct {
	Position [2]float32
	Delta    [2]float32
	Scroll   [2]float32
	// contains filtered or unexported fields
}

MouseInfo ...

var Mouse MouseInfo

Mouse ...

type Object

type Object interface {
	Base() *BaseObject
	Renderable() bool
	Prepare()
}

Object ...

type PrimitiveType

type PrimitiveType = uint32

PrimitiveType ...

type PrintFn

type PrintFn = func(a ...interface{})

PrintFn ...

type PrintfFn

type PrintfFn = func(format string, a ...interface{})

PrintfFn ...

type PrintlnFn

type PrintlnFn = func(a ...interface{})

PrintlnFn ...

type Redirector

type Redirector struct {
	Print   PrintFn
	Printf  PrintfFn
	Println PrintlnFn
}

Redirector ...

func GetLogRedirector

func GetLogRedirector() *Redirector

GetLogRedirector ...

func (*Redirector) SetDefaults

func (r *Redirector) SetDefaults()

SetDefaults ...

func (*Redirector) SetPrint

func (r *Redirector) SetPrint(fn PrintFn)

SetPrint ...

func (*Redirector) SetPrintf

func (r *Redirector) SetPrintf(fn PrintfFn)

SetPrintf ...

func (*Redirector) SetPrintln

func (r *Redirector) SetPrintln(fn PrintlnFn)

SetPrintln ...

type Scene

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

Scene ...

func (*Scene) Import

func (s *Scene) Import(obj Object)

Import ...

func (*Scene) Render

func (s *Scene) Render()

Render ...

func (*Scene) SetCamera

func (s *Scene) SetCamera(c *Camera) *Camera

SetCamera ...

type Texture

type Texture struct {
	ImageData      []*ImageData
	Unit           uint32
	ID             uint32
	TextureID      uint32
	Target         uint32
	Mips           int32
	Format         int32
	Originalformat uint32
	MagFilter      int32
	MinFilter      int32
	WrapS          int32
	WrapT          int32
	WrapR          int32
}

Texture ...

func NewCubeMap

func NewCubeMap(PosX, NegX, PosY, NegY, PosZ, NegZ string) *Texture

NewCubeMap ...

func NewTextureFromFile

func NewTextureFromFile(target uint32, filename ...string) *Texture

NewTextureFromFile ...

func NewTextureFromImage

func NewTextureFromImage(target uint32, img ...image.Image) *Texture

NewTextureFromImage ...

type Transformer

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

Transformer ...

func NewTransformer

func NewTransformer() *Transformer

NewTransformer ...

func (*Transformer) GetPosition

func (t *Transformer) GetPosition() mgl32.Vec3

GetPosition ...

func (*Transformer) GetRotation

func (t *Transformer) GetRotation() mgl32.Quat

GetRotation ...

func (*Transformer) GetScale

func (t *Transformer) GetScale() mgl32.Vec3

GetScale ...

func (*Transformer) GetTransformMatrix

func (t *Transformer) GetTransformMatrix() *mgl32.Mat4

GetTransformMatrix ...

func (*Transformer) Scale

func (t *Transformer) Scale(v mgl32.Vec3)

Scale ...

func (*Transformer) ScaleX

func (t *Transformer) ScaleX(f float32)

ScaleX ...

func (*Transformer) ScaleY

func (t *Transformer) ScaleY(f float32)

ScaleY ...

func (*Transformer) ScaleZ

func (t *Transformer) ScaleZ(f float32)

ScaleZ ...

func (*Transformer) Scalef

func (t *Transformer) Scalef(f float32)

Scalef ...

func (*Transformer) SetPosition

func (t *Transformer) SetPosition(x, y, z float32)

SetPosition ...

func (*Transformer) SetRotation

func (t *Transformer) SetRotation(q mgl32.Quat)

SetRotation ...

func (*Transformer) Translate

func (t *Transformer) Translate(v mgl32.Vec3)

Translate ...

func (*Transformer) TranslateX

func (t *Transformer) TranslateX(d float32)

TranslateX ...

func (*Transformer) TranslateY

func (t *Transformer) TranslateY(d float32)

TranslateY ...

func (*Transformer) TranslateZ

func (t *Transformer) TranslateZ(d float32)

TranslateZ ...

func (*Transformer) UpdateTransform

func (t *Transformer) UpdateTransform()

UpdateTransform ...

type UniformSubmission

type UniformSubmission struct {
	Type gravitygl.Enum
	Loc  int32
	Data interface{}
}

UniformSubmission ...

type Window

type Window struct {
	Width, Height float32
	GlfwWin       *glfw.Window
	// contains filtered or unexported fields
}

Window ...

func GetWindow

func GetWindow() *Window

GetWindow ...

func (*Window) Captured

func (win *Window) Captured() bool

Captured ...

Directories

Path Synopsis
internal
pkg
tools

Jump to

Keyboard shortcuts

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