forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (46 loc) · 1.97 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
66
67
68
69
70
71
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
camera := rl.Camera{}
camera.Position = rl.NewVector3(16.0, 14.0, 16.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
camera.Type = rl.CameraPerspective
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
model := rl.LoadModelFromMesh(mesh)
// NOTE: By default each cube is mapped to one part of texture atlas
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
rl.UnloadImage(image) // Unload cubicmap 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.White)
rl.EndMode3D()
rl.DrawTextureEx(cubicmap, rl.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, rl.White)
rl.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, rl.Green)
rl.DrawText("cubicmap image used to", 658, 90, 10, rl.Gray)
rl.DrawText("generate map 3d model", 658, 104, 10, rl.Gray)
rl.DrawFPS(10, 10)
rl.EndDrawing()
}
rl.UnloadTexture(cubicmap) // Unload cubicmap texture
rl.UnloadTexture(texture) // Unload map texture
rl.UnloadModel(model) // Unload map model
rl.CloseWindow()
}