Skip to content

Getting Started (WIP)

Justin Clift edited this page Aug 18, 2018 · 5 revisions

This guide is a work in-progress.

Introduction

The g3n project is a game engine for Google Go (golang).

Installation

Dependencies

Installing on Windows

Installing on macOS

Installing on Linux

For Fedora, install the required packages:

$ sudo dnf -y install xorg-x11-proto-devel mesa-libGL mesa-libGL-devel openal-soft \
  openal-soft-devel libvorbis libvorbis-devel glfw-devel libXi-devel

For CentOS 7, enable the EPEL repo then install the same packages as for Fedora above:

$ sudo yum -y install \
  https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Remember to use yum instead of dnf for the package installation command.

Installing on FreeBSD

Hello, g3n!

package main

import (
	"github.com/g3n/engine/util/application"
	"github.com/g3n/engine/geometry"
	"github.com/g3n/engine/material"
	"github.com/g3n/engine/math32"
	"github.com/g3n/engine/graphic"
	"github.com/g3n/engine/light"
)

func main() {

	app, _ := application.Create(application.Options{
		Title:  "Hello G3N",
		Width:  800,
		Height: 600,
	})

	// Create a blue torus and add it to the scene
	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)

	// Add lights to the scene
	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}, 5.0)
	pointLight.SetPosition(1, 0, 2)
	app.Scene().Add(pointLight)

	// Add an axis helper to the scene
	axis := graphic.NewAxisHelper(0.5)
	app.Scene().Add(axis)

	app.CameraPersp().SetPosition(0, 0, 3)
	app.Run()
}

Imports

import (
	"github.com/g3n/engine/util/application"
	"github.com/g3n/engine/geometry"
	"github.com/g3n/engine/material"
	"github.com/g3n/engine/math32"
	"github.com/g3n/engine/graphic"
	"github.com/g3n/engine/light"
)

Creating an application

	app, _ := application.Create(application.Options{
		Title:  "Hello G3N",
		Width:  800,
		Height: 600,
	})

Creating a geometry

	geom := geometry.NewTorus(1, .4, 12, 32, math32.Pi*2)

Creating a material

	mat := material.NewPhong(math32.NewColor("DarkBlue"))

Creating a mesh

	torusMesh := graphic.NewMesh(geom, mat)

Adding a node to the scene

	app.Scene().Add(torusMesh)

Lighting

	// Add lights to the scene
	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}, 5.0)
	pointLight.SetPosition(1, 0, 2)
	app.Scene().Add(pointLight)

Axis helpers

	// Add an axis helper to the scene
	axis := graphic.NewAxisHelper(0.5)
	app.Scene().Add(axis)

Perspective camera

	app.CameraPersp().SetPosition(0, 0, 3)

Running the applicatioon

	app.Run()
Clone this wiki locally