init
This commit is contained in:
commit
aab9fd2460
|
|
@ -0,0 +1,12 @@
|
|||
module myschools.me/suguo/g3n-demo
|
||||
|
||||
go 1.21.5
|
||||
|
||||
require github.com/g3n/engine v0.2.0
|
||||
|
||||
require (
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
github.com/g3n/engine v0.2.0 h1:7dmj4c+3xHcBnYrVmRuVf/oZ2JycxJU9Y+2FQj1Af2Y=
|
||||
github.com/g3n/engine v0.2.0/go.mod h1:rnj8jiLdKEDI8VbveKhmdL4rovjjy+uxNP5YROg2x8g=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9 h1:D0iM1dTCbD5Dg1CbuvLC/v/agLc79efSj/L35Q3Vqhs=
|
||||
golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/g3n/engine/app"
|
||||
"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/gui"
|
||||
"github.com/g3n/engine/light"
|
||||
"github.com/g3n/engine/material"
|
||||
"github.com/g3n/engine/math32"
|
||||
"github.com/g3n/engine/renderer"
|
||||
"github.com/g3n/engine/util/helper"
|
||||
"github.com/g3n/engine/window"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
// Create application and scene
|
||||
a := app.App()
|
||||
scene := core.NewNode()
|
||||
|
||||
// Set the scene to be managed by the gui manager
|
||||
gui.Manager().Set(scene)
|
||||
|
||||
// Create perspective camera
|
||||
cam := camera.New(1)
|
||||
cam.SetPosition(0, 0, 3)
|
||||
scene.Add(cam)
|
||||
|
||||
// Set up orbit control for the camera
|
||||
camera.NewOrbitControl(cam)
|
||||
|
||||
// Set up callback to update viewport and camera aspect ratio when the window is resized
|
||||
onResize := func(evname string, ev interface{}) {
|
||||
// Get framebuffer size and update viewport accordingly
|
||||
width, height := a.GetSize()
|
||||
a.Gls().Viewport(0, 0, int32(width), int32(height))
|
||||
// Update the camera's aspect ratio
|
||||
cam.SetAspect(float32(width) / float32(height))
|
||||
}
|
||||
a.Subscribe(window.OnWindowSize, onResize)
|
||||
onResize("", nil)
|
||||
|
||||
// Create a blue torus and add it to the scene
|
||||
geom := geometry.NewTorus(1, .4, 12, 32, math32.Pi*2)
|
||||
mat := material.NewStandard(math32.NewColor("DarkBlue"))
|
||||
mesh := graphic.NewMesh(geom, mat)
|
||||
scene.Add(mesh)
|
||||
|
||||
// Create and add a button to the scene
|
||||
btn := gui.NewButton("Make Red")
|
||||
btn.SetPosition(100, 40)
|
||||
btn.SetSize(40, 40)
|
||||
btn.Subscribe(gui.OnClick, func(name string, ev interface{}) {
|
||||
mat.SetColor(math32.NewColor("DarkRed"))
|
||||
})
|
||||
scene.Add(btn)
|
||||
|
||||
// Create and add lights to the scene
|
||||
scene.Add(light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 0.8))
|
||||
pointLight := light.NewPoint(&math32.Color{1, 1, 1}, 5.0)
|
||||
pointLight.SetPosition(1, 0, 2)
|
||||
scene.Add(pointLight)
|
||||
|
||||
// Create and add an axis helper to the scene
|
||||
scene.Add(helper.NewAxes(0.5))
|
||||
|
||||
// Set background color to gray
|
||||
a.Gls().ClearColor(0.5, 0.5, 0.5, 1.0)
|
||||
|
||||
// Run the application
|
||||
a.Run(func(renderer *renderer.Renderer, deltaTime time.Duration) {
|
||||
a.Gls().Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)
|
||||
renderer.Render(scene, cam)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue