func main() { runtime.LockOSThread() settings := three.WindowSettings{ Width: width, Height: height, Title: "Example - Text", Fullscreen: false, ClearColor: &three.Color{0., 0., 0.4}, } window, err := three.NewWindow(settings) if err != nil { log.Fatal(err) } renderer, err := three.NewRenderer(window) if err != nil { log.Fatal(err) } scene := three.NewScene() camera := three.NewPerspectiveCamera(fov, width/height, near, far) var size float32 = 15 var offset float32 = 50.0 for i := 0; i < 16; i++ { white := three.NewBasicMaterial() white.SetColor(&three.Color{1.0, 1.0, 1.0}) regular, err := three.NewFont("../_fonts/Inconsolata-Regular.ttf", int32(15+i)) if err != nil { log.Fatal(err) } titleGeometry := three.NewTextGeometry("Grumpy wizards", mgl32.Vec2{10, offset}, size, regular) title := three.NewText(titleGeometry, white) scene.AddText(title) offset += size + 5 size += 2 } camera.Transform.SetPosition(20, 20, 20) camera.Transform.LookAt(0, 0, 0) for !window.ShouldClose() { renderer.Render(scene, camera) } renderer.Unload(scene) renderer.OpenGLSentinel() }
func main() { runtime.LockOSThread() settings := three.WindowSettings{ Width: width, Height: height, Title: "Example - Wireframe Cube", Fullscreen: false, ClearColor: &three.Color{0., 0., 0.4}, } window, err := three.NewWindow(settings) if err != nil { log.Fatal(err) } renderer, err := three.NewRenderer(window) if err != nil { log.Fatal(err) } scene := three.NewScene() camera := three.NewPerspectiveCamera(fov, width/height, near, far) camera.Transform.SetPosition(4.0, 3.0, 4.0) camera.Transform.LookAt(0, 0, 0) box := geometries.NewCube(1) red := three.NewBasicMaterial() red.SetColor(&three.Color{1.0, 0.0, 0.0}) red.SetWireframe(true) mesh := three.NewMesh(box, red) scene.Add(mesh) var rotX float32 = 0.01 var rotY float32 = 0.02 transform := mesh.Transform() for !window.ShouldClose() { transform.RotateX(rotX) transform.RotateY(rotY) renderer.Render(scene, camera) } renderer.Unload(scene) renderer.OpenGLSentinel() }
func main() { runtime.LockOSThread() settings := three.WindowSettings{ Width: width, Height: height, Title: "Example - Textured Cube", Fullscreen: false, } window, err := three.NewWindow(settings) if err != nil { log.Fatal(err) } renderer, err := three.NewRenderer(window) if err != nil { log.Fatal(err) } scene := three.NewScene() camera := three.NewPerspectiveCamera(fov, width/height, near, far) camera.Transform.TranslateZ(1000) box := geometries.NewCube(200) texture := three.NewBasicMaterial() t, err := three.NewTexture("textures/uvgrid01.dds") if err != nil { log.Panic(err) } texture.SetTexture(t) mesh := three.NewMesh(box, texture) scene.Add(mesh) transform := mesh.Transform() for !window.ShouldClose() { transform.RotateX(0.01) transform.RotateY(0.02) renderer.Render(scene, camera) } renderer.Unload(scene) renderer.OpenGLSentinel() }
func main() { runtime.LockOSThread() settings := three.WindowSettings{ Width: width, Height: height, Title: "Example - Obj Loading", Fullscreen: false, ClearColor: &three.Color{0., 0., 0.4}, } window, err := three.NewWindow(settings) if err != nil { log.Fatal(err) } renderer, err := three.NewRenderer(window) if err != nil { log.Fatal(err) } scene := three.NewScene() camera := three.NewPerspectiveCamera(fov, width/height, near, far) camera.Transform.SetPosition(0, 0, 5.0) box, err := loaders.LoadFromObj("obj/suzanne.obj") if err != nil { log.Fatal(err) } grey := three.NewBasicMaterial() grey.SetColor(&three.Color{0.5, 0.5, 0.5}) helpers.AddAxes(scene) mesh := three.NewMesh(box, grey) white := three.NewBasicMaterial() white.SetColor(&three.Color{1.0, 1.0, 1.0}) regular, err := three.NewFont("../_fonts/Inconsolata-Regular.ttf", int32(25)) if err != nil { log.Fatal(err) } fpsGeometry := three.NewTextGeometry(" ", mgl32.Vec2{50, 50}, 25, regular) fps := three.NewText(fpsGeometry, white) scene.AddText(fps) scene.Add(mesh) transform := mesh.Transform() lastTime := three.GetTime() nbFrames := 0 for !window.ShouldClose() { currTime := three.GetTime() nbFrames++ if currTime-lastTime >= 1.0 { frames := fmt.Sprintf("%v FPS", nbFrames) fps.SetText(frames) nbFrames = 0 lastTime += 1.0 } transform.RotateX(0.01) transform.RotateY(0.02) renderer.Render(scene, camera) } renderer.Unload(scene) renderer.OpenGLSentinel() }