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