GameEngine

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

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

Go to latest
Published: Apr 24, 2015 License: MIT Imports: 14 Imported by: 0

README

GameEngine

Rapid Game Prototyping Library, Written in Go

Using OpenGL and GLFW, this library makes it easy to get that first window open and start working on your game loop. It even supplies a native mesh type (as if we need another one of these) in case you don't have one to work with. See examples for details.

Admittedly, this library is far from finished. This being my very first Go project, and having worked on several since, there are many things I would have done differently (e.g., using interfaces, better abstraction, etc) to meet this library's goal. My hope is that by publishing it on github it might spark some ideas or get improved/forked. There is no documentation yet, but if someone finds this library interesting I may write some--perhaps even continue development. So, provide some feedback!

This library utilizes the legacy GL package, simply because it was written before the updated OpenGL bindings at https://github.com/go-gl/gl were updated. This could be changed in the future.

GameEngine is released under the MIT license; see LICENSE for more details.

Documentation

Overview

Engine implements...

Error implements...

Input implements...

Monitor implements...

Window implements...

Index

Constants

View Source
const (
	ORTHOGRAPHIC = iota
	PERSPECTIVE  = iota
)

Variables

View Source
var (
	DefaultWindowHints = map[glfw.Hint]int{
		glfw.ContextVersionMajor:     3,
		glfw.ContextVersionMinor:     3,
		glfw.OpenglForwardCompatible: glfw.True,
		glfw.OpenglProfile:           glfw.OpenglCoreProfile,
	}

	DefaultSettings = Settings{
		Vsync: 1,
		Windows: []Window{
			Window{
				KeyCallbacks: []KeyCallback{
					DefaultKeyCallback,
				},
				LoopCallback: DefaultLoopCallback,
				Title:        "GameEngine",
			},
		},
	}
)

Functions

func CheckGLError

func CheckGLError()

func DefaultKeyCallback

func DefaultKeyCallback(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey)

Default Key Handling Function

func DefaultLoopCallback

func DefaultLoopCallback(w *Window, e *Engine)

Default Loop Function

func Mat4dToMat4f

func Mat4dToMat4f(m mgl64.Mat4) (M mgl32.Mat4)

Types

type Camera

type Camera struct {
	Object
	ProjectionType uint

	//Projection Properties
	Far, Near,

	Left, Right, Bottom, Top,

	Aspect, SensorHeight, SensorWidth, FocalLength float64
}

func (*Camera) FieldOfViewX

func (c *Camera) FieldOfViewX() float64

Horizontal Field of View

func (*Camera) FieldOfViewY

func (c *Camera) FieldOfViewY() float64

Vertical Field of View

func (*Camera) Init

func (c *Camera) Init()

func (*Camera) ProjectionMatrix

func (c *Camera) ProjectionMatrix() mgl.Mat4

func (*Camera) TransformationMatrix

func (c *Camera) TransformationMatrix() mgl.Mat4

func (*Camera) ViewMatrix

func (c *Camera) ViewMatrix() mgl.Mat4

type ColladaDoc

type ColladaDoc struct {
	XMLName xml.Name `xml:"COLLADA"`
	Collada14.TxsdCollada
}

func ImportColladaFile

func ImportColladaFile(filename string) (c *ColladaDoc)

type Engine

type Engine struct {
	Settings *Settings
	Monitors []Monitor
	Windows  []Window
	Objects  []*Object
	Cameras  []*Camera

	ActiveCamera *Camera

	InitCallBacks []InitCallBack

	WindowHints map[glfw.Hint]int
}

Main Driver

func (*Engine) ActivateCamera

func (e *Engine) ActivateCamera(c *Camera)

func (*Engine) ActivateCameraIndex

func (e *Engine) ActivateCameraIndex(i int) *Camera

func (*Engine) Finish

func (e *Engine) Finish()

func (*Engine) FromCollada

func (e *Engine) FromCollada(c *ColladaDoc)

func (*Engine) FromColladaFile

func (e *Engine) FromColladaFile(filepath string)

func (*Engine) Hint

func (e *Engine) Hint()

func (*Engine) Init

func (e *Engine) Init() error

func (*Engine) NewCamera

func (e *Engine) NewCamera() (c *Camera)

func (*Engine) NewObject

func (e *Engine) NewObject() (o *Object)

func (*Engine) Run

func (e *Engine) Run() error

type GeneralError

type GeneralError struct {
	Time    time.Time
	Details string
}

func (*GeneralError) Error

func (e *GeneralError) Error() string

func (*GeneralError) Log

func (e *GeneralError) Log(d string)

type InitCallBack

type InitCallBack func(e *Engine)

type KeyCallback

type KeyCallback func(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey)

type LoopCallback

type LoopCallback func(w *Window, e *Engine)

type Mesh

type Mesh struct {
	Programs []*Program
	Vertices []Vertex
	Indices  []uint32
}

func (*Mesh) CalculateNormals

func (m *Mesh) CalculateNormals()

func (*Mesh) NewProgram

func (m *Mesh) NewProgram() (p *Program)

type Monitor

type Monitor struct {
	*glfw.Monitor
}

type OGLError

type OGLError struct {
	*GeneralError
}

type OGLObjectError

type OGLObjectError struct {
	*GeneralError
	OGLObject *gl.Object
}

type OGLProgramError

type OGLProgramError struct {
	*GeneralError
	OGLProgram *Program
}

type OGLShaderError

type OGLShaderError struct {
	*GeneralError
	OGLShader *Shader
}

func (*OGLShaderError) Log

func (e *OGLShaderError) Log(s *Shader, d string)

type Object

type Object struct {
	Meshes      []*Mesh
	Translation mgl.Mat4
	Rotation    mgl.Mat4
	Scale       mgl.Mat4
}

func (*Object) Init

func (o *Object) Init()

func (*Object) NewMesh

func (o *Object) NewMesh() (m *Mesh)

type Program

type Program struct {
	gl.Program
	Shaders []*Shader
}

func (*Program) MakeProgram

func (p *Program) MakeProgram()

func (*Program) NewShader

func (p *Program) NewShader(t gl.GLenum) (s *Shader)

func (*Program) Register

func (p *Program) Register() error

Use TBD over this method--may be unexported in the future; Reserves the program resource on the GPU

type Settings

type Settings struct {
	Vsync   int
	Windows []Window
}

type Shader

type Shader struct {
	gl.Shader
	Type   gl.GLenum
	Source string
}

func (*Shader) Create

func (s *Shader) Create()

func (*Shader) Register

func (s *Shader) Register() error

Use TBD over this method--may be unexported in the future; Reserves the shader resource on the GPU

func (*Shader) SourceFile

func (s *Shader) SourceFile(p string) error

type Vec2

type Vec2 mgl.Vec2

type Vec3

type Vec3 mgl.Vec3

type Vec4

type Vec4 mgl.Vec4

type Vertex

type Vertex struct {
	Position mgl.Vec3
	Color    mgl.Vec4
	Normal   mgl.Vec3
	UVST     mgl.Vec2
	Index    uint32
}

func (*Vertex) CalculateNormal

func (v *Vertex) CalculateNormal(m *Mesh)

type Window

type Window struct {
	*glfw.Window
	*Monitor
	KeyCallbacks []KeyCallback
	LoopCallback
	Title      string
	Width      int
	Height     int
	ClearColor mgl.Vec4
}

func (*Window) Aspect

func (w *Window) Aspect() float64

Horizontal Field of View

func (*Window) SetKeyCallbackRange

func (w *Window) SetKeyCallbackRange()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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