Initial commit
219
examples/textures/formats_loading/main.go
Normal file
|
@ -0,0 +1,219 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const NumTextures = 24
|
||||
|
||||
const (
|
||||
PNG_R8G8B8A8 = iota
|
||||
PVR_GRAYSCALE
|
||||
PVR_GRAY_ALPHA
|
||||
PVR_R5G6B5
|
||||
PVR_R5G5B5A1
|
||||
PVR_R4G4B4A4
|
||||
DDS_R5G6B5
|
||||
DDS_R5G5B5A1
|
||||
DDS_R4G4B4A4
|
||||
DDS_R8G8B8A8
|
||||
DDS_DXT1_RGB
|
||||
DDS_DXT1_RGBA
|
||||
DDS_DXT3_RGBA
|
||||
DDS_DXT5_RGBA
|
||||
PKM_ETC1_RGB
|
||||
PKM_ETC2_RGB
|
||||
PKM_ETC2_EAC_RGBA
|
||||
KTX_ETC1_RGB
|
||||
KTX_ETC2_RGB
|
||||
KTX_ETC2_EAC_RGBA
|
||||
ASTC_4x4_LDR
|
||||
ASTC_8x8_LDR
|
||||
PVR_PVRT_RGB
|
||||
PVR_PVRT_RGBA
|
||||
)
|
||||
|
||||
var formatText = []string{
|
||||
"PNG_R8G8B8A8",
|
||||
"PVR_GRAYSCALE",
|
||||
"PVR_GRAY_ALPHA",
|
||||
"PVR_R5G6B5",
|
||||
"PVR_R5G5B5A1",
|
||||
"PVR_R4G4B4A4",
|
||||
"DDS_R5G6B5",
|
||||
"DDS_R5G5B5A1",
|
||||
"DDS_R4G4B4A4",
|
||||
"DDS_R8G8B8A8",
|
||||
"DDS_DXT1_RGB",
|
||||
"DDS_DXT1_RGBA",
|
||||
"DDS_DXT3_RGBA",
|
||||
"DDS_DXT5_RGBA",
|
||||
"PKM_ETC1_RGB",
|
||||
"PKM_ETC2_RGB",
|
||||
"PKM_ETC2_EAC_RGBA",
|
||||
"KTX_ETC1_RGB",
|
||||
"KTX_ETC2_RGB",
|
||||
"KTX_ETC2_EAC_RGBA",
|
||||
"ASTC_4x4_LDR",
|
||||
"ASTC_8x8_LDR",
|
||||
"PVR_PVRT_RGB",
|
||||
"PVR_PVRT_RGBA",
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
sonic := make([]raylib.Texture2D, NumTextures)
|
||||
|
||||
sonic[PNG_R8G8B8A8] = raylib.LoadTexture("texture_formats/sonic.png")
|
||||
|
||||
// Load UNCOMPRESSED PVR texture data
|
||||
sonic[PVR_GRAYSCALE] = raylib.LoadTexture("texture_formats/sonic_GRAYSCALE.pvr")
|
||||
sonic[PVR_GRAY_ALPHA] = raylib.LoadTexture("texture_formats/sonic_L8A8.pvr")
|
||||
sonic[PVR_R5G6B5] = raylib.LoadTexture("texture_formats/sonic_R5G6B5.pvr")
|
||||
sonic[PVR_R5G5B5A1] = raylib.LoadTexture("texture_formats/sonic_R5G5B5A1.pvr")
|
||||
sonic[PVR_R4G4B4A4] = raylib.LoadTexture("texture_formats/sonic_R4G4B4A4.pvr")
|
||||
|
||||
// Load UNCOMPRESSED DDS texture data
|
||||
sonic[DDS_R5G6B5] = raylib.LoadTexture("texture_formats/sonic_R5G6B5.dds")
|
||||
sonic[DDS_R5G5B5A1] = raylib.LoadTexture("texture_formats/sonic_A1R5G5B5.dds")
|
||||
sonic[DDS_R4G4B4A4] = raylib.LoadTexture("texture_formats/sonic_A4R4G4B4.dds")
|
||||
sonic[DDS_R8G8B8A8] = raylib.LoadTexture("texture_formats/sonic_A8R8G8B8.dds")
|
||||
|
||||
// Load COMPRESSED DXT DDS texture data (if supported)
|
||||
sonic[DDS_DXT1_RGB] = raylib.LoadTexture("texture_formats/sonic_DXT1_RGB.dds")
|
||||
sonic[DDS_DXT1_RGBA] = raylib.LoadTexture("texture_formats/sonic_DXT1_RGBA.dds")
|
||||
sonic[DDS_DXT3_RGBA] = raylib.LoadTexture("texture_formats/sonic_DXT3_RGBA.dds")
|
||||
sonic[DDS_DXT5_RGBA] = raylib.LoadTexture("texture_formats/sonic_DXT5_RGBA.dds")
|
||||
|
||||
// Load COMPRESSED ETC texture data (if supported)
|
||||
sonic[PKM_ETC1_RGB] = raylib.LoadTexture("texture_formats/sonic_ETC1_RGB.pkm")
|
||||
sonic[PKM_ETC2_RGB] = raylib.LoadTexture("texture_formats/sonic_ETC2_RGB.pkm")
|
||||
sonic[PKM_ETC2_EAC_RGBA] = raylib.LoadTexture("texture_formats/sonic_ETC2_EAC_RGBA.pkm")
|
||||
|
||||
sonic[KTX_ETC1_RGB] = raylib.LoadTexture("texture_formats/sonic_ETC1_RGB.ktx")
|
||||
sonic[KTX_ETC2_RGB] = raylib.LoadTexture("texture_formats/sonic_ETC2_RGB.ktx")
|
||||
sonic[KTX_ETC2_EAC_RGBA] = raylib.LoadTexture("texture_formats/sonic_ETC2_EAC_RGBA.ktx")
|
||||
|
||||
// Load COMPRESSED ASTC texture data (if supported)
|
||||
sonic[ASTC_4x4_LDR] = raylib.LoadTexture("texture_formats/sonic_ASTC_4x4_ldr.astc")
|
||||
sonic[ASTC_8x8_LDR] = raylib.LoadTexture("texture_formats/sonic_ASTC_8x8_ldr.astc")
|
||||
|
||||
// Load COMPRESSED PVR texture data (if supported)
|
||||
sonic[PVR_PVRT_RGB] = raylib.LoadTexture("texture_formats/sonic_PVRT_RGB.pvr")
|
||||
sonic[PVR_PVRT_RGBA] = raylib.LoadTexture("texture_formats/sonic_PVRT_RGBA.pvr")
|
||||
|
||||
selectedFormat := PNG_R8G8B8A8
|
||||
|
||||
selectRecs := make([]raylib.Rectangle, NumTextures)
|
||||
|
||||
for i := 0; i < NumTextures; i++ {
|
||||
if i < NumTextures/2 {
|
||||
selectRecs[i] = raylib.NewRectangle(40, int32(30+32*i), 150, 30)
|
||||
} else {
|
||||
selectRecs[i] = raylib.NewRectangle(40+152, int32(30+32*(i-NumTextures/2)), 150, 30)
|
||||
}
|
||||
}
|
||||
|
||||
// Texture sizes in KB
|
||||
var textureSizes = [NumTextures]int{
|
||||
512 * 512 * 32 / 8 / 1024, //PNG_R8G8B8A8 (32 bpp)
|
||||
512 * 512 * 8 / 8 / 1024, //PVR_GRAYSCALE (8 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_GRAY_ALPHA (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R5G6B5 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R5G5B5A1 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //PVR_R4G4B4A4 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R5G6B5 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R5G5B5A1 (16 bpp)
|
||||
512 * 512 * 16 / 8 / 1024, //DDS_R4G4B4A4 (16 bpp)
|
||||
512 * 512 * 32 / 8 / 1024, //DDS_R8G8B8A8 (32 bpp)
|
||||
512 * 512 * 4 / 8 / 1024, //DDS_DXT1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //DDS_DXT1_RGBA (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //DDS_DXT3_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //DDS_DXT5_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PKM_ETC1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PKM_ETC2_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //PKM_ETC2_EAC_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //KTX_ETC1_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //KTX_ETC2_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //KTX_ETC2_EAC_RGBA (8 bpp) -Compressed-
|
||||
512 * 512 * 8 / 8 / 1024, //ASTC_4x4_LDR (8 bpp) -Compressed-
|
||||
512 * 512 * 2 / 8 / 1024, //ASTC_8x8_LDR (2 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PVR_PVRT_RGB (4 bpp) -Compressed-
|
||||
512 * 512 * 4 / 8 / 1024, //PVR_PVRT_RGBA (4 bpp) -Compressed-
|
||||
}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeyDown) {
|
||||
selectedFormat++
|
||||
if selectedFormat >= NumTextures {
|
||||
selectedFormat = 0
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyUp) {
|
||||
selectedFormat--
|
||||
if selectedFormat < 0 {
|
||||
selectedFormat = NumTextures - 1
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
if selectedFormat < NumTextures/2 {
|
||||
selectedFormat += NumTextures / 2
|
||||
}
|
||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
||||
if selectedFormat >= NumTextures/2 {
|
||||
selectedFormat -= NumTextures / 2
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
// Draw rectangles
|
||||
for i := 0; i < NumTextures; i++ {
|
||||
if i == selectedFormat {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Blue)
|
||||
raylib.DrawText(formatText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(formatText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkBlue)
|
||||
} else {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Gray)
|
||||
raylib.DrawText(formatText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(formatText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkGray)
|
||||
}
|
||||
}
|
||||
|
||||
// Draw selected texture
|
||||
if sonic[selectedFormat].Id != 0 {
|
||||
raylib.DrawTexture(sonic[selectedFormat], 350, -10, raylib.White)
|
||||
} else {
|
||||
raylib.DrawRectangleLines(488, 165, 200, 110, raylib.DarkGray)
|
||||
raylib.DrawText("FORMAT", 550, 180, 20, raylib.Maroon)
|
||||
raylib.DrawText("NOT SUPPORTED", 500, 210, 20, raylib.Maroon)
|
||||
raylib.DrawText("ON YOUR GPU", 520, 240, 20, raylib.Maroon)
|
||||
}
|
||||
|
||||
raylib.DrawText("Select texture format (use cursor keys):", 40, 10, 10, raylib.DarkGray)
|
||||
raylib.DrawText("Required GPU memory size (VRAM):", 40, 427, 10, raylib.DarkGray)
|
||||
raylib.DrawText(fmt.Sprintf("%4.0d KB", textureSizes[selectedFormat]), 240, 420, 20, raylib.DarkBlue)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
for i := 0; i < NumTextures; i++ {
|
||||
raylib.UnloadTexture(sonic[i])
|
||||
}
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/formats_loading/texture_formats/sonic.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
examples/textures/formats_loading/texture_formats/sonic_L8A8.pvr
Normal file
BIN
examples/textures/image_drawing/cat.png
Normal file
After Width: | Height: | Size: 379 KiB |
49
examples/textures/image_drawing/main.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
cat := raylib.LoadImage("cat.png") // Load image in CPU memory (RAM)
|
||||
raylib.ImageCrop(cat, raylib.NewRectangle(100, 10, 280, 380)) // Crop an image piece
|
||||
raylib.ImageFlipHorizontal(cat) // Flip cropped image horizontally
|
||||
raylib.ImageResize(cat, 150, 200) // Resize flipped-cropped image
|
||||
|
||||
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||
|
||||
// Draw one image over the other with a scaling of 1.5f
|
||||
raylib.ImageDraw(parrots, cat, raylib.NewRectangle(0, 0, cat.Width, cat.Height), raylib.NewRectangle(30, 40, int32(float32(cat.Width)*1.5), int32(float32(cat.Height)*1.5)))
|
||||
raylib.ImageCrop(parrots, raylib.NewRectangle(0, 50, parrots.Width, parrots.Height-100)) // Crop resulting image
|
||||
|
||||
raylib.UnloadImage(cat) // Unload image from RAM
|
||||
|
||||
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
raylib.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, raylib.DarkGray)
|
||||
|
||||
raylib.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, raylib.DarkGray)
|
||||
raylib.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, raylib.DarkGray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/image_drawing/parrots.png
Normal file
After Width: | Height: | Size: 288 KiB |
37
examples/textures/image_loading/main.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
image := raylib.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
raylib.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
|
||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/image_loading/raylib_logo.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
134
examples/textures/image_processing/main.go
Normal file
|
@ -0,0 +1,134 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const NumProcesses = 8
|
||||
|
||||
const (
|
||||
None = iota
|
||||
ColorGrayscale
|
||||
ColorTint
|
||||
ColorInvert
|
||||
ColorContrast
|
||||
ColorBrightness
|
||||
FlipVertical
|
||||
FlipHorizontal
|
||||
)
|
||||
|
||||
var processText = []string{
|
||||
"NO PROCESSING",
|
||||
"COLOR GRAYSCALE",
|
||||
"COLOR TINT",
|
||||
"COLOR INVERT",
|
||||
"COLOR CONTRAST",
|
||||
"COLOR BRIGHTNESS",
|
||||
"FLIP VERTICAL",
|
||||
"FLIP HORIZONTAL",
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
|
||||
|
||||
image := raylib.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
|
||||
raylib.ImageFormat(image, int32(raylib.UncompressedR8g8b8a8)) // Format image to RGBA 32bit (required for texture update)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
currentProcess := None
|
||||
textureReload := false
|
||||
|
||||
selectRecs := make([]raylib.Rectangle, NumProcesses)
|
||||
|
||||
for i := int32(0); i < NumProcesses; i++ {
|
||||
selectRecs[i] = raylib.NewRectangle(40, 50+32*i, 150, 30)
|
||||
}
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyDown) {
|
||||
currentProcess++
|
||||
if currentProcess > 7 {
|
||||
currentProcess = 0
|
||||
}
|
||||
textureReload = true
|
||||
} else if raylib.IsKeyPressed(raylib.KeyUp) {
|
||||
currentProcess--
|
||||
if currentProcess < 0 {
|
||||
currentProcess = 7
|
||||
}
|
||||
textureReload = true
|
||||
}
|
||||
|
||||
if textureReload {
|
||||
raylib.UnloadImage(image) // Unload current image data
|
||||
image = raylib.LoadImage("parrots.png") // Re-load image data
|
||||
|
||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
||||
// If image processing is required in a frame-basis, it should be done
|
||||
// with a texture and by shaders
|
||||
switch currentProcess {
|
||||
case ColorGrayscale:
|
||||
raylib.ImageColorGrayscale(image)
|
||||
break
|
||||
case ColorTint:
|
||||
raylib.ImageColorTint(image, raylib.Green)
|
||||
break
|
||||
case ColorInvert:
|
||||
raylib.ImageColorInvert(image)
|
||||
break
|
||||
case ColorContrast:
|
||||
raylib.ImageColorContrast(image, -40)
|
||||
break
|
||||
case ColorBrightness:
|
||||
raylib.ImageColorBrightness(image, -80)
|
||||
break
|
||||
case FlipVertical:
|
||||
raylib.ImageFlipVertical(image)
|
||||
break
|
||||
case FlipHorizontal:
|
||||
raylib.ImageFlipHorizontal(image)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
pixels := raylib.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
||||
raylib.UpdateTexture(texture, pixels) // Update texture with new image data
|
||||
|
||||
textureReload = false
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawText("IMAGE PROCESSING:", 40, 30, 10, raylib.DarkGray)
|
||||
|
||||
// Draw rectangles
|
||||
for i := 0; i < NumProcesses; i++ {
|
||||
if i == currentProcess {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Blue)
|
||||
raylib.DrawText(processText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(processText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkBlue)
|
||||
} else {
|
||||
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
|
||||
raylib.DrawRectangleLines(selectRecs[i].X, selectRecs[i].Y, selectRecs[i].Width, selectRecs[i].Height, raylib.Gray)
|
||||
raylib.DrawText(processText[i], selectRecs[i].X+selectRecs[i].Width/2-raylib.MeasureText(processText[i], 10)/2, selectRecs[i].Y+11, 10, raylib.DarkGray)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, raylib.Black)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/image_processing/parrots.png
Normal file
After Width: | Height: | Size: 288 KiB |
31
examples/textures/logo_raylib/main.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
texture := raylib.LoadTexture("raylib_logo.png")
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("this IS a texture!", 360, 370, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/logo_raylib/raylib_logo.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
123
examples/textures/particles_trail_blending/main.go
Normal file
|
@ -0,0 +1,123 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
MaxParticles = 200
|
||||
)
|
||||
|
||||
type Particle struct {
|
||||
Position raylib.Vector2
|
||||
Color raylib.Color
|
||||
Alpha float32
|
||||
Size float32
|
||||
Rotation float32
|
||||
Active bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending")
|
||||
|
||||
// Particles pool, reuse them!
|
||||
mouseTail := make([]Particle, MaxParticles)
|
||||
|
||||
// Initialize particles
|
||||
for i := 0; i < MaxParticles; i++ {
|
||||
mouseTail[i].Position = raylib.NewVector2(0, 0)
|
||||
mouseTail[i].Color = raylib.NewColor(byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), byte(raylib.GetRandomValue(0, 255)), 255)
|
||||
mouseTail[i].Alpha = 1.0
|
||||
mouseTail[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
|
||||
mouseTail[i].Rotation = float32(raylib.GetRandomValue(0, 360))
|
||||
mouseTail[i].Active = false
|
||||
}
|
||||
|
||||
gravity := float32(3.0)
|
||||
|
||||
smoke := raylib.LoadTexture("smoke.png")
|
||||
|
||||
blending := raylib.BlendAlpha
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
|
||||
// Activate one particle every frame and Update active particles
|
||||
// NOTE: Particles initial position should be mouse position when activated
|
||||
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
|
||||
// NOTE: When a particle disappears, active = false and it can be reused.
|
||||
for i := 0; i < MaxParticles; i++ {
|
||||
if !mouseTail[i].Active {
|
||||
mouseTail[i].Active = true
|
||||
mouseTail[i].Alpha = 1.0
|
||||
mouseTail[i].Position = raylib.GetMousePosition()
|
||||
i = MaxParticles
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < MaxParticles; i++ {
|
||||
if mouseTail[i].Active {
|
||||
mouseTail[i].Position.Y += gravity
|
||||
mouseTail[i].Alpha -= 0.01
|
||||
|
||||
if mouseTail[i].Alpha <= 0.0 {
|
||||
mouseTail[i].Active = false
|
||||
}
|
||||
|
||||
mouseTail[i].Rotation += 5.0
|
||||
}
|
||||
}
|
||||
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
if blending == raylib.BlendAlpha {
|
||||
blending = raylib.BlendAdditive
|
||||
} else {
|
||||
blending = raylib.BlendAlpha
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.DarkGray)
|
||||
|
||||
raylib.BeginBlendMode(blending)
|
||||
|
||||
// Draw active particles
|
||||
for i := 0; i < MaxParticles; i++ {
|
||||
if mouseTail[i].Active {
|
||||
raylib.DrawTexturePro(
|
||||
smoke,
|
||||
raylib.NewRectangle(0, 0, smoke.Width, smoke.Height),
|
||||
raylib.NewRectangle(int32(mouseTail[i].Position.X), int32(mouseTail[i].Position.Y), smoke.Width*int32(mouseTail[i].Size), smoke.Height*int32(mouseTail[i].Size)),
|
||||
raylib.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
|
||||
mouseTail[i].Rotation,
|
||||
raylib.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
raylib.EndBlendMode()
|
||||
|
||||
raylib.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, raylib.Black)
|
||||
|
||||
if blending == raylib.BlendAlpha {
|
||||
raylib.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, raylib.Black)
|
||||
} else {
|
||||
raylib.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, raylib.RayWhite)
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(smoke)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/particles_trail_blending/smoke.png
Normal file
After Width: | Height: | Size: 15 KiB |
66
examples/textures/raw_data/main.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.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 (512x512, 32bit RGBA, no file header)
|
||||
sonicRaw := raylib.LoadImageRaw("texture_formats/sonic_R8G8B8A8.raw", 512, 512, raylib.UncompressedR8g8b8a8, 0)
|
||||
sonic := raylib.LoadTextureFromImage(sonicRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||
raylib.UnloadImage(sonicRaw) // 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([]raylib.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] = raylib.DarkBlue
|
||||
} else {
|
||||
pixels[y*height+x] = raylib.SkyBlue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load pixels data into an image structure and create texture
|
||||
checkedIm := raylib.LoadImageEx(pixels, int32(width), int32(height))
|
||||
checked := raylib.LoadTextureFromImage(checkedIm)
|
||||
raylib.UnloadImage(checkedIm) // Unload CPU (RAM) image data
|
||||
|
||||
// Dynamic memory must be freed after using it
|
||||
pixels = nil // Unload CPU (RAM) pixels data
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, raylib.Fade(raylib.White, 0.3))
|
||||
raylib.DrawTexture(sonic, 330, -20, raylib.White)
|
||||
|
||||
raylib.DrawText("CHECKED TEXTURE ", 84, 100, 30, raylib.DarkBlue)
|
||||
raylib.DrawText("GENERATED by CODE", 72, 164, 30, raylib.DarkBlue)
|
||||
raylib.DrawText("and RAW IMAGE LOADING", 46, 226, 30, raylib.DarkBlue)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(sonic) // Texture unloading
|
||||
raylib.UnloadTexture(checked) // Texture unloading
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/raw_data/texture_formats/sonic_R8G8B8A8.raw
Normal file
BIN
examples/textures/rectangle/guybrush.png
Normal file
After Width: | Height: | Size: 83 KiB |
57
examples/textures/rectangle/main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
guybrush := raylib.LoadTexture("guybrush.png") // Texture loading
|
||||
|
||||
position := raylib.NewVector2(350.0, 240.0)
|
||||
frameRec := raylib.NewRectangle(0, 0, guybrush.Width/7, guybrush.Height)
|
||||
currentFrame := int32(0)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
||||
currentFrame++
|
||||
|
||||
if currentFrame > 6 {
|
||||
currentFrame = 0
|
||||
}
|
||||
|
||||
frameRec.X = currentFrame * guybrush.Width / 7
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(guybrush, 35, 40, raylib.White)
|
||||
raylib.DrawRectangleLines(35, 40, guybrush.Width, guybrush.Height, raylib.Lime)
|
||||
|
||||
raylib.DrawTextureRec(guybrush, frameRec, position, raylib.White) // Draw part of the texture
|
||||
|
||||
raylib.DrawRectangleLines(35+frameRec.X, 40+frameRec.Y, frameRec.Width, frameRec.Height, raylib.Red)
|
||||
|
||||
raylib.DrawText("PRESS RIGHT KEY TO", 540, 310, 10, raylib.Gray)
|
||||
raylib.DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, raylib.Gray)
|
||||
|
||||
raylib.DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, raylib.Gray)
|
||||
raylib.DrawText("main character of the Monkey Island series", 80, 320, 10, raylib.Gray)
|
||||
raylib.DrawText("of computer adventure games by LucasArts.", 80, 340, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(guybrush)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/srcrec_dstrec/guybrush.png
Normal file
After Width: | Height: | Size: 83 KiB |
57
examples/textures/srcrec_dstrec/main.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
||||
|
||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
guybrush := raylib.LoadTexture("guybrush.png") // Texture loading
|
||||
|
||||
frameWidth := guybrush.Width / 7
|
||||
frameHeight := guybrush.Height
|
||||
|
||||
// NOTE: Source rectangle (part of the texture to use for drawing)
|
||||
sourceRec := raylib.NewRectangle(0, 0, int32(frameWidth), int32(frameHeight))
|
||||
|
||||
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
|
||||
destRec := raylib.NewRectangle(screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2)
|
||||
|
||||
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
|
||||
origin := raylib.NewVector2(float32(frameWidth), float32(frameHeight))
|
||||
|
||||
rotation := float32(0)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
// Update
|
||||
rotation++
|
||||
|
||||
// Draw
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
|
||||
// sourceRec defines the part of the texture we use for drawing
|
||||
// destRec defines the rectangle where our texture part will fit (scaling it to fit)
|
||||
// origin defines the point of the texture used as reference for rotation and scaling
|
||||
// rotation defines the texture rotation (using origin as rotation point)
|
||||
raylib.DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, raylib.White)
|
||||
|
||||
raylib.DrawLine(destRec.X, 0, destRec.X, screenHeight, raylib.Gray)
|
||||
raylib.DrawLine(0, destRec.Y, screenWidth, destRec.Y, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(guybrush)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
39
examples/textures/to_image/main.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
|
||||
|
||||
image := raylib.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
|
||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
raylib.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
||||
|
||||
image = raylib.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
raylib.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
||||
|
||||
texture = raylib.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
raylib.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadTexture(texture)
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
BIN
examples/textures/to_image/raylib_logo.png
Normal file
After Width: | Height: | Size: 3.7 KiB |