forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
94 lines (76 loc) · 2.66 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
const numTextures = 7
func main() {
screenWidth := 800
screenHeight := 450
rl.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
verticalGradient := rl.GenImageGradientV(screenWidth, screenHeight, rl.Red, rl.Blue)
horizontalGradient := rl.GenImageGradientH(screenWidth, screenHeight, rl.Red, rl.Blue)
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
perlinNoise := rl.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
cellular := rl.GenImageCellular(screenWidth, screenHeight, 32)
textures := make([]rl.Texture2D, numTextures)
textures[0] = rl.LoadTextureFromImage(verticalGradient)
textures[1] = rl.LoadTextureFromImage(horizontalGradient)
textures[2] = rl.LoadTextureFromImage(radialGradient)
textures[3] = rl.LoadTextureFromImage(checked)
textures[4] = rl.LoadTextureFromImage(whiteNoise)
textures[5] = rl.LoadTextureFromImage(perlinNoise)
textures[6] = rl.LoadTextureFromImage(cellular)
// Unload image data (CPU RAM)
rl.UnloadImage(verticalGradient)
rl.UnloadImage(horizontalGradient)
rl.UnloadImage(radialGradient)
rl.UnloadImage(checked)
rl.UnloadImage(whiteNoise)
rl.UnloadImage(perlinNoise)
rl.UnloadImage(cellular)
currentTexture := 0
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawTexture(textures[currentTexture], 0, 0, rl.White)
rl.DrawRectangle(30, 400, 325, 30, rl.Fade(rl.SkyBlue, 0.5))
rl.DrawRectangleLines(30, 400, 325, 30, rl.Fade(rl.White, 0.5))
rl.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, rl.White)
switch currentTexture {
case 0:
rl.DrawText("VERTICAL GRADIENT", 560, 10, 20, rl.RayWhite)
break
case 1:
rl.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, rl.RayWhite)
break
case 2:
rl.DrawText("RADIAL GRADIENT", 580, 10, 20, rl.LightGray)
break
case 3:
rl.DrawText("CHECKED", 680, 10, 20, rl.RayWhite)
break
case 4:
rl.DrawText("WHITE NOISE", 640, 10, 20, rl.Red)
break
case 5:
rl.DrawText("PERLIN NOISE", 630, 10, 20, rl.RayWhite)
break
case 6:
rl.DrawText("CELLULAR", 670, 10, 20, rl.RayWhite)
break
default:
break
}
rl.EndDrawing()
}
for _, t := range textures {
rl.UnloadTexture(t)
}
rl.CloseWindow()
}