g3n

package module
v0.0.0-...-8dce647 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: BSD-2-Clause Imports: 1 Imported by: 0

README

TGE-G3N - G3N plugin for TGE

Godoc Go Report Card

Game Engine for TGE runtime - TGE

Based on :

  • G3N - Copyright (c) 2016 The G3N Authors. All rights reserved.

Targets

  • Desktop
  • Browsers
  • Mobile

Dependencies

Limitations

Not implemented:

  • audio - use tge-audio instead (WIP)
  • gui - use tge-nuklear instead (WIP)
  • window - replaced by TGE runtime

Implementation

See example at G3N examples

Just import package and replace G3N former entry point Application by App lifecycle:

package main

import (
	tge "github.com/thommil/tge"

	camera "github.com/thommil/tge-g3n/camera"
	core "github.com/thommil/tge-g3n/core"
	gls "github.com/thommil/tge-g3n/gls"
	light "github.com/thommil/tge-g3n/light"
	math32 "github.com/thommil/tge-g3n/math32"
	renderer "github.com/thommil/tge-g3n/renderer"
)

type G3NApp struct {
    runtime    tge.Runtime
    gls        *gls.GLS
    scene      *core.Node
    camPersp   *camera.Perspective
    renderer   *renderer.Renderer
}

func (app *G3NApp) OnStart(runtime tge.Runtime) error {
    runtime.Subscribe(tge.ResizeEvent{}.Channel(), app.OnResize)
	
    var err error

    // OpenGL
    app.gls, err = gls.New()
    if err != nil {
        return err
    }

    // INIT
    cc := math32.NewColor("black")
    app.gls.ClearColor(cc.R, cc.G, cc.B, 1)
    app.gls.Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)

    // SCENE
    app.scene = core.NewNode()
    app.renderer = renderer.NewRenderer(app.gls)
    err = app.renderer.AddDefaultShaders()
    if err != nil {
        return fmt.Errorf("Error from AddDefaulShaders:%v", err)
    }
    app.renderer.SetScene(app.scene)

    // TORUS
    geom := geometry.NewTorus(1, .4, 12, 32, math32.Pi*2)
    mat := material.NewPhong(math32.NewColor("DarkBlue"))
    torusMesh := graphic.NewMesh(geom, mat)
    app.scene.Add(torusMesh)
    
    // LIGHTS
    ambientLight := light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 0.8)
    app.scene.Add(ambientLight)

    pointLight := light.NewPoint(&math32.Color{1, 1, 1}, 100.0)
    pointLight.SetPosition(0, 0, 25)
    app.scene.Add(pointLight)

    // CAMERA
    app.camPersp = camera.NewPerspective(65, 1, 0.01, 1000)
    app.camPersp.SetPosition(10, 10, 10)
    app.camPersp.LookAt(&math32.Vector3{0, 0, 0})

    return nil
}

func (app *G3NApp) OnResize(event tge.Event) bool {
    app.camPersp.SetAspect(float32(event.(tge.ResizeEvent).Width) / float32(event.(tge.ResizeEvent).Height))
    app.gls.Viewport(0, 0, event.(tge.ResizeEvent).Width, event.(tge.ResizeEvent).Height)
    return false
}

func (app *G3NApp) OnRender(elapsedTime time.Duration, syncChan <-chan interface{}) {
    <-syncChan
    app.gls.Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)
    app.renderer.Render(app.camPersp)
}

func (app *G3NApp) OnTick(elapsedTime time.Duration, syncChan chan<- interface{}) {
    ...
    syncChan <- true
}

...

Documentation

Index

Constants

View Source
const Name = "g3n"

Name name of the plugin

Variables

This section is empty.

Functions

func Runtime

func Runtime() tge.Runtime

Runtime gives access to current running TGE Runtime

Types

This section is empty.

Directories

Path Synopsis
Package animation
Package animation
Package camera contains common camera types used for rendering 3D scenes.
Package camera contains common camera types used for rendering 3D scenes.
control
Package control implements controllers for cameras
Package control implements controllers for cameras
Package core implements some basic types used by other packages.
Package core implements some basic types used by other packages.
experimental
collision
Package collision implements collision related algorithms and data structures.
Package collision implements collision related algorithms and data structures.
physics
Package collision implements collision related algorithms and data structures.
Package collision implements collision related algorithms and data structures.
physics/constraint
Package constraint implements physics constraints.
Package constraint implements physics constraints.
physics/equation
Package equation implements SPOOK equations based on the 2007 PhD thesis of Claude Lacoursière titled "Ghosts and Machines: Regularized Variational Methods for Interactive Simulations of Multibodies with Dry Frictional Contacts"
Package equation implements SPOOK equations based on the 2007 PhD thesis of Claude Lacoursière titled "Ghosts and Machines: Regularized Variational Methods for Interactive Simulations of Multibodies with Dry Frictional Contacts"
physics/solver
Package physics implements a basic physics engine.
Package physics implements a basic physics engine.
Package geometry implements several primitive geometry generators.
Package geometry implements several primitive geometry generators.
Package gls implements a loader of OpenGL functions for the platform and a Go binding for selected OpenGL functions.
Package gls implements a loader of OpenGL functions for the platform and a Go binding for selected OpenGL functions.
Package graphic implements scene objects which have a graphic representation.
Package graphic implements scene objects which have a graphic representation.
Package light contains common light types which can be add to a 3D scene to illuminate it.
Package light contains common light types which can be add to a 3D scene to illuminate it.
loader
collada
Package collada
Package collada
gltf
Package gltf
Package gltf
obj
Package obj
Package obj
Package material contains several types of materials which can be used to set the appearance of graphic object
Package material contains several types of materials which can be used to set the appearance of graphic object
Package math32 implements basic math functions which operate directly on float32 numbers without casting and contains types of common entities used in 3D Graphics such as vectors, matrices, quaternions and others.
Package math32 implements basic math functions which operate directly on float32 numbers without casting and contains types of common entities used in 3D Graphics such as vectors, matrices, quaternions and others.
Package renderer implements the scene renderer.
Package renderer implements the scene renderer.
shaders
Package shaders contains the several shaders used by the engine
Package shaders contains the several shaders used by the engine
Package text implements text font support.
Package text implements text font support.
Package texture contains several types of textures which can be added to materials.
Package texture contains several types of textures which can be added to materials.
tools
g3nshaders
g3nshaders reads shaders files with ".glsl" extensions and generates a Go file containing strings with the content of these files.
g3nshaders reads shaders files with ".glsl" extensions and generates a Go file containing strings with the content of these files.
util

Jump to

Keyboard shortcuts

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