Go 3D Game Engine http://g3n.rocks
Fork from https://github.com/g3n/engine

Daniel Salvadori 62faf56b25 improved screenshot link 7 лет назад
audio 29a5ff33c8 cleanup/docs/golint 7 лет назад
camera 753095026f cleanup 7 лет назад
core 771dfe2ae1 added index-based children-related methods to Node 7 лет назад
geometry 3b9a383b76 improve box geometry argument validation 7 лет назад
gls 018156cd56 added docs to OpenGL binding 7 лет назад
graphic 50bebfa1f9 improve box geometry API 7 лет назад
gui e9f6bf4aa7 added dark style, made it the default 7 лет назад
light 29a5ff33c8 cleanup/docs/golint 7 лет назад
loader 29a5ff33c8 cleanup/docs/golint 7 лет назад
material 8ddeeafafa cleanup 7 лет назад
math32 690273855c cleanup/docs/golint 7 лет назад
renderer 3d9211ec5f improved edit/label/font and panel shader 7 лет назад
text 3d9211ec5f improved edit/label/font and panel shader 7 лет назад
texture 0bba2e7b57 minor doc/typo fixes 7 лет назад
tools fcfe0a8067 improved docs 7 лет назад
util 690273855c cleanup/docs/golint 7 лет назад
window 3227dca484 window api changed / application exec tracer support 8 лет назад
.gitattributes 60a4df0db5 mark audio/windows as linguist-vendored 7 лет назад
LICENSE 3585b36aec first import 8 лет назад
README.md 62faf56b25 improved screenshot link 7 лет назад

README.md

G3N Banner

Godoc Go Report Card

G3N - Go 3D Game Engine

G3N (pronounced "gen") is an OpenGL 3D game engine written in Go. G3N was heavily inspired by three.js.

To see G3N in action try the G3N demo or the Gokoban award winning game.

G3ND In Action

Highlighted Projects

Gokoban - 3D Puzzle Game (1st place in the 2017 Gopher Game Jam)

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 the following packages:
    • xorg-dev
    • libgl1-mesa-dev
    • libopenal1
    • libopenal-dev
    • libvorbis0a
    • libvorbis-dev
    • libvorbisfile3
  • For CentOS/Fedora-like Linux distributions, install the following packages:
    • xorg-x11-devel.x86_64
    • mesa-libGL.x86_64
    • mesa-libGL-devel.x86_64
    • openal-soft.x86_64
    • openal-soft-devel.x86_64
    • libvorbis.x86_64
    • libvorbis-devel.x86_64
  • For Windows the necessary audio libraries sources and dlls are supplied but they need to be installed manually. Please see Audio libraries for Windows for details. We tested the Windows build using the mingw-w64 toolchain.
  • Currently not tested on OS X

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.

G3N Banner

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
	wmgr, err := window.Manager("glfw")
	if err != nil {
		panic(err)
	}
	win, err := wmgr.CreateWindow(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 CreateWindow())
	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.Size()
	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("White"))
	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)
	}
	rend.SetScene(scene)

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

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

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

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

		// Update window and checks for I/O events
		win.SwapBuffers()
		wmgr.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.

Community

Join our channel on Gophers Slack.