···11+MIT License
22+33+Copyright (c) 2024 skeetcha
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
···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-}