add more textures examples

This commit is contained in:
unkl nik 2023-10-20 22:01:45 +02:00
parent 6f0f7a0d03
commit 0dda56d08d
8 changed files with 149 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -0,0 +1,67 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
var (
screenW = int32(1280)
screenH = int32(500)
)
func main() {
rl.InitWindow(screenW, screenH, "raylib [textures] example - background scrolling")
background := rl.LoadTexture("cyberpunk_street_background.png")
midground := rl.LoadTexture("cyberpunk_street_midground.png")
foreground := rl.LoadTexture("cyberpunk_street_foreground.png")
scrollBack := float32(0)
scrollMid := float32(0)
scrollFore := float32(0)
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
scrollBack -= 0.1
scrollMid -= 0.5
scrollFore -= 1
if scrollBack <= -float32(background.Width)*2 {
scrollBack = 0
}
if scrollMid <= -float32(midground.Width)*2 {
scrollMid = 0
}
if scrollFore <= -float32(foreground.Width)*2 {
scrollFore = 0
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawTextureEx(background, rl.NewVector2(scrollBack, 20), 0, 2, rl.White)
rl.DrawTextureEx(background, rl.NewVector2(float32(background.Width*2)+scrollBack, 20), 0, 2, rl.White)
rl.DrawTextureEx(midground, rl.NewVector2(scrollMid, 20), 0, 2, rl.White)
rl.DrawTextureEx(midground, rl.NewVector2(float32(midground.Width*2)+scrollMid, 20), 0, 2, rl.White)
rl.DrawTextureEx(foreground, rl.NewVector2(scrollFore, 20), 0, 2, rl.White)
rl.DrawTextureEx(foreground, rl.NewVector2(float32(foreground.Width*2)+scrollFore, 20), 0, 2, rl.White)
txt := "BACKGROUND SCROLLING & PARALLAX"
txtlen := rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-50, 20, rl.Black)
txt = "(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)"
txtlen = rl.MeasureText(txt, 10)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-25, 10, rl.Black)
rl.EndDrawing()
}
rl.CloseWindow()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,81 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
)
var (
screenW = int32(1280)
screenH = int32(720)
blendCountMax = 4
blendMode = 0
)
func main() {
rl.InitWindow(screenW, screenH, "raylib [textures] example - blend modes")
bgImg := rl.LoadImage("cyberpunk_street_background.png")
bgTex := rl.LoadTextureFromImage(bgImg)
fgImg := rl.LoadImage("cyberpunk_street_foreground.png")
fgTex := rl.LoadTextureFromImage(fgImg)
rl.UnloadImage(bgImg)
rl.UnloadImage(fgImg)
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
if rl.IsKeyPressed(rl.KeySpace) {
if blendMode >= blendCountMax-1 {
blendMode = 0
} else {
blendMode++
}
}
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawTexture(bgTex, screenW/2-bgTex.Width/2, screenH/2-bgTex.Height/2, rl.White)
rl.BeginBlendMode(rl.BlendMode(blendMode))
rl.DrawTexture(fgTex, screenW/2-fgTex.Width/2, screenH/2-fgTex.Height/2, rl.White)
rl.EndBlendMode()
txt := "Press SPACE to change blend modes"
txtlen := rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-70, 20, rl.Black)
switch rl.BlendMode(blendMode) {
case rl.BlendAlpha:
txt = "Current rl.BlendAlpha"
txtlen = rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-50, 20, rl.Black)
case rl.BlendAdditive:
txt = "Current rl.BlendAdditive"
txtlen = rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-50, 20, rl.Black)
case rl.BlendMultiplied:
txt = "Current rl.BlendMultiplied"
txtlen = rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-50, 20, rl.Black)
case rl.BlendAddColors:
txt = "Current rl.BlendAddColors"
txtlen = rl.MeasureText(txt, 20)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-50, 20, rl.Black)
}
txt = "(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)"
txtlen = rl.MeasureText(txt, 10)
rl.DrawText(txt, (screenW/2)-txtlen/2, screenH-25, 10, rl.Black)
rl.EndDrawing()
}
rl.UnloadTexture(fgTex)
rl.UnloadTexture(bgTex)
rl.CloseWindow()
}

View file

@ -12,7 +12,7 @@ func main() {
screenWidth := int32(1280)
screenHeight := int32(720)
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - sprite explosion")
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion")
rl.InitAudioDevice()
fxBoom := rl.LoadSound("boom.wav")