···11+package main
22+33+import (
44+ "time"
55+66+ "github.com/g3n/engine/app"
77+ "github.com/g3n/engine/camera"
88+ "github.com/g3n/engine/core"
99+ "github.com/g3n/engine/geometry"
1010+ "github.com/g3n/engine/gls"
1111+ "github.com/g3n/engine/graphic"
1212+ "github.com/g3n/engine/gui"
1313+ "github.com/g3n/engine/light"
1414+ "github.com/g3n/engine/material"
1515+ "github.com/g3n/engine/math32"
1616+ "github.com/g3n/engine/renderer"
1717+ "github.com/g3n/engine/util/helper"
1818+ "github.com/g3n/engine/window"
1919+)
2020+2121+func main() {
2222+ // Create the application and scene
2323+ a := app.App()
2424+ scene := core.NewNode()
2525+2626+ // Set the scene to be managed by the gui manager
2727+ gui.Manager().Set(scene)
2828+2929+ // Create perspective camera
3030+ cam := camera.New(1)
3131+ cam.SetPosition(0, 0, 3)
3232+ scene.Add(cam)
3333+3434+ // Set up orbit control for the camera
3535+ camera.NewOrbitControl(cam)
3636+3737+ // Set up callback to update viewport and camera aspect ratio when the window is resized
3838+ onResize := func(evname string, ev interface{}) {
3939+ // Get framebuffer size and update viewport accordingly
4040+ width, height := a.GetSize()
4141+ a.Gls().Viewport(0, 0, int32(width), int32(height))
4242+ // Update the camera's aspect ratio
4343+ cam.SetAspect(float32(width) / float32(height))
4444+ }
4545+4646+ a.Subscribe(window.OnWindowSize, onResize)
4747+ onResize("", nil)
4848+4949+ // Create a blue torus and add it to the scene
5050+ geom := geometry.NewTorus(1, 0.4, 12, 32, math32.Pi*2)
5151+ mat := material.NewStandard(math32.NewColor("DarkBlue"))
5252+ mesh := graphic.NewMesh(geom, mat)
5353+ scene.Add(mesh)
5454+5555+ // Create and add a button to the scene
5656+ btn := gui.NewButton("Make Red")
5757+ btn.SetPosition(100, 40)
5858+ btn.SetSize(40, 40)
5959+ btn.Subscribe(gui.OnClick, func(name string, ev interface{}) {
6060+ mat.SetColor(math32.NewColor("DarkRed"))
6161+ })
6262+ scene.Add(btn)
6363+6464+ // Create and add lights to the scene
6565+ scene.Add(light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 0.8))
6666+ pointLight := light.NewPoint(&math32.Color{1, 1, 1}, 5.0)
6767+ pointLight.SetPosition(1, 0, 2)
6868+ scene.Add(pointLight)
6969+7070+ // Create and add an axis helper to the scene
7171+ scene.Add(helper.NewAxes(0.5))
7272+7373+ // Set background color to gray
7474+ a.Gls().ClearColor(0.5, 0.5, 0.5, 1.0)
7575+7676+ // Run the application
7777+ a.Run(func(renderer *renderer.Renderer, deltaTime time.Duration) {
7878+ a.Gls().Clear(gls.DEPTH_BUFFER_BIT | gls.STENCIL_BUFFER_BIT | gls.COLOR_BUFFER_BIT)
7979+ renderer.Render(scene, cam)
8080+ })
8181+}