engine

module
v0.0.0-...-a112006 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: BSD-2-Clause

README

G3N - Go 3D Game Engine

GoDoc

G3N is a basic (for now!) OpenGL 3D game engine written in Go. G3N was heavily inspired and based on the three.js Javascript 3D library. If you are curious about G3N and would like to see it in action we recommend that you install the G3N demo program.

Dependencies

The engine needs an OpenGL driver installed in the system and on Unix like systems depends on some C libraries that can be installed using the distribution package manager. In all cases it is necessary to have a gcc compatible C compiler installed.

  • For Ubuntu/Debian-like Linux distributions, install libgl1-mesa-dev and xorg-dev packages.
  • For CentOS/Fedora-like Linux distributions, install libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel packages.
  • Currently it was not tested on OS X.
  • For Windows we tested the build using the mingw-w64 toolchain.

G3N supports spatial audio using external libraries but loads these libraries dynamically on demand, so you can install G3N and build a 3D application (not using audio) without installing these libraries.

The following libraries are necessary for the optional audio support:

  • For Ubuntu/Debian-like Linux distributions, install libopenal1 and libvorbisfile3
  • For CentOS/Fedora-like Linux distributions, install libopenal1 and libvorbisfile3 (to be verified)
  • Currently it was not tested on OS X.
  • For Windows its is necessary to install the following dlls: OpenAL32.dll, libogg.dll, libvorbis.dll and libvorbisfile.dll. See windows_audio_dlls for how to get them.

G3N was only tested with Go1.7.4+

Installation

The following command will download the engine and all its dependencies, compile and install the packages. Make sure your GOPATH is set correctly.

go get -u github.com/g3n/engine/...

Features

  • Hierarchical scene graph. Any node can contain other nodes.
  • Supports perspective and orthographic cameras. The camera can be controlled by the orbit control which allow zooming, rotation and panning using the mouse or keyboard.
  • Suports ambient, directional, point and spot lights. Many lights can be added to the scene.
  • Generators for primitive geometries such as: lines, box, sphere, cylinder and torus.
  • Geometries can support multimaterials.
  • Image textures can loaded from GIF, PNG or JPEG files and applied to materials.
  • Loaders for the following 3D formats: Obj and Collada
  • Text support allowing loading freetype fonts.
  • Basic GUI supporting the widgets: label, image, button, checkbox, radiobutton, edit, scrollbar, slider, splitter, list, dropdown, tree, folder, window and layout managers (horizontal box, vertical box, grid, dock)
  • Spatial audio support allowing playing sound from wave or Ogg Vorbis files.
  • Users' applications can use their own vertex and fragment shaders.

Basic application

The following code shows a basic G3N application (hellog3n) which shows a wireframed sphere rotating. You can install hellog3n using: go get -u github.com/g3n/demos/hellog3n

For more complex demos please see the G3N demo program.

package main

import (
	"github.com/g3n/engine/camera"
	"github.com/g3n/engine/core"
	"github.com/g3n/engine/geometry"
	"github.com/g3n/engine/gls"
	"github.com/g3n/engine/graphic"
	"github.com/g3n/engine/light"
	"github.com/g3n/engine/material"
	"github.com/g3n/engine/math32"
	"github.com/g3n/engine/renderer"
	"github.com/g3n/engine/window"
	"math"
	"runtime"
)

