forked from gen2brain/raylib-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (46 loc) · 1.83 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
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
// Load RAW image data (384x512, 32bit RGBA, no file header)
fudesumiRaw := rl.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, rl.UncompressedR8g8b8a8, 0)
fudesumi := rl.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
rl.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
// Generate a checked texture by code (1024x1024 pixels)
width := 1024
height := 1024
// Dynamic memory allocation to store pixels data (Color type)
pixels := make([]rl.Color, width*height)
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
if ((x/32+y/32)/1)%2 == 0 {
pixels[y*height+x] = rl.Orange
} else {
pixels[y*height+x] = rl.Gold
}
}
}
// Load pixels data into an image structure and create texture
checkedIm := rl.LoadImageEx(pixels, int32(width), int32(height))
checked := rl.LoadTextureFromImage(checkedIm)
rl.UnloadImage(checkedIm) // Unload CPU (RAM) image data
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, rl.Fade(rl.White, 0.5))
rl.DrawTexture(fudesumi, 430, -30, rl.White)
rl.DrawText("CHECKED TEXTURE ", 84, 100, 30, rl.Brown)
rl.DrawText("GENERATED by CODE", 72, 164, 30, rl.Brown)
rl.DrawText("and RAW IMAGE LOADING", 46, 226, 30, rl.Brown)
rl.EndDrawing()
}
rl.UnloadTexture(fudesumi) // Texture unloading
rl.UnloadTexture(checked) // Texture unloading
rl.CloseWindow()
}