diff --git a/examples/textures/background_scrolling/cyberpunk_street_background.png b/examples/textures/background_scrolling/cyberpunk_street_background.png new file mode 100644 index 0000000..838d08a Binary files /dev/null and b/examples/textures/background_scrolling/cyberpunk_street_background.png differ diff --git a/examples/textures/background_scrolling/cyberpunk_street_foreground.png b/examples/textures/background_scrolling/cyberpunk_street_foreground.png new file mode 100644 index 0000000..528b4ae Binary files /dev/null and b/examples/textures/background_scrolling/cyberpunk_street_foreground.png differ diff --git a/examples/textures/background_scrolling/cyberpunk_street_midground.png b/examples/textures/background_scrolling/cyberpunk_street_midground.png new file mode 100644 index 0000000..73f24fe Binary files /dev/null and b/examples/textures/background_scrolling/cyberpunk_street_midground.png differ diff --git a/examples/textures/background_scrolling/main.go b/examples/textures/background_scrolling/main.go new file mode 100644 index 0000000..f57efa6 --- /dev/null +++ b/examples/textures/background_scrolling/main.go @@ -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() +} diff --git a/examples/textures/blend_modes/cyberpunk_street_background.png b/examples/textures/blend_modes/cyberpunk_street_background.png new file mode 100644 index 0000000..838d08a Binary files /dev/null and b/examples/textures/blend_modes/cyberpunk_street_background.png differ diff --git a/examples/textures/blend_modes/cyberpunk_street_foreground.png b/examples/textures/blend_modes/cyberpunk_street_foreground.png new file mode 100644 index 0000000..528b4ae Binary files /dev/null and b/examples/textures/blend_modes/cyberpunk_street_foreground.png differ diff --git a/examples/textures/blend_modes/main.go b/examples/textures/blend_modes/main.go new file mode 100644 index 0000000..4171bad --- /dev/null +++ b/examples/textures/blend_modes/main.go @@ -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() +} diff --git a/examples/textures/sprite_explosion/main.go b/examples/textures/sprite_explosion/main.go index 1e71291..ecc1584 100644 --- a/examples/textures/sprite_explosion/main.go +++ b/examples/textures/sprite_explosion/main.go @@ -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")