func main() {

	// Creates window and OpenGL context
	win, err := window.New("glfw", 800, 600, "Hello G3N", false)
	if err != nil {
		panic(err)
	}

	// OpenGL functions must be executed in the same thread where
	// the context was created (by window.New())
	runtime.LockOSThread()

	// Create OpenGL state
	gs, err := gls.New()
	if err != nil {
		panic(err)
	}

	// Sets the OpenGL viewport size the same as the window size
	// This normally should be updated if the window is resized.
	width, height := win.GetSize()
	gs.Viewport(0, 0, int32(width), int32(height))

	// Creates scene for 3D objects
	scene := core.NewNode()

	// Adds white ambient light to the scene
	ambLight := light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 0.5)
	scene.Add(ambLight)

	// Adds a perspective camera to the scene
	// The camera aspect ratio should be updated if the window is resized.
	aspect := float32(width) / float32(height)
	camera := camera.NewPerspective(65, aspect, 0.01, 1000)
	camera.SetPosition(0, 0, 5)

	// Add an axis helper to the scene
	axis := graphic.NewAxisHelper(2)
	scene.Add(axis)

	// Creates a wireframe sphere positioned at the center of the scene
	geom := geometry.NewSphere(2, 16, 16, 0, math.Pi*2, 0, math.Pi)
	mat := material.NewStandard(math32.NewColor(1, 1, 1))
	mat.SetSide(material.SideDouble)
	mat.SetWireframe(true)
	sphere := graphic.NewMesh(geom, mat)
	scene.Add(sphere)

	// Creates a renderer and adds default shaders
	rend := renderer.NewRenderer(gs)
	err = rend.AddDefaultShaders()
	if err != nil {
		panic(err)
	}

	// Sets window background color
	gs.ClearColor(0, 0, 0, 1.0)

	// Render loop
	for !win.ShouldClose() {

		// Clear buffers
		gs.Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)

		// Rotates the sphere a bit around the Z axis (up)
		sphere.AddRotationY(0.005)

		// Render the scene using the specified camera
		rend.Render(scene, camera)

		// Update window and checks for I/O events
		win.SwapBuffers()
		win.PollEvents()
	}
}

hellog3n Screenshot

To Do

G3N is a basic game engine. There is a lot of things to do. We will soon insert here a list of the most important missing features.

Documentation

For the engine API reference, please use GoDoc. Currently the best way to learn how to use the engine is to see the source code of the demos from G3ND. We intend to write in the future documentation topics to build a user guide in the wiki.

Contributing

If you spot a bug or create a new feature you are encouraged to send pull requests.

Directories

Path Synopsis
Package audio contains sub packages for binding to external audio libraries and implements a spatial audio player.
Package audio contains sub packages for binding to external audio libraries and implements a spatial audio player.
al
Package al implements the Go bindings of a subset of the functions of the OpenAL C library.
Package al implements the Go bindings of a subset of the functions of the OpenAL C library.
ov
Package ov implements the Go bindings of a subset of the functions of the Ogg Vorbis File C library.
Package ov implements the Go bindings of a subset of the functions of the Ogg Vorbis File C library.
vorbis
Package vorbis implements the Go bindings of a subset (only one function) of the functions of the libvorbis library It also implements a loader so the library can be dynamically loaded See API reference at: https://xiph.org/vorbis/doc/libvorbis/reference.html
Package vorbis implements the Go bindings of a subset (only one function) of the functions of the libvorbis library It also implements a loader so the library can be dynamically loaded See API reference at: https://xiph.org/vorbis/doc/libvorbis/reference.html
Package camera contain common camera types used for rendering 3D scenes.
Package camera contain 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.
Package geometry implements several primitive geometry generators.
Package geometry implements several primitive geometry generators.
Package gls allows access to the OpenGL functions.
Package gls allows access to the OpenGL functions.
Package graphic implements scene objects which have a graphic representation.
Package graphic implements scene objects which have a graphic representation.
gui
Package gui implements the GUI infraestructure and several widgets.
Package gui implements the GUI infraestructure and several widgets.
assets
This file was generated from the original 'codepoints' file from the material icon fonts.
This file was generated from the original 'codepoints' file from the material icon fonts.
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
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.
shader
Package shader contains the several shaders used by the engine.
Package shader contains the several shaders used by the engine.
Package text implements text font support.
Package text implements text font support.
Package textures contains several types of texture which can be added to materials.
Package textures contains several types of texture which can be added to materials.
util
logger
Package logger implements an hierachical logger used by other packages.
Package logger implements an hierachical logger used by other packages.
Package window abstracts the OpenGL Window manager Currently only "glfw" is supported
Package window abstracts the OpenGL Window manager Currently only "glfw" is supported

Jump to

Keyboard shortcuts

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