forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (41 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
camera := rl.Camera{}
camera.Position = rl.NewVector3(18.0, 16.0, 18.0)
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
camera.Fovy = 45.0
image := rl.LoadImage("heightmap.png") // Load heightmap image (RAM)
texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
// Update
rl.UpdateCamera(&camera) // Update camera
// Draw
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.BeginMode3D(camera)
rl.DrawModel(model, mapPosition, 1.0, rl.Red)
rl.DrawGrid(20, 1.0)
rl.EndMode3D()
rl.DrawTexture(texture, screenWidth-texture.Width-20, 20, rl.White)
rl.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, rl.Green)
rl.DrawFPS(10, 10)
rl.EndDrawing()
}
rl.UnloadTexture(texture) // Unload map texture
rl.UnloadModel(model) // Unload map model
rl.CloseWindow()
}