Go 3D Game Engine http://g3n.rocks
Fork from https://github.com/g3n/engine
|
|
7 lat temu | |
|---|---|---|
| audio | 7 lat temu | |
| camera | 7 lat temu | |
| core | 7 lat temu | |
| geometry | 7 lat temu | |
| gls | 7 lat temu | |
| graphic | 7 lat temu | |
| gui | 7 lat temu | |
| light | 7 lat temu | |
| loader | 7 lat temu | |
| material | 7 lat temu | |
| math32 | 7 lat temu | |
| renderer | 7 lat temu | |
| text | 7 lat temu | |
| texture | 7 lat temu | |
| tools | 8 lat temu | |
| util | 7 lat temu | |
| window | 8 lat temu | |
| .gitattributes | 7 lat temu | |
| LICENSE | 8 lat temu | |
| README.md | 7 lat temu |

G3N (pronounced "gen") is an OpenGL 3D game engine written in Go. G3N was heavily inspired by the three.js Javascript 3D library.
Gokoban - 3D Puzzle Game (1st place in the 2017 Gopher Game Jam)
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.
xorg-devlibgl1-mesa-devlibopenal1libopenal-devlibvorbis0alibvorbis-devlibvorbisfile3xorg-x11-devel.x86_64mesa-libGL.x86_64mesa-libGL-devel.x86_64openal-soft.x86_64openal-soft-devel.x86_64libvorbis.x86_64libvorbis-devel.x86_64dlls 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.G3N was only tested with Go1.7.4+
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/...
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()
}
}
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.
For the engine API reference, please use
.
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.
If you spot a bug or create a new feature you are encouraged to send pull requests.
Join our channel on Gophers Slack.