Update C sources, add new functions and rename package to
This commit is contained in:
parent
391c25482d
commit
08aa518a46
156 changed files with 34542 additions and 19573 deletions
16
README.md
16
README.md
|
@ -72,21 +72,21 @@ package main
|
||||||
import "github.com/gen2brain/raylib-go/raylib"
|
import "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - basic window")
|
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LightGray)
|
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -10,21 +10,25 @@ import (
|
||||||
// Linear Easing functions
|
// Linear Easing functions
|
||||||
|
|
||||||
// LinearNone easing
|
// LinearNone easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func LinearNone(t, b, c, d float32) float32 {
|
func LinearNone(t, b, c, d float32) float32 {
|
||||||
return c*t/d + b
|
return c*t/d + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinearIn easing
|
// LinearIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func LinearIn(t, b, c, d float32) float32 {
|
func LinearIn(t, b, c, d float32) float32 {
|
||||||
return c*t/d + b
|
return c*t/d + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinearOut easing
|
// LinearOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func LinearOut(t, b, c, d float32) float32 {
|
func LinearOut(t, b, c, d float32) float32 {
|
||||||
return c*t/d + b
|
return c*t/d + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinearInOut easing
|
// LinearInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func LinearInOut(t, b, c, d float32) float32 {
|
func LinearInOut(t, b, c, d float32) float32 {
|
||||||
return c*t/d + b
|
return c*t/d + b
|
||||||
}
|
}
|
||||||
|
@ -32,16 +36,19 @@ func LinearInOut(t, b, c, d float32) float32 {
|
||||||
// Sine Easing functions
|
// Sine Easing functions
|
||||||
|
|
||||||
// SineIn easing
|
// SineIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func SineIn(t, b, c, d float32) float32 {
|
func SineIn(t, b, c, d float32) float32 {
|
||||||
return -c*float32(math.Cos(float64(t/d)*(math.Pi/2))) + c + b
|
return -c*float32(math.Cos(float64(t/d)*(math.Pi/2))) + c + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// SineOut easing
|
// SineOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func SineOut(t, b, c, d float32) float32 {
|
func SineOut(t, b, c, d float32) float32 {
|
||||||
return c*float32(math.Sin(float64(t/d)*(math.Pi/2))) + b
|
return c*float32(math.Sin(float64(t/d)*(math.Pi/2))) + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// SineInOut easing
|
// SineInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func SineInOut(t, b, c, d float32) float32 {
|
func SineInOut(t, b, c, d float32) float32 {
|
||||||
return -c/2*(float32(math.Cos(math.Pi*float64(t/d)))-1) + b
|
return -c/2*(float32(math.Cos(math.Pi*float64(t/d)))-1) + b
|
||||||
}
|
}
|
||||||
|
@ -49,17 +56,20 @@ func SineInOut(t, b, c, d float32) float32 {
|
||||||
// Circular Easing functions
|
// Circular Easing functions
|
||||||
|
|
||||||
// CircIn easing
|
// CircIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CircIn(t, b, c, d float32) float32 {
|
func CircIn(t, b, c, d float32) float32 {
|
||||||
t = t / d
|
t = t / d
|
||||||
return -c*(float32(math.Sqrt(float64(1-t*t)))-1) + b
|
return -c*(float32(math.Sqrt(float64(1-t*t)))-1) + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// CircOut easing
|
// CircOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CircOut(t, b, c, d float32) float32 {
|
func CircOut(t, b, c, d float32) float32 {
|
||||||
return c*float32(math.Sqrt(1-float64((t/d-1)*t))) + b
|
return c*float32(math.Sqrt(1-float64((t/d-1)*t))) + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// CircInOut easing
|
// CircInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CircInOut(t, b, c, d float32) float32 {
|
func CircInOut(t, b, c, d float32) float32 {
|
||||||
t = t / d * 2
|
t = t / d * 2
|
||||||
|
|
||||||
|
@ -74,18 +84,21 @@ func CircInOut(t, b, c, d float32) float32 {
|
||||||
// Cubic Easing functions
|
// Cubic Easing functions
|
||||||
|
|
||||||
// CubicIn easing
|
// CubicIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CubicIn(t, b, c, d float32) float32 {
|
func CubicIn(t, b, c, d float32) float32 {
|
||||||
t = t / d
|
t = t / d
|
||||||
return c*t*t*t + b
|
return c*t*t*t + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// CubicOut easing
|
// CubicOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CubicOut(t, b, c, d float32) float32 {
|
func CubicOut(t, b, c, d float32) float32 {
|
||||||
t = t/d - 1
|
t = t/d - 1
|
||||||
return c*(t*t*t+1) + b
|
return c*(t*t*t+1) + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// CubicInOut easing
|
// CubicInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func CubicInOut(t, b, c, d float32) float32 {
|
func CubicInOut(t, b, c, d float32) float32 {
|
||||||
t = t / d * 2
|
t = t / d * 2
|
||||||
if t < 1 {
|
if t < 1 {
|
||||||
|
@ -99,18 +112,21 @@ func CubicInOut(t, b, c, d float32) float32 {
|
||||||
// Quadratic Easing functions
|
// Quadratic Easing functions
|
||||||
|
|
||||||
// QuadIn easing
|
// QuadIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func QuadIn(t, b, c, d float32) float32 {
|
func QuadIn(t, b, c, d float32) float32 {
|
||||||
t = t / d
|
t = t / d
|
||||||
return c*t*t + b
|
return c*t*t + b
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuadOut easing
|
// QuadOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func QuadOut(t, b, c, d float32) float32 {
|
func QuadOut(t, b, c, d float32) float32 {
|
||||||
t = t / d
|
t = t / d
|
||||||
return (-c*t*(t-2) + b)
|
return (-c*t*(t-2) + b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// QuadInOut easing
|
// QuadInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func QuadInOut(t, b, c, d float32) float32 {
|
func QuadInOut(t, b, c, d float32) float32 {
|
||||||
t = t / d * 2
|
t = t / d * 2
|
||||||
if t < 1 {
|
if t < 1 {
|
||||||
|
@ -123,6 +139,7 @@ func QuadInOut(t, b, c, d float32) float32 {
|
||||||
// Exponential Easing functions
|
// Exponential Easing functions
|
||||||
|
|
||||||
// ExpoIn easing
|
// ExpoIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ExpoIn(t, b, c, d float32) float32 {
|
func ExpoIn(t, b, c, d float32) float32 {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return b
|
return b
|
||||||
|
@ -132,6 +149,7 @@ func ExpoIn(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpoOut easing
|
// ExpoOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ExpoOut(t, b, c, d float32) float32 {
|
func ExpoOut(t, b, c, d float32) float32 {
|
||||||
if t == d {
|
if t == d {
|
||||||
return (b + c)
|
return (b + c)
|
||||||
|
@ -141,6 +159,7 @@ func ExpoOut(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpoInOut easing
|
// ExpoInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ExpoInOut(t, b, c, d float32) float32 {
|
func ExpoInOut(t, b, c, d float32) float32 {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return b
|
return b
|
||||||
|
@ -162,6 +181,7 @@ func ExpoInOut(t, b, c, d float32) float32 {
|
||||||
// Back Easing functions
|
// Back Easing functions
|
||||||
|
|
||||||
// BackIn easing
|
// BackIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BackIn(t, b, c, d float32) float32 {
|
func BackIn(t, b, c, d float32) float32 {
|
||||||
s := float32(1.70158)
|
s := float32(1.70158)
|
||||||
t = t / d
|
t = t / d
|
||||||
|
@ -169,6 +189,7 @@ func BackIn(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackOut easing
|
// BackOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BackOut(t, b, c, d float32) float32 {
|
func BackOut(t, b, c, d float32) float32 {
|
||||||
s := float32(1.70158)
|
s := float32(1.70158)
|
||||||
t = t/d - 1
|
t = t/d - 1
|
||||||
|
@ -176,6 +197,7 @@ func BackOut(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BackInOut easing
|
// BackInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BackInOut(t, b, c, d float32) float32 {
|
func BackInOut(t, b, c, d float32) float32 {
|
||||||
s := float32(1.70158)
|
s := float32(1.70158)
|
||||||
s = s * 1.525
|
s = s * 1.525
|
||||||
|
@ -192,11 +214,13 @@ func BackInOut(t, b, c, d float32) float32 {
|
||||||
// Bounce Easing functions
|
// Bounce Easing functions
|
||||||
|
|
||||||
// BounceIn easing
|
// BounceIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BounceIn(t, b, c, d float32) float32 {
|
func BounceIn(t, b, c, d float32) float32 {
|
||||||
return (c - BounceOut(d-t, 0, c, d) + b)
|
return (c - BounceOut(d-t, 0, c, d) + b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BounceOut easing
|
// BounceOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BounceOut(t, b, c, d float32) float32 {
|
func BounceOut(t, b, c, d float32) float32 {
|
||||||
t = t / d
|
t = t / d
|
||||||
if t < (1 / 2.75) {
|
if t < (1 / 2.75) {
|
||||||
|
@ -214,6 +238,7 @@ func BounceOut(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BounceInOut easing
|
// BounceInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func BounceInOut(t, b, c, d float32) float32 {
|
func BounceInOut(t, b, c, d float32) float32 {
|
||||||
if t < d/2 {
|
if t < d/2 {
|
||||||
return BounceIn(t*2, 0, c, d)*0.5 + b
|
return BounceIn(t*2, 0, c, d)*0.5 + b
|
||||||
|
@ -225,6 +250,7 @@ func BounceInOut(t, b, c, d float32) float32 {
|
||||||
// Elastic Easing functions
|
// Elastic Easing functions
|
||||||
|
|
||||||
// ElasticIn easing
|
// ElasticIn easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ElasticIn(t, b, c, d float32) float32 {
|
func ElasticIn(t, b, c, d float32) float32 {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return b
|
return b
|
||||||
|
@ -245,6 +271,7 @@ func ElasticIn(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ElasticOut easing
|
// ElasticOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ElasticOut(t, b, c, d float32) float32 {
|
func ElasticOut(t, b, c, d float32) float32 {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return b
|
return b
|
||||||
|
@ -264,6 +291,7 @@ func ElasticOut(t, b, c, d float32) float32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ElasticInOut easing
|
// ElasticInOut easing
|
||||||
|
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||||
func ElasticInOut(t, b, c, d float32) float32 {
|
func ElasticInOut(t, b, c, d float32) float32 {
|
||||||
if t == 0 {
|
if t == 0 {
|
||||||
return b
|
return b
|
||||||
|
|
|
@ -7,27 +7,27 @@ import (
|
||||||
const maxCircles = 64
|
const maxCircles = 64
|
||||||
|
|
||||||
type circleWave struct {
|
type circleWave struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Radius float32
|
Radius float32
|
||||||
Alpha float32
|
Alpha float32
|
||||||
Speed float32
|
Speed float32
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // NOTE: Try to enable MSAA 4X
|
rl.SetConfigFlags(rl.FlagMsaa4xHint) // NOTE: Try to enable MSAA 4X
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)")
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
colors := []raylib.Color{
|
colors := []rl.Color{
|
||||||
raylib.Orange, raylib.Red, raylib.Gold, raylib.Lime, raylib.Blue,
|
rl.Orange, rl.Red, rl.Gold, rl.Lime, rl.Blue,
|
||||||
raylib.Violet, raylib.Brown, raylib.LightGray, raylib.Pink,
|
rl.Violet, rl.Brown, rl.LightGray, rl.Pink,
|
||||||
raylib.Yellow, raylib.Green, raylib.SkyBlue, raylib.Purple, raylib.Beige,
|
rl.Yellow, rl.Green, rl.SkyBlue, rl.Purple, rl.Beige,
|
||||||
}
|
}
|
||||||
|
|
||||||
circles := make([]circleWave, maxCircles)
|
circles := make([]circleWave, maxCircles)
|
||||||
|
@ -36,47 +36,47 @@ func main() {
|
||||||
c := circleWave{}
|
c := circleWave{}
|
||||||
|
|
||||||
c.Alpha = 0
|
c.Alpha = 0
|
||||||
c.Radius = float32(raylib.GetRandomValue(10, 40))
|
c.Radius = float32(rl.GetRandomValue(10, 40))
|
||||||
|
|
||||||
x := raylib.GetRandomValue(int32(c.Radius), screenWidth-int32(c.Radius))
|
x := rl.GetRandomValue(int32(c.Radius), screenWidth-int32(c.Radius))
|
||||||
y := raylib.GetRandomValue(int32(c.Radius), screenHeight-int32(c.Radius))
|
y := rl.GetRandomValue(int32(c.Radius), screenHeight-int32(c.Radius))
|
||||||
c.Position = raylib.NewVector2(float32(x), float32(y))
|
c.Position = rl.NewVector2(float32(x), float32(y))
|
||||||
|
|
||||||
c.Speed = float32(raylib.GetRandomValue(1, 100)) / 20000.0
|
c.Speed = float32(rl.GetRandomValue(1, 100)) / 20000.0
|
||||||
c.Color = colors[raylib.GetRandomValue(0, int32(len(colors)-1))]
|
c.Color = colors[rl.GetRandomValue(0, int32(len(colors)-1))]
|
||||||
|
|
||||||
circles[i] = c
|
circles[i] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
xm := raylib.LoadMusicStream("mini1111.xm")
|
xm := rl.LoadMusicStream("mini1111.xm")
|
||||||
raylib.PlayMusicStream(xm)
|
rl.PlayMusicStream(xm)
|
||||||
|
|
||||||
pause := false
|
pause := false
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateMusicStream(xm) // Update music buffer with new stream data
|
rl.UpdateMusicStream(xm) // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
raylib.StopMusicStream(xm)
|
rl.StopMusicStream(xm)
|
||||||
raylib.PlayMusicStream(xm)
|
rl.PlayMusicStream(xm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/Resume music playing
|
// Pause/Resume music playing
|
||||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
if rl.IsKeyPressed(rl.KeyP) {
|
||||||
pause = !pause
|
pause = !pause
|
||||||
|
|
||||||
if pause {
|
if pause {
|
||||||
raylib.PauseMusicStream(xm)
|
rl.PauseMusicStream(xm)
|
||||||
} else {
|
} else {
|
||||||
raylib.ResumeMusicStream(xm)
|
rl.ResumeMusicStream(xm)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions
|
// Get timePlayed scaled to bar dimensions
|
||||||
timePlayed := int32(raylib.GetMusicTimePlayed(xm)/raylib.GetMusicTimeLength(xm)*float32(screenWidth-40)) * 2
|
timePlayed := int32(rl.GetMusicTimePlayed(xm)/rl.GetMusicTimeLength(xm)*float32(screenWidth-40)) * 2
|
||||||
|
|
||||||
// Color circles animation
|
// Color circles animation
|
||||||
for i := maxCircles - 1; (i >= 0) && !pause; i-- {
|
for i := maxCircles - 1; (i >= 0) && !pause; i-- {
|
||||||
|
@ -89,33 +89,33 @@ func main() {
|
||||||
|
|
||||||
if circles[i].Alpha <= 0.0 {
|
if circles[i].Alpha <= 0.0 {
|
||||||
circles[i].Alpha = 0.0
|
circles[i].Alpha = 0.0
|
||||||
circles[i].Radius = float32(raylib.GetRandomValue(10, 40))
|
circles[i].Radius = float32(rl.GetRandomValue(10, 40))
|
||||||
circles[i].Position.X = float32(raylib.GetRandomValue(int32(circles[i].Radius), screenWidth-int32(circles[i].Radius)))
|
circles[i].Position.X = float32(rl.GetRandomValue(int32(circles[i].Radius), screenWidth-int32(circles[i].Radius)))
|
||||||
circles[i].Position.Y = float32(raylib.GetRandomValue(int32(circles[i].Radius), screenHeight-int32(circles[i].Radius)))
|
circles[i].Position.Y = float32(rl.GetRandomValue(int32(circles[i].Radius), screenHeight-int32(circles[i].Radius)))
|
||||||
circles[i].Color = colors[raylib.GetRandomValue(0, 13)]
|
circles[i].Color = colors[rl.GetRandomValue(0, 13)]
|
||||||
circles[i].Speed = float32(raylib.GetRandomValue(1, 100)) / 20000.0
|
circles[i].Speed = float32(rl.GetRandomValue(1, 100)) / 20000.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
for i := maxCircles - 1; i >= 0; i-- {
|
for i := maxCircles - 1; i >= 0; i-- {
|
||||||
raylib.DrawCircleV(circles[i].Position, float32(circles[i].Radius), raylib.Fade(circles[i].Color, circles[i].Alpha))
|
rl.DrawCircleV(circles[i].Position, float32(circles[i].Radius), rl.Fade(circles[i].Color, circles[i].Alpha))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw time bar
|
// Draw time bar
|
||||||
raylib.DrawRectangle(20, screenHeight-20-12, screenWidth-40, 12, raylib.LightGray)
|
rl.DrawRectangle(20, screenHeight-20-12, screenWidth-40, 12, rl.LightGray)
|
||||||
raylib.DrawRectangle(20, screenHeight-20-12, timePlayed, 12, raylib.Maroon)
|
rl.DrawRectangle(20, screenHeight-20-12, timePlayed, 12, rl.Maroon)
|
||||||
raylib.DrawRectangleLines(20, screenHeight-20-12, screenWidth-40, 12, raylib.Gray)
|
rl.DrawRectangleLines(20, screenHeight-20-12, screenWidth-40, 12, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadMusicStream(xm)
|
rl.UnloadMusicStream(xm)
|
||||||
|
|
||||||
raylib.CloseAudioDevice()
|
rl.CloseAudioDevice()
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,56 +5,56 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
music := raylib.LoadMusicStream("guitar_noodling.ogg")
|
music := rl.LoadMusicStream("guitar_noodling.ogg")
|
||||||
pause := false
|
pause := false
|
||||||
|
|
||||||
raylib.PlayMusicStream(music)
|
rl.PlayMusicStream(music)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateMusicStream(music) // Update music buffer with new stream data
|
rl.UpdateMusicStream(music) // Update music buffer with new stream data
|
||||||
|
|
||||||
// Restart music playing (stop and play)
|
// Restart music playing (stop and play)
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
raylib.StopMusicStream(music)
|
rl.StopMusicStream(music)
|
||||||
raylib.PlayMusicStream(music)
|
rl.PlayMusicStream(music)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause/Resume music playing
|
// Pause/Resume music playing
|
||||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
if rl.IsKeyPressed(rl.KeyP) {
|
||||||
pause = !pause
|
pause = !pause
|
||||||
|
|
||||||
if pause {
|
if pause {
|
||||||
raylib.PauseMusicStream(music)
|
rl.PauseMusicStream(music)
|
||||||
} else {
|
} else {
|
||||||
raylib.ResumeMusicStream(music)
|
rl.ResumeMusicStream(music)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get timePlayed scaled to bar dimensions (400 pixels)
|
// Get timePlayed scaled to bar dimensions (400 pixels)
|
||||||
timePlayed := raylib.GetMusicTimePlayed(music) / raylib.GetMusicTimeLength(music) * 100 * 4
|
timePlayed := rl.GetMusicTimePlayed(music) / rl.GetMusicTimeLength(music) * 100 * 4
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
raylib.DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, raylib.LightGray)
|
rl.DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.DrawRectangle(200, 200, 400, 12, raylib.LightGray)
|
rl.DrawRectangle(200, 200, 400, 12, rl.LightGray)
|
||||||
raylib.DrawRectangle(200, 200, int32(timePlayed), 12, raylib.Maroon)
|
rl.DrawRectangle(200, 200, int32(timePlayed), 12, rl.Maroon)
|
||||||
raylib.DrawRectangleLines(200, 200, 400, 12, raylib.Gray)
|
rl.DrawRectangleLines(200, 200, 400, 12, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, raylib.LightGray)
|
rl.DrawText("PRESS SPACE TO RESTART MUSIC", 215, 250, 20, rl.LightGray)
|
||||||
raylib.DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, raylib.LightGray)
|
rl.DrawText("PRESS P TO PAUSE/RESUME MUSIC", 208, 280, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadMusicStream(music) // Unload music stream buffers from RAM
|
rl.UnloadMusicStream(music) // Unload music stream buffers from RAM
|
||||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,34 +12,34 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
stream := raylib.InitAudioStream(22050, 32, 1)
|
stream := rl.InitAudioStream(22050, 32, 1)
|
||||||
|
|
||||||
//// Fill audio stream with some samples (sine wave)
|
//// Fill audio stream with some samples (sine wave)
|
||||||
data := make([]float32, maxSamples)
|
data := make([]float32, maxSamples)
|
||||||
|
|
||||||
for i := 0; i < maxSamples; i++ {
|
for i := 0; i < maxSamples; i++ {
|
||||||
data[i] = float32(math.Sin(float64((2*raylib.Pi*float32(i))/2) * raylib.Deg2rad))
|
data[i] = float32(math.Sin(float64((2*rl.Pi*float32(i))/2) * rl.Deg2rad))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
// for that reason, there is a clip everytime audio stream is looped
|
// for that reason, there is a clip everytime audio stream is looped
|
||||||
raylib.PlayAudioStream(stream)
|
rl.PlayAudioStream(stream)
|
||||||
|
|
||||||
totalSamples := int32(maxSamples)
|
totalSamples := int32(maxSamples)
|
||||||
samplesLeft := int32(totalSamples)
|
samplesLeft := int32(totalSamples)
|
||||||
|
|
||||||
position := raylib.NewVector2(0, 0)
|
position := rl.NewVector2(0, 0)
|
||||||
|
|
||||||
raylib.SetTargetFPS(30)
|
rl.SetTargetFPS(30)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Refill audio stream if required
|
// Refill audio stream if required
|
||||||
if raylib.IsAudioBufferProcessed(stream) {
|
if rl.IsAudioBufferProcessed(stream) {
|
||||||
numSamples := int32(0)
|
numSamples := int32(0)
|
||||||
if samplesLeft >= maxSamplesPerUpdate {
|
if samplesLeft >= maxSamplesPerUpdate {
|
||||||
numSamples = maxSamplesPerUpdate
|
numSamples = maxSamplesPerUpdate
|
||||||
|
@ -47,7 +47,7 @@ func main() {
|
||||||
numSamples = samplesLeft
|
numSamples = samplesLeft
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
rl.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||||
|
|
||||||
samplesLeft -= numSamples
|
samplesLeft -= numSamples
|
||||||
|
|
||||||
|
@ -57,25 +57,25 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
raylib.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, raylib.LightGray)
|
rl.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, rl.LightGray)
|
||||||
|
|
||||||
// NOTE: Draw a part of the sine wave (only screen width)
|
// NOTE: Draw a part of the sine wave (only screen width)
|
||||||
for i := 0; i < int(raylib.GetScreenWidth()); i++ {
|
for i := 0; i < int(rl.GetScreenWidth()); i++ {
|
||||||
position.X = float32(i)
|
position.X = float32(i)
|
||||||
position.Y = 250 + 50*data[i]
|
position.Y = 250 + 50*data[i]
|
||||||
|
|
||||||
raylib.DrawPixelV(position, raylib.Red)
|
rl.DrawPixelV(position, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
rl.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,37 +5,37 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [audio] example - sound loading and playing")
|
rl.InitWindow(800, 450, "raylib [audio] example - sound loading and playing")
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
fxWav := raylib.LoadSound("weird.wav")
|
fxWav := rl.LoadSound("weird.wav")
|
||||||
fxOgg := raylib.LoadSound("tanatana.ogg")
|
fxOgg := rl.LoadSound("tanatana.ogg")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
raylib.PlaySound(fxWav)
|
rl.PlaySound(fxWav)
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
raylib.PlaySound(fxOgg)
|
rl.PlaySound(fxOgg)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, raylib.LightGray)
|
rl.DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, rl.LightGray)
|
||||||
raylib.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, raylib.LightGray)
|
rl.DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadSound(fxWav)
|
rl.UnloadSound(fxWav)
|
||||||
raylib.UnloadSound(fxOgg)
|
rl.UnloadSound(fxOgg)
|
||||||
|
|
||||||
raylib.CloseAudioDevice()
|
rl.CloseAudioDevice()
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,54 +12,54 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera")
|
||||||
|
|
||||||
player := raylib.NewRectangle(400, 280, 40, 40)
|
player := rl.NewRectangle(400, 280, 40, 40)
|
||||||
|
|
||||||
buildings := make([]raylib.Rectangle, maxBuildings)
|
buildings := make([]rl.Rectangle, maxBuildings)
|
||||||
buildColors := make([]raylib.Color, maxBuildings)
|
buildColors := make([]rl.Color, maxBuildings)
|
||||||
|
|
||||||
spacing := float32(0)
|
spacing := float32(0)
|
||||||
|
|
||||||
for i := 0; i < maxBuildings; i++ {
|
for i := 0; i < maxBuildings; i++ {
|
||||||
r := raylib.Rectangle{}
|
r := rl.Rectangle{}
|
||||||
r.Width = float32(raylib.GetRandomValue(50, 200))
|
r.Width = float32(rl.GetRandomValue(50, 200))
|
||||||
r.Height = float32(raylib.GetRandomValue(100, 800))
|
r.Height = float32(rl.GetRandomValue(100, 800))
|
||||||
r.Y = float32(screenHeight) - 130 - r.Height
|
r.Y = float32(screenHeight) - 130 - r.Height
|
||||||
r.X = -6000 + spacing
|
r.X = -6000 + spacing
|
||||||
|
|
||||||
spacing += r.Width
|
spacing += r.Width
|
||||||
|
|
||||||
c := raylib.NewColor(byte(raylib.GetRandomValue(200, 240)), byte(raylib.GetRandomValue(200, 240)), byte(raylib.GetRandomValue(200, 250)), byte(255))
|
c := rl.NewColor(byte(rl.GetRandomValue(200, 240)), byte(rl.GetRandomValue(200, 240)), byte(rl.GetRandomValue(200, 250)), byte(255))
|
||||||
|
|
||||||
buildings[i] = r
|
buildings[i] = r
|
||||||
buildColors[i] = c
|
buildColors[i] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
camera := raylib.Camera2D{}
|
camera := rl.Camera2D{}
|
||||||
camera.Target = raylib.NewVector2(float32(player.X+20), float32(player.Y+20))
|
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||||
camera.Offset = raylib.NewVector2(0, 0)
|
camera.Offset = rl.NewVector2(0, 0)
|
||||||
camera.Rotation = 0.0
|
camera.Rotation = 0.0
|
||||||
camera.Zoom = 1.0
|
camera.Zoom = 1.0
|
||||||
|
|
||||||
raylib.SetTargetFPS(30)
|
rl.SetTargetFPS(30)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
if rl.IsKeyDown(rl.KeyRight) {
|
||||||
player.X += 2 // Player movement
|
player.X += 2 // Player movement
|
||||||
camera.Offset.X -= 2 // Camera displacement with player movement
|
camera.Offset.X -= 2 // Camera displacement with player movement
|
||||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
player.X -= 2 // Player movement
|
player.X -= 2 // Player movement
|
||||||
camera.Offset.X += 2 // Camera displacement with player movement
|
camera.Offset.X += 2 // Camera displacement with player movement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera target follows player
|
// Camera target follows player
|
||||||
camera.Target = raylib.NewVector2(float32(player.X+20), float32(player.Y+20))
|
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||||
|
|
||||||
// Camera rotation controls
|
// Camera rotation controls
|
||||||
if raylib.IsKeyDown(raylib.KeyA) {
|
if rl.IsKeyDown(rl.KeyA) {
|
||||||
camera.Rotation--
|
camera.Rotation--
|
||||||
} else if raylib.IsKeyDown(raylib.KeyS) {
|
} else if rl.IsKeyDown(rl.KeyS) {
|
||||||
camera.Rotation++
|
camera.Rotation++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera zoom controls
|
// Camera zoom controls
|
||||||
camera.Zoom += float32(raylib.GetMouseWheelMove()) * 0.05
|
camera.Zoom += float32(rl.GetMouseWheelMove()) * 0.05
|
||||||
|
|
||||||
if camera.Zoom > 3.0 {
|
if camera.Zoom > 3.0 {
|
||||||
camera.Zoom = 3.0
|
camera.Zoom = 3.0
|
||||||
|
@ -80,48 +80,48 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera reset (zoom and rotation)
|
// Camera reset (zoom and rotation)
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
if rl.IsKeyPressed(rl.KeyR) {
|
||||||
camera.Zoom = 1.0
|
camera.Zoom = 1.0
|
||||||
camera.Rotation = 0.0
|
camera.Rotation = 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode2D(camera)
|
rl.BeginMode2D(camera)
|
||||||
|
|
||||||
raylib.DrawRectangle(-6000, 320, 13000, 8000, raylib.DarkGray)
|
rl.DrawRectangle(-6000, 320, 13000, 8000, rl.DarkGray)
|
||||||
|
|
||||||
for i := 0; i < maxBuildings; i++ {
|
for i := 0; i < maxBuildings; i++ {
|
||||||
raylib.DrawRectangleRec(buildings[i], buildColors[i])
|
rl.DrawRectangleRec(buildings[i], buildColors[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangleRec(player, raylib.Red)
|
rl.DrawRectangleRec(player, rl.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(int32(camera.Target.X), -500, 1, screenHeight*4, raylib.Green)
|
rl.DrawRectangle(int32(camera.Target.X), -500, 1, screenHeight*4, rl.Green)
|
||||||
raylib.DrawRectangle(-500, int32(camera.Target.Y), screenWidth*4, 1, raylib.Green)
|
rl.DrawRectangle(-500, int32(camera.Target.Y), screenWidth*4, 1, rl.Green)
|
||||||
|
|
||||||
raylib.EndMode2D()
|
rl.EndMode2D()
|
||||||
|
|
||||||
raylib.DrawText("SCREEN AREA", 640, 10, 20, raylib.Red)
|
rl.DrawText("SCREEN AREA", 640, 10, 20, rl.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, 5, raylib.Red)
|
rl.DrawRectangle(0, 0, screenWidth, 5, rl.Red)
|
||||||
raylib.DrawRectangle(0, 5, 5, screenHeight-10, raylib.Red)
|
rl.DrawRectangle(0, 5, 5, screenHeight-10, rl.Red)
|
||||||
raylib.DrawRectangle(screenWidth-5, 5, 5, screenHeight-10, raylib.Red)
|
rl.DrawRectangle(screenWidth-5, 5, 5, screenHeight-10, rl.Red)
|
||||||
raylib.DrawRectangle(0, screenHeight-5, screenWidth, 5, raylib.Red)
|
rl.DrawRectangle(0, screenHeight-5, screenWidth, 5, rl.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(10, 10, 250, 113, raylib.Fade(raylib.SkyBlue, 0.5))
|
rl.DrawRectangle(10, 10, 250, 113, rl.Fade(rl.SkyBlue, 0.5))
|
||||||
raylib.DrawRectangleLines(10, 10, 250, 113, raylib.Blue)
|
rl.DrawRectangleLines(10, 10, 250, 113, rl.Blue)
|
||||||
|
|
||||||
raylib.DrawText("Free 2d camera controls:", 20, 20, 10, raylib.Black)
|
rl.DrawText("Free 2d camera controls:", 20, 20, 10, rl.Black)
|
||||||
raylib.DrawText("- Right/Left to move Offset", 40, 40, 10, raylib.DarkGray)
|
rl.DrawText("- Right/Left to move Offset", 40, 40, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, raylib.DarkGray)
|
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 60, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- A / S to Rotate", 40, 80, 10, raylib.DarkGray)
|
rl.DrawText("- A / S to Rotate", 40, 80, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, raylib.DarkGray)
|
rl.DrawText("- R to reset Zoom and Rotation", 40, 100, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,61 +9,61 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
|
rl.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
|
||||||
|
|
||||||
camera := raylib.Camera3D{}
|
camera := rl.Camera3D{}
|
||||||
camera.Position = raylib.NewVector3(4.0, 2.0, 4.0)
|
camera.Position = rl.NewVector3(4.0, 2.0, 4.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 1.8, 0.0)
|
camera.Target = rl.NewVector3(0.0, 1.8, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 60.0
|
camera.Fovy = 60.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
// Generates some random columns
|
// Generates some random columns
|
||||||
heights := make([]float32, maxColumns)
|
heights := make([]float32, maxColumns)
|
||||||
positions := make([]raylib.Vector3, maxColumns)
|
positions := make([]rl.Vector3, maxColumns)
|
||||||
colors := make([]raylib.Color, maxColumns)
|
colors := make([]rl.Color, maxColumns)
|
||||||
|
|
||||||
for i := 0; i < maxColumns; i++ {
|
for i := 0; i < maxColumns; i++ {
|
||||||
heights[i] = float32(raylib.GetRandomValue(1, 12))
|
heights[i] = float32(rl.GetRandomValue(1, 12))
|
||||||
positions[i] = raylib.NewVector3(float32(raylib.GetRandomValue(-15, 15)), heights[i]/2, float32(raylib.GetRandomValue(-15, 15)))
|
positions[i] = rl.NewVector3(float32(rl.GetRandomValue(-15, 15)), heights[i]/2, float32(rl.GetRandomValue(-15, 15)))
|
||||||
colors[i] = raylib.NewColor(uint8(raylib.GetRandomValue(20, 255)), uint8(raylib.GetRandomValue(10, 55)), 30, 255)
|
colors[i] = rl.NewColor(uint8(rl.GetRandomValue(20, 255)), uint8(rl.GetRandomValue(10, 55)), 30, 255)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFirstPerson) // Set a first person camera mode
|
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set a first person camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawPlane(raylib.NewVector3(0.0, 0.0, 0.0), raylib.NewVector2(32.0, 32.0), raylib.LightGray) // Draw ground
|
rl.DrawPlane(rl.NewVector3(0.0, 0.0, 0.0), rl.NewVector2(32.0, 32.0), rl.LightGray) // Draw ground
|
||||||
raylib.DrawCube(raylib.NewVector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, raylib.Blue) // Draw a blue wall
|
rl.DrawCube(rl.NewVector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Blue) // Draw a blue wall
|
||||||
raylib.DrawCube(raylib.NewVector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, raylib.Lime) // Draw a green wall
|
rl.DrawCube(rl.NewVector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.Lime) // Draw a green wall
|
||||||
raylib.DrawCube(raylib.NewVector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, raylib.Gold) // Draw a yellow wall
|
rl.DrawCube(rl.NewVector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.Gold) // Draw a yellow wall
|
||||||
|
|
||||||
// Draw some cubes around
|
// Draw some cubes around
|
||||||
for i := 0; i < maxColumns; i++ {
|
for i := 0; i < maxColumns; i++ {
|
||||||
raylib.DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
rl.DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i])
|
||||||
raylib.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, raylib.Maroon)
|
rl.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, rl.Maroon)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawRectangle(10, 10, 220, 70, raylib.Fade(raylib.SkyBlue, 0.5))
|
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SkyBlue, 0.5))
|
||||||
raylib.DrawRectangleLines(10, 10, 220, 70, raylib.Blue)
|
rl.DrawRectangleLines(10, 10, 220, 70, rl.Blue)
|
||||||
|
|
||||||
raylib.DrawText("First person camera default controls:", 20, 20, 10, raylib.Black)
|
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Black)
|
||||||
raylib.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, raylib.DarkGray)
|
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Mouse move to look around", 40, 60, 10, raylib.DarkGray)
|
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,53 +5,53 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d camera free")
|
rl.InitWindow(800, 450, "raylib [core] example - 3d camera free")
|
||||||
|
|
||||||
camera := raylib.Camera3D{}
|
camera := rl.Camera3D{}
|
||||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0)
|
camera.Position = rl.NewVector3(10.0, 10.0, 10.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
if raylib.IsKeyDown(raylib.KeyZ) {
|
if rl.IsKeyDown(rl.KeyZ) {
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0)
|
rl.DrawGrid(10, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawRectangle(10, 10, 320, 133, raylib.Fade(raylib.SkyBlue, 0.5))
|
rl.DrawRectangle(10, 10, 320, 133, rl.Fade(rl.SkyBlue, 0.5))
|
||||||
raylib.DrawRectangleLines(10, 10, 320, 133, raylib.Blue)
|
rl.DrawRectangleLines(10, 10, 320, 133, rl.Blue)
|
||||||
|
|
||||||
raylib.DrawText("Free camera default controls:", 20, 20, 10, raylib.Black)
|
rl.DrawText("Free camera default controls:", 20, 20, 10, rl.Black)
|
||||||
raylib.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, raylib.DarkGray)
|
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, raylib.DarkGray)
|
rl.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, raylib.DarkGray)
|
rl.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, raylib.DarkGray)
|
rl.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, rl.DarkGray)
|
||||||
raylib.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, raylib.DarkGray)
|
rl.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,39 +5,39 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - 3d mode")
|
rl.InitWindow(800, 450, "raylib [core] example - 3d mode")
|
||||||
|
|
||||||
camera := raylib.Camera3D{}
|
camera := rl.Camera3D{}
|
||||||
camera.Position = raylib.NewVector3(0.0, 10.0, 10.0)
|
camera.Position = rl.NewVector3(0.0, 10.0, 10.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0)
|
rl.DrawGrid(10, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("Welcome to the third dimension!", 10, 40, 20, raylib.DarkGray)
|
rl.DrawText("Welcome to the third dimension!", 10, 40, 20, rl.DarkGray)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,70 +8,71 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking")
|
||||||
|
|
||||||
camera := raylib.Camera3D{}
|
camera := rl.Camera3D{}
|
||||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0)
|
camera.Position = rl.NewVector3(10.0, 10.0, 10.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := raylib.NewVector3(0.0, 1.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
cubeSize := raylib.NewVector3(2.0, 2.0, 2.0)
|
cubeSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||||
|
|
||||||
var ray raylib.Ray
|
var ray rl.Ray
|
||||||
|
|
||||||
collision := false
|
collision := false
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
ray = raylib.GetMouseRay(raylib.GetMousePosition(), camera)
|
// NOTE: This function is NOT WORKING properly!
|
||||||
|
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
||||||
|
|
||||||
// Check collision between ray and box
|
// Check collision between ray and box
|
||||||
min := raylib.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
min := rl.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
||||||
max := raylib.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
max := rl.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
||||||
collision = raylib.CheckCollisionRayBox(ray, raylib.NewBoundingBox(min, max))
|
collision = rl.CheckCollisionRayBox(ray, rl.NewBoundingBox(min, max))
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
if collision {
|
if collision {
|
||||||
raylib.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Red)
|
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Red)
|
||||||
raylib.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Maroon)
|
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawCubeWires(cubePosition, cubeSize.X+0.2, cubeSize.Y+0.2, cubeSize.Z+0.2, raylib.Green)
|
rl.DrawCubeWires(cubePosition, cubeSize.X+0.2, cubeSize.Y+0.2, cubeSize.Z+0.2, rl.Green)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.Gray)
|
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Gray)
|
||||||
raylib.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, raylib.DarkGray)
|
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.DarkGray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRay(ray, raylib.Maroon)
|
rl.DrawRay(ray, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0)
|
rl.DrawGrid(10, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("Try selecting the box with mouse!", 240, 10, 20, raylib.DarkGray)
|
rl.DrawText("Try selecting the box with mouse!", 240, 10, 20, rl.DarkGray)
|
||||||
|
|
||||||
if collision {
|
if collision {
|
||||||
raylib.DrawText("BOX SELECTED", (screenWidth-raylib.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, raylib.Green)
|
rl.DrawText("BOX SELECTED", (screenWidth-rl.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, rl.Green)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package main
|
||||||
import "github.com/gen2brain/raylib-go/raylib"
|
import "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - basic window")
|
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||||
|
|
||||||
//raylib.SetTargetFPS(60)
|
//rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LightGray)
|
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
||||||
|
|
||||||
colors := [21]raylib.Color{
|
colors := [21]rl.Color{
|
||||||
raylib.DarkGray, raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple,
|
rl.DarkGray, rl.Maroon, rl.Orange, rl.DarkGreen, rl.DarkBlue, rl.DarkPurple,
|
||||||
raylib.DarkBrown, raylib.Gray, raylib.Red, raylib.Gold, raylib.Lime, raylib.Blue, raylib.Violet, raylib.Brown,
|
rl.DarkBrown, rl.Gray, rl.Red, rl.Gold, rl.Lime, rl.Blue, rl.Violet, rl.Brown,
|
||||||
raylib.LightGray, raylib.Pink, raylib.Yellow, raylib.Green, raylib.SkyBlue, raylib.Purple, raylib.Beige,
|
rl.LightGray, rl.Pink, rl.Yellow, rl.Green, rl.SkyBlue, rl.Purple, rl.Beige,
|
||||||
}
|
}
|
||||||
|
|
||||||
colorsRecs := make([]raylib.Rectangle, 21) // Rectangles array
|
colorsRecs := make([]rl.Rectangle, 21) // Rectangles array
|
||||||
|
|
||||||
// Fills colorsRecs data (for every rectangle)
|
// Fills colorsRecs data (for every rectangle)
|
||||||
for i := 0; i < 21; i++ {
|
for i := 0; i < 21; i++ {
|
||||||
r := raylib.Rectangle{}
|
r := rl.Rectangle{}
|
||||||
r.X = float32(20 + 100*(i%7) + 10*(i%7))
|
r.X = float32(20 + 100*(i%7) + 10*(i%7))
|
||||||
r.Y = float32(60 + 100*(i/7) + 10*(i/7))
|
r.Y = float32(60 + 100*(i/7) + 10*(i/7))
|
||||||
r.Width = 100
|
r.Width = 100
|
||||||
|
@ -28,18 +28,18 @@ func main() {
|
||||||
|
|
||||||
selected := make([]bool, 21) // Selected rectangles indicator
|
selected := make([]bool, 21) // Selected rectangles indicator
|
||||||
|
|
||||||
mousePoint := raylib.Vector2{}
|
mousePoint := rl.Vector2{}
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
mousePoint = raylib.GetMousePosition()
|
mousePoint = rl.GetMousePosition()
|
||||||
|
|
||||||
for i := 0; i < 21; i++ { // Iterate along all the rectangles
|
for i := 0; i < 21; i++ { // Iterate along all the rectangles
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, colorsRecs[i]) {
|
if rl.CheckCollisionPointRec(mousePoint, colorsRecs[i]) {
|
||||||
colors[i].A = 120
|
colors[i].A = 120
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
selected[i] = !selected[i]
|
selected[i] = !selected[i]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,24 +47,24 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
for i := 0; i < 21; i++ { // Draw all rectangles
|
for i := 0; i < 21; i++ { // Draw all rectangles
|
||||||
raylib.DrawRectangleRec(colorsRecs[i], colors[i])
|
rl.DrawRectangleRec(colorsRecs[i], colors[i])
|
||||||
|
|
||||||
// Draw four rectangles around selected rectangle
|
// Draw four rectangles around selected rectangle
|
||||||
if selected[i] {
|
if selected[i] {
|
||||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 100, 10, raylib.RayWhite) // Square top rectangle
|
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 100, 10, rl.RayWhite) // Square top rectangle
|
||||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 10, 100, raylib.RayWhite) // Square left rectangle
|
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y), 10, 100, rl.RayWhite) // Square left rectangle
|
||||||
raylib.DrawRectangle(int32(colorsRecs[i].X+90), int32(colorsRecs[i].Y), 10, 100, raylib.RayWhite) // Square right rectangle
|
rl.DrawRectangle(int32(colorsRecs[i].X+90), int32(colorsRecs[i].Y), 10, 100, rl.RayWhite) // Square right rectangle
|
||||||
raylib.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y)+90, 100, 10, raylib.RayWhite) // Square bottom rectangle
|
rl.DrawRectangle(int32(colorsRecs[i].X), int32(colorsRecs[i].Y)+90, 100, 10, rl.RayWhite) // Square bottom rectangle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,43 +8,43 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
count := int32(0)
|
count := int32(0)
|
||||||
var droppedFiles []string
|
var droppedFiles []string
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsFileDropped() {
|
if rl.IsFileDropped() {
|
||||||
droppedFiles = raylib.GetDroppedFiles(&count)
|
droppedFiles = rl.GetDroppedFiles(&count)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
raylib.DrawText("Drop your files to this window!", 100, 40, 20, raylib.DarkGray)
|
rl.DrawText("Drop your files to this window!", 100, 40, 20, rl.DarkGray)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("Dropped files:", 100, 40, 20, raylib.DarkGray)
|
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
||||||
|
|
||||||
for i := int32(0); i < count; i++ {
|
for i := int32(0); i < count; i++ {
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
raylib.DrawRectangle(0, int32(85+40*i), screenWidth, 40, raylib.Fade(raylib.LightGray, 0.5))
|
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawRectangle(0, int32(85+40*i), screenWidth, 40, raylib.Fade(raylib.LightGray, 0.3))
|
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.3))
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText(droppedFiles[i], 120, int32(100+i*40), 10, raylib.Gray)
|
rl.DrawText(droppedFiles[i], 120, int32(100), 10, rl.Gray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Drop new files...", 100, int32(150+count*40), 20, raylib.DarkGray)
|
rl.DrawText("Drop new files...", 100, int32(150), 20, rl.DarkGray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.ClearDroppedFiles()
|
rl.ClearDroppedFiles()
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,47 +12,47 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - gestures detection")
|
||||||
|
|
||||||
touchPosition := raylib.NewVector2(0, 0)
|
touchPosition := rl.NewVector2(0, 0)
|
||||||
touchArea := raylib.NewRectangle(220, 10, float32(screenWidth)-230, float32(screenHeight)-20)
|
touchArea := rl.NewRectangle(220, 10, float32(screenWidth)-230, float32(screenHeight)-20)
|
||||||
|
|
||||||
gestureStrings := make([]string, 0)
|
gestureStrings := make([]string, 0)
|
||||||
|
|
||||||
currentGesture := raylib.GestureNone
|
currentGesture := rl.GestureNone
|
||||||
lastGesture := raylib.GestureNone
|
lastGesture := rl.GestureNone
|
||||||
|
|
||||||
//raylib.SetGesturesEnabled(uint32(raylib.GestureHold | raylib.GestureDrag)) // Enable only some gestures to be detected
|
//rl.SetGesturesEnabled(uint32(rl.GestureHold | rl.GestureDrag)) // Enable only some gestures to be detected
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
lastGesture = currentGesture
|
lastGesture = currentGesture
|
||||||
currentGesture = raylib.GetGestureDetected()
|
currentGesture = rl.GetGestureDetected()
|
||||||
touchPosition = raylib.GetTouchPosition(0)
|
touchPosition = rl.GetTouchPosition(0)
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(touchPosition, touchArea) && currentGesture != raylib.GestureNone {
|
if rl.CheckCollisionPointRec(touchPosition, touchArea) && currentGesture != rl.GestureNone {
|
||||||
if currentGesture != lastGesture {
|
if currentGesture != lastGesture {
|
||||||
switch currentGesture {
|
switch currentGesture {
|
||||||
case raylib.GestureTap:
|
case rl.GestureTap:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE TAP")
|
gestureStrings = append(gestureStrings, "GESTURE TAP")
|
||||||
case raylib.GestureDoubletap:
|
case rl.GestureDoubletap:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE DOUBLETAP")
|
gestureStrings = append(gestureStrings, "GESTURE DOUBLETAP")
|
||||||
case raylib.GestureHold:
|
case rl.GestureHold:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE HOLD")
|
gestureStrings = append(gestureStrings, "GESTURE HOLD")
|
||||||
case raylib.GestureDrag:
|
case rl.GestureDrag:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE DRAG")
|
gestureStrings = append(gestureStrings, "GESTURE DRAG")
|
||||||
case raylib.GestureSwipeRight:
|
case rl.GestureSwipeRight:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE RIGHT")
|
gestureStrings = append(gestureStrings, "GESTURE SWIPE RIGHT")
|
||||||
case raylib.GestureSwipeLeft:
|
case rl.GestureSwipeLeft:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE LEFT")
|
gestureStrings = append(gestureStrings, "GESTURE SWIPE LEFT")
|
||||||
case raylib.GestureSwipeUp:
|
case rl.GestureSwipeUp:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE UP")
|
gestureStrings = append(gestureStrings, "GESTURE SWIPE UP")
|
||||||
case raylib.GestureSwipeDown:
|
case rl.GestureSwipeDown:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE SWIPE DOWN")
|
gestureStrings = append(gestureStrings, "GESTURE SWIPE DOWN")
|
||||||
case raylib.GesturePinchIn:
|
case rl.GesturePinchIn:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE PINCH IN")
|
gestureStrings = append(gestureStrings, "GESTURE PINCH IN")
|
||||||
case raylib.GesturePinchOut:
|
case rl.GesturePinchOut:
|
||||||
gestureStrings = append(gestureStrings, "GESTURE PINCH OUT")
|
gestureStrings = append(gestureStrings, "GESTURE PINCH OUT")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,38 +62,38 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawRectangleRec(touchArea, raylib.Gray)
|
rl.DrawRectangleRec(touchArea, rl.Gray)
|
||||||
raylib.DrawRectangle(225, 15, screenWidth-240, screenHeight-30, raylib.RayWhite)
|
rl.DrawRectangle(225, 15, screenWidth-240, screenHeight-30, rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("GESTURES TEST AREA", screenWidth-270, screenHeight-40, 20, raylib.Fade(raylib.Gray, 0.5))
|
rl.DrawText("GESTURES TEST AREA", screenWidth-270, screenHeight-40, 20, rl.Fade(rl.Gray, 0.5))
|
||||||
|
|
||||||
for i := 0; i < len(gestureStrings); i++ {
|
for i := 0; i < len(gestureStrings); i++ {
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
raylib.DrawRectangle(10, int32(30+20*i), 200, 20, raylib.Fade(raylib.LightGray, 0.5))
|
rl.DrawRectangle(10, int32(30+20*i), 200, 20, rl.Fade(rl.LightGray, 0.5))
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawRectangle(10, int32(30+20*i), 200, 20, raylib.Fade(raylib.LightGray, 0.3))
|
rl.DrawRectangle(10, int32(30+20*i), 200, 20, rl.Fade(rl.LightGray, 0.3))
|
||||||
}
|
}
|
||||||
|
|
||||||
if i < len(gestureStrings)-1 {
|
if i < len(gestureStrings)-1 {
|
||||||
raylib.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, raylib.DarkGray)
|
rl.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, rl.DarkGray)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, raylib.Maroon)
|
rl.DrawText(gestureStrings[i], 35, int32(36+20*i), 10, rl.Maroon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangleLines(10, 29, 200, screenHeight-50, raylib.Gray)
|
rl.DrawRectangleLines(10, 29, 200, screenHeight-50, rl.Gray)
|
||||||
raylib.DrawText("DETECTED GESTURES", 50, 15, 10, raylib.Gray)
|
rl.DrawText("DETECTED GESTURES", 50, 15, 10, rl.Gray)
|
||||||
|
|
||||||
if currentGesture != raylib.GestureNone {
|
if currentGesture != rl.GestureNone {
|
||||||
raylib.DrawCircleV(touchPosition, 30, raylib.Maroon)
|
rl.DrawCircleV(touchPosition, 30, rl.Maroon)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,190 +12,190 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Set MSAA 4X hint before windows creation
|
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Set MSAA 4X hint before windows creation
|
||||||
|
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - gamepad input")
|
rl.InitWindow(800, 450, "raylib [core] example - gamepad input")
|
||||||
|
|
||||||
texPs3Pad := raylib.LoadTexture("ps3.png")
|
texPs3Pad := rl.LoadTexture("ps3.png")
|
||||||
texXboxPad := raylib.LoadTexture("xbox.png")
|
texXboxPad := rl.LoadTexture("xbox.png")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
if raylib.IsGamepadAvailable(raylib.GamepadPlayer1) {
|
if rl.IsGamepadAvailable(rl.GamepadPlayer1) {
|
||||||
raylib.DrawText(fmt.Sprintf("GP1: %s", raylib.GetGamepadName(raylib.GamepadPlayer1)), 10, 10, 10, raylib.Black)
|
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(rl.GamepadPlayer1)), 10, 10, 10, rl.Black)
|
||||||
|
|
||||||
if raylib.IsGamepadName(raylib.GamepadPlayer1, xbox360NameID) {
|
if rl.IsGamepadName(rl.GamepadPlayer1, xbox360NameID) {
|
||||||
raylib.DrawTexture(texXboxPad, 0, 0, raylib.DarkGray)
|
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)
|
||||||
|
|
||||||
// Draw buttons: xbox home
|
// Draw buttons: xbox home
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonHome) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonHome) {
|
||||||
raylib.DrawCircle(394, 89, 19, raylib.Red)
|
rl.DrawCircle(394, 89, 19, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: basic
|
// Draw buttons: basic
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonStart) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonStart) {
|
||||||
raylib.DrawCircle(436, 150, 9, raylib.Red)
|
rl.DrawCircle(436, 150, 9, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonSelect) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonSelect) {
|
||||||
raylib.DrawCircle(352, 150, 9, raylib.Red)
|
rl.DrawCircle(352, 150, 9, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonX) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonX) {
|
||||||
raylib.DrawCircle(501, 151, 15, raylib.Blue)
|
rl.DrawCircle(501, 151, 15, rl.Blue)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonA) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonA) {
|
||||||
raylib.DrawCircle(536, 187, 15, raylib.Lime)
|
rl.DrawCircle(536, 187, 15, rl.Lime)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonB) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonB) {
|
||||||
raylib.DrawCircle(572, 151, 15, raylib.Maroon)
|
rl.DrawCircle(572, 151, 15, rl.Maroon)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonY) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonY) {
|
||||||
raylib.DrawCircle(536, 115, 15, raylib.Gold)
|
rl.DrawCircle(536, 115, 15, rl.Gold)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: d-pad
|
// Draw buttons: d-pad
|
||||||
raylib.DrawRectangle(317, 202, 19, 71, raylib.Black)
|
rl.DrawRectangle(317, 202, 19, 71, rl.Black)
|
||||||
raylib.DrawRectangle(293, 228, 69, 19, raylib.Black)
|
rl.DrawRectangle(293, 228, 69, 19, rl.Black)
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonUp) {
|
||||||
raylib.DrawRectangle(317, 202, 19, 26, raylib.Red)
|
rl.DrawRectangle(317, 202, 19, 26, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonDown) {
|
||||||
raylib.DrawRectangle(317, 202+45, 19, 26, raylib.Red)
|
rl.DrawRectangle(317, 202+45, 19, 26, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLeft) {
|
||||||
raylib.DrawRectangle(292, 228, 25, 19, raylib.Red)
|
rl.DrawRectangle(292, 228, 25, 19, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRight) {
|
||||||
raylib.DrawRectangle(292+44, 228, 26, 19, raylib.Red)
|
rl.DrawRectangle(292+44, 228, 26, 19, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: left-right back
|
// Draw buttons: left-right back
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonLb) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLb) {
|
||||||
raylib.DrawCircle(259, 61, 20, raylib.Red)
|
rl.DrawCircle(259, 61, 20, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadXboxButtonRb) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRb) {
|
||||||
raylib.DrawCircle(536, 61, 20, raylib.Red)
|
rl.DrawCircle(536, 61, 20, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw axis: left joystick
|
// Draw axis: left joystick
|
||||||
raylib.DrawCircle(259, 152, 39, raylib.Black)
|
rl.DrawCircle(259, 152, 39, rl.Black)
|
||||||
raylib.DrawCircle(259, 152, 34, raylib.LightGray)
|
rl.DrawCircle(259, 152, 34, rl.LightGray)
|
||||||
raylib.DrawCircle(int32(259+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLeftX)*20)),
|
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftX)*20)),
|
||||||
int32(152-(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLeftY)*20)), 25, raylib.Black)
|
int32(152-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: right joystick
|
// Draw axis: right joystick
|
||||||
raylib.DrawCircle(461, 237, 38, raylib.Black)
|
rl.DrawCircle(461, 237, 38, rl.Black)
|
||||||
raylib.DrawCircle(461, 237, 33, raylib.LightGray)
|
rl.DrawCircle(461, 237, 33, rl.LightGray)
|
||||||
raylib.DrawCircle(int32(461+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRightX)*20)),
|
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightX)*20)),
|
||||||
int32(237-(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRightY)*20)), 25, raylib.Black)
|
int32(237-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: left-right triggers
|
// Draw axis: left-right triggers
|
||||||
raylib.DrawRectangle(170, 30, 15, 70, raylib.Gray)
|
rl.DrawRectangle(170, 30, 15, 70, rl.Gray)
|
||||||
raylib.DrawRectangle(604, 30, 15, 70, raylib.Gray)
|
rl.DrawRectangle(604, 30, 15, 70, rl.Gray)
|
||||||
raylib.DrawRectangle(170, 30, 15, int32(((1.0+raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisLt))/2.0)*70), raylib.Red)
|
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLt))/2.0)*70), rl.Red)
|
||||||
raylib.DrawRectangle(604, 30, 15, int32(((1.0+raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadXboxAxisRt))/2.0)*70), raylib.Red)
|
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRt))/2.0)*70), rl.Red)
|
||||||
|
|
||||||
} else if raylib.IsGamepadName(raylib.GamepadPlayer1, ps3NameID) {
|
} else if rl.IsGamepadName(rl.GamepadPlayer1, ps3NameID) {
|
||||||
raylib.DrawTexture(texPs3Pad, 0, 0, raylib.DarkGray)
|
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)
|
||||||
|
|
||||||
// Draw buttons: ps
|
// Draw buttons: ps
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonPs) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonPs) {
|
||||||
raylib.DrawCircle(396, 222, 13, raylib.Red)
|
rl.DrawCircle(396, 222, 13, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: basic
|
// Draw buttons: basic
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonSelect) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSelect) {
|
||||||
raylib.DrawRectangle(328, 170, 32, 13, raylib.Red)
|
rl.DrawRectangle(328, 170, 32, 13, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonStart) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonStart) {
|
||||||
raylib.DrawTriangle(raylib.NewVector2(436, 168), raylib.NewVector2(436, 185), raylib.NewVector2(464, 177), raylib.Red)
|
rl.DrawTriangle(rl.NewVector2(436, 168), rl.NewVector2(436, 185), rl.NewVector2(464, 177), rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonTriangle) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonTriangle) {
|
||||||
raylib.DrawCircle(557, 144, 13, raylib.Lime)
|
rl.DrawCircle(557, 144, 13, rl.Lime)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonCircle) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCircle) {
|
||||||
raylib.DrawCircle(586, 173, 13, raylib.Red)
|
rl.DrawCircle(586, 173, 13, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonCross) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCross) {
|
||||||
raylib.DrawCircle(557, 203, 13, raylib.Violet)
|
rl.DrawCircle(557, 203, 13, rl.Violet)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonSquare) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSquare) {
|
||||||
raylib.DrawCircle(527, 173, 13, raylib.Pink)
|
rl.DrawCircle(527, 173, 13, rl.Pink)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: d-pad
|
// Draw buttons: d-pad
|
||||||
raylib.DrawRectangle(225, 132, 24, 84, raylib.Black)
|
rl.DrawRectangle(225, 132, 24, 84, rl.Black)
|
||||||
raylib.DrawRectangle(195, 161, 84, 25, raylib.Black)
|
rl.DrawRectangle(195, 161, 84, 25, rl.Black)
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonUp) {
|
||||||
raylib.DrawRectangle(225, 132, 24, 29, raylib.Red)
|
rl.DrawRectangle(225, 132, 24, 29, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonDown) {
|
||||||
raylib.DrawRectangle(225, 132+54, 24, 30, raylib.Red)
|
rl.DrawRectangle(225, 132+54, 24, 30, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonLeft) {
|
||||||
raylib.DrawRectangle(195, 161, 30, 25, raylib.Red)
|
rl.DrawRectangle(195, 161, 30, 25, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonRight) {
|
||||||
raylib.DrawRectangle(195+54, 161, 30, 25, raylib.Red)
|
rl.DrawRectangle(195+54, 161, 30, 25, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: left-right back buttons
|
// Draw buttons: left-right back buttons
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonL1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonL1) {
|
||||||
raylib.DrawCircle(239, 82, 20, raylib.Red)
|
rl.DrawCircle(239, 82, 20, rl.Red)
|
||||||
}
|
}
|
||||||
if raylib.IsGamepadButtonDown(raylib.GamepadPlayer1, raylib.GamepadPs3ButtonR1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonR1) {
|
||||||
raylib.DrawCircle(557, 82, 20, raylib.Red)
|
rl.DrawCircle(557, 82, 20, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw axis: left joystick
|
// Draw axis: left joystick
|
||||||
raylib.DrawCircle(319, 255, 35, raylib.Black)
|
rl.DrawCircle(319, 255, 35, rl.Black)
|
||||||
raylib.DrawCircle(319, 255, 31, raylib.LightGray)
|
rl.DrawCircle(319, 255, 31, rl.LightGray)
|
||||||
raylib.DrawCircle(int32(319+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisLeftX)*20)),
|
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftX)*20)),
|
||||||
int32(255+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisLeftY)*20)), 25, raylib.Black)
|
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: right joystick
|
// Draw axis: right joystick
|
||||||
raylib.DrawCircle(475, 255, 35, raylib.Black)
|
rl.DrawCircle(475, 255, 35, rl.Black)
|
||||||
raylib.DrawCircle(475, 255, 31, raylib.LightGray)
|
rl.DrawCircle(475, 255, 31, rl.LightGray)
|
||||||
raylib.DrawCircle(int32(475+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisRightX)*20)),
|
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightX)*20)),
|
||||||
int32(255+(raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisRightY)*20)), 25, raylib.Black)
|
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: left-right triggers
|
// Draw axis: left-right triggers
|
||||||
raylib.DrawRectangle(169, 48, 15, 70, raylib.Gray)
|
rl.DrawRectangle(169, 48, 15, 70, rl.Gray)
|
||||||
raylib.DrawRectangle(611, 48, 15, 70, raylib.Gray)
|
rl.DrawRectangle(611, 48, 15, 70, rl.Gray)
|
||||||
raylib.DrawRectangle(169, 48, 15, int32(((1.0-raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisL2))/2.0)*70), raylib.Red)
|
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisL2))/2.0)*70), rl.Red)
|
||||||
raylib.DrawRectangle(611, 48, 15, int32(((1.0-raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, raylib.GamepadPs3AxisR2))/2.0)*70), raylib.Red)
|
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisR2))/2.0)*70), rl.Red)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, raylib.Gray)
|
rl.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, rl.Gray)
|
||||||
|
|
||||||
// TODO: Draw generic gamepad
|
// TODO: Draw generic gamepad
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", raylib.GetGamepadAxisCount(raylib.GamepadPlayer1)), 10, 50, 10, raylib.Maroon)
|
rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(rl.GamepadPlayer1)), 10, 50, 10, rl.Maroon)
|
||||||
|
|
||||||
for i := int32(0); i < raylib.GetGamepadAxisCount(raylib.GamepadPlayer1); i++ {
|
for i := int32(0); i < rl.GetGamepadAxisCount(rl.GamepadPlayer1); i++ {
|
||||||
raylib.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, raylib.GetGamepadAxisMovement(raylib.GamepadPlayer1, i)), 20, 70+20*i, 10, raylib.DarkGray)
|
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(rl.GamepadPlayer1, i)), 20, 70+20*i, 10, rl.DarkGray)
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.GetGamepadButtonPressed() != -1 {
|
if rl.GetGamepadButtonPressed() != -1 {
|
||||||
raylib.DrawText(fmt.Sprintf("DETECTED BUTTON: %d", raylib.GetGamepadButtonPressed()), 10, 430, 10, raylib.Red)
|
rl.DrawText(fmt.Sprintf("DETECTED BUTTON: %d", rl.GetGamepadButtonPressed()), 10, 430, 10, rl.Red)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("DETECTED BUTTON: NONE", 10, 430, 10, raylib.Gray)
|
rl.DrawText("DETECTED BUTTON: NONE", 10, 430, 10, rl.Gray)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("GP1: NOT DETECTED", 10, 10, 10, raylib.Gray)
|
rl.DrawText("GP1: NOT DETECTED", 10, 10, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawTexture(texXboxPad, 0, 0, raylib.LightGray)
|
rl.DrawTexture(texXboxPad, 0, 0, rl.LightGray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texPs3Pad)
|
rl.UnloadTexture(texPs3Pad)
|
||||||
raylib.UnloadTexture(texXboxPad)
|
rl.UnloadTexture(texXboxPad)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,34 +8,34 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input")
|
||||||
|
|
||||||
ballPosition := raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2)
|
ballPosition := rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
if rl.IsKeyDown(rl.KeyRight) {
|
||||||
ballPosition.X += 0.8
|
ballPosition.X += 0.8
|
||||||
}
|
}
|
||||||
if raylib.IsKeyDown(raylib.KeyLeft) {
|
if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
ballPosition.X -= 0.8
|
ballPosition.X -= 0.8
|
||||||
}
|
}
|
||||||
if raylib.IsKeyDown(raylib.KeyUp) {
|
if rl.IsKeyDown(rl.KeyUp) {
|
||||||
ballPosition.Y -= 0.8
|
ballPosition.Y -= 0.8
|
||||||
}
|
}
|
||||||
if raylib.IsKeyDown(raylib.KeyDown) {
|
if rl.IsKeyDown(rl.KeyDown) {
|
||||||
ballPosition.Y += 0.8
|
ballPosition.Y += 0.8
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("move the ball with arrow keys", 10, 10, 20, raylib.DarkGray)
|
rl.DrawText("move the ball with arrow keys", 10, 10, 20, rl.DarkGray)
|
||||||
raylib.DrawCircleV(ballPosition, 50, raylib.Maroon)
|
rl.DrawCircleV(ballPosition, 50, rl.Maroon)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,31 +5,31 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - mouse input")
|
rl.InitWindow(800, 450, "raylib [core] example - mouse input")
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
ballColor := raylib.DarkBlue
|
ballColor := rl.DarkBlue
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
ballPosition := raylib.GetMousePosition()
|
ballPosition := rl.GetMousePosition()
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
ballColor = raylib.Maroon
|
ballColor = rl.Maroon
|
||||||
} else if raylib.IsMouseButtonPressed(raylib.MouseMiddleButton) {
|
} else if rl.IsMouseButtonPressed(rl.MouseMiddleButton) {
|
||||||
ballColor = raylib.Lime
|
ballColor = rl.Lime
|
||||||
} else if raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
|
} else if rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||||
ballColor = raylib.DarkBlue
|
ballColor = rl.DarkBlue
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
raylib.DrawCircleV(ballPosition, 40, ballColor)
|
rl.DrawCircleV(ballPosition, 40, ballColor)
|
||||||
|
|
||||||
raylib.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, raylib.DarkGray)
|
rl.DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,27 +10,27 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse wheel")
|
||||||
|
|
||||||
boxPositionY := screenHeight/2 - 40
|
boxPositionY := screenHeight/2 - 40
|
||||||
scrollSpeed := int32(4) // Scrolling speed in pixels
|
scrollSpeed := int32(4) // Scrolling speed in pixels
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
boxPositionY -= raylib.GetMouseWheelMove() * scrollSpeed
|
boxPositionY -= rl.GetMouseWheelMove() * scrollSpeed
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawRectangle(screenWidth/2-40, boxPositionY, 80, 80, raylib.Maroon)
|
rl.DrawRectangle(screenWidth/2-40, boxPositionY, 80, 80, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawText("Use mouse wheel to move the square up and down!", 10, 10, 20, raylib.Gray)
|
rl.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, rl.Gray)
|
||||||
raylib.DrawText(fmt.Sprintf("Box position Y: %d", boxPositionY), 10, 40, 20, raylib.LightGray)
|
rl.DrawText(fmt.Sprintf("Box position Y: %d", boxPositionY), 10, 40, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,32 +7,32 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - generate random values")
|
rl.InitWindow(800, 450, "raylib [core] example - generate random values")
|
||||||
|
|
||||||
framesCounter := 0 // Variable used to count frames
|
framesCounter := 0 // Variable used to count frames
|
||||||
randValue := raylib.GetRandomValue(-8, 5) // Get a random integer number between -8 and 5 (both included)
|
randValue := rl.GetRandomValue(-8, 5) // Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
framesCounter++
|
framesCounter++
|
||||||
|
|
||||||
// Every two seconds (120 frames) a new random value is generated
|
// Every two seconds (120 frames) a new random value is generated
|
||||||
if ((framesCounter / 120) % 2) == 1 {
|
if ((framesCounter / 120) % 2) == 1 {
|
||||||
randValue = raylib.GetRandomValue(-8, 5)
|
randValue = rl.GetRandomValue(-8, 5)
|
||||||
framesCounter = 0
|
framesCounter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, raylib.Maroon)
|
rl.DrawText("Every 2 seconds a new random value is generated:", 130, 100, 20, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("%d", randValue), 360, 180, 80, raylib.LightGray)
|
rl.DrawText(fmt.Sprintf("%d", randValue), 360, 180, 80, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,47 +12,47 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
rl.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
||||||
|
|
||||||
score := int32(0)
|
score := int32(0)
|
||||||
hiscore := int32(0)
|
hiscore := int32(0)
|
||||||
|
|
||||||
framesCounter := 0
|
framesCounter := 0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
if rl.IsKeyPressed(rl.KeyR) {
|
||||||
score = raylib.GetRandomValue(1000, 2000)
|
score = rl.GetRandomValue(1000, 2000)
|
||||||
hiscore = raylib.GetRandomValue(2000, 4000)
|
hiscore = rl.GetRandomValue(2000, 4000)
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
raylib.StorageSaveValue(storageScore, score)
|
rl.StorageSaveValue(storageScore, score)
|
||||||
raylib.StorageSaveValue(storageHiscore, hiscore)
|
rl.StorageSaveValue(storageHiscore, hiscore)
|
||||||
} else if raylib.IsKeyPressed(raylib.KeySpace) {
|
} else if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
// NOTE: If requested position could not be found, value 0 is returned
|
// NOTE: If requested position could not be found, value 0 is returned
|
||||||
score = raylib.StorageLoadValue(storageScore)
|
score = rl.StorageLoadValue(storageScore)
|
||||||
hiscore = raylib.StorageLoadValue(storageHiscore)
|
hiscore = rl.StorageLoadValue(storageHiscore)
|
||||||
}
|
}
|
||||||
|
|
||||||
framesCounter++
|
framesCounter++
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, raylib.Maroon)
|
rl.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, rl.Maroon)
|
||||||
raylib.DrawText(fmt.Sprintf("HI-SCORE: %d", hiscore), 210, 200, 50, raylib.Black)
|
rl.DrawText(fmt.Sprintf("HI-SCORE: %d", hiscore), 210, 200, 50, rl.Black)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("frames: %d", framesCounter), 10, 10, 20, raylib.Lime)
|
rl.DrawText(fmt.Sprintf("frames: %d", framesCounter), 10, 10, 20, rl.Lime)
|
||||||
|
|
||||||
raylib.DrawText("Press R to generate random numbers", 220, 40, 20, raylib.LightGray)
|
rl.DrawText("Press R to generate random numbers", 220, 40, 20, rl.LightGray)
|
||||||
raylib.DrawText("Press ENTER to SAVE values", 250, 310, 20, raylib.LightGray)
|
rl.DrawText("Press ENTER to SAVE values", 250, 310, 20, rl.LightGray)
|
||||||
raylib.DrawText("Press SPACE to LOAD values", 252, 350, 20, raylib.LightGray)
|
rl.DrawText("Press SPACE to LOAD values", 252, 350, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,50 +5,54 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
hmd := raylib.GetVrDeviceInfo(raylib.HmdOculusRiftCv1) // Oculus Rift CV1
|
screenWidth := int32(1080)
|
||||||
raylib.InitWindow(int32(hmd.HScreenSize), int32(hmd.VScreenSize), "raylib [core] example - vr simulator")
|
screenHeight := int32(600)
|
||||||
|
|
||||||
|
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||||
|
|
||||||
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
||||||
|
|
||||||
// NOTE: default device (simulator)
|
// NOTE: default device (simulator)
|
||||||
raylib.InitVrSimulator(hmd) // Init VR device
|
rl.InitVrSimulator(rl.GetVrDeviceInfo(rl.HmdOculusRiftCv1)) // Init VR device (Oculus Rift CV1)
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(5.0, 2.0, 5.0) // Camera position
|
camera.Position = rl.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
camera.Target = rl.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||||
camera.Fovy = 60.0 // Camera field-of-view Y
|
camera.Fovy = 60.0 // Camera field-of-view Y
|
||||||
|
|
||||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFirstPerson) // Set first person camera mode
|
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set first person camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(90)
|
rl.SetTargetFPS(90)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera (simulator mode)
|
rl.UpdateCamera(&camera) // Update camera (simulator mode)
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginVrDrawing()
|
rl.BeginVrDrawing()
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawGrid(40, 1.0)
|
rl.DrawGrid(40, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.EndVrDrawing()
|
rl.EndVrDrawing()
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseVrSimulator() // Close VR simulator
|
rl.CloseVrSimulator() // Close VR simulator
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(10.0, 10.0, 10.0) // Camera position
|
camera.Position = rl.NewVector3(10.0, 10.0, 10.0) // Camera position
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0) // Camera looking at point
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0) // Camera looking at point
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||||
camera.Fovy = 45.0 // Camera field-of-view Y
|
camera.Fovy = 45.0 // Camera field-of-view Y
|
||||||
|
|
||||||
cubePosition := raylib.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
cubeScreenPosition := raylib.Vector2{}
|
cubeScreenPosition := rl.Vector2{}
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set a free camera mode
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Calculate cube screen space position (with a little offset to be in top)
|
// Calculate cube screen space position (with a little offset to be in top)
|
||||||
cubeScreenPosition = raylib.GetWorldToScreen(raylib.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
cubeScreenPosition = rl.GetWorldToScreen(rl.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawCube(cubePosition, 2.0, 2.0, 2.0, raylib.Red)
|
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||||
raylib.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, raylib.Maroon)
|
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0)
|
rl.DrawGrid(10, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("Enemy: 100 / 100", int32(cubeScreenPosition.X)-raylib.MeasureText("Enemy: 100 / 100", 20)/2, int32(cubeScreenPosition.Y), 20, raylib.Black)
|
rl.DrawText("Enemy: 100 / 100", int32(cubeScreenPosition.X)-rl.MeasureText("Enemy: 100 / 100", 20)/2, int32(cubeScreenPosition.Y), 20, rl.Black)
|
||||||
raylib.DrawText("Text is always on top of the cube", (screenWidth-raylib.MeasureText("Text is always on top of the cube", 20))/2, 25, 20, raylib.Gray)
|
rl.DrawText("Text is always on top of the cube", (screenWidth-rl.MeasureText("Text is always on top of the cube", 20))/2, 25, 20, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [easings] example - easings")
|
||||||
|
|
||||||
currentTime := 0
|
currentTime := 0
|
||||||
duration := float32(60)
|
duration := float32(60)
|
||||||
|
@ -19,7 +19,7 @@ func main() {
|
||||||
finalPositionX := startPositionX * 3
|
finalPositionX := startPositionX * 3
|
||||||
currentPositionX := startPositionX
|
currentPositionX := startPositionX
|
||||||
|
|
||||||
ballPosition := raylib.NewVector2(startPositionX, float32(screenHeight)/2)
|
ballPosition := rl.NewVector2(startPositionX, float32(screenHeight)/2)
|
||||||
|
|
||||||
comboActive := 0
|
comboActive := 0
|
||||||
comboLastActive := 0
|
comboLastActive := 0
|
||||||
|
@ -27,10 +27,10 @@ func main() {
|
||||||
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
|
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
|
||||||
ease := easingTypes[comboActive]
|
ease := easingTypes[comboActive]
|
||||||
|
|
||||||
//raylib.SetTargetFPS(60)
|
//rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyDown(raylib.KeyR) {
|
if rl.IsKeyDown(rl.KeyR) {
|
||||||
currentTime = 0
|
currentTime = 0
|
||||||
currentPositionX = startPositionX
|
currentPositionX = startPositionX
|
||||||
ballPosition.X = currentPositionX
|
ballPosition.X = currentPositionX
|
||||||
|
@ -71,18 +71,18 @@ func main() {
|
||||||
currentTime++
|
currentTime++
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
raygui.Label(rl.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
||||||
comboActive = raygui.ComboBox(raylib.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
|
comboActive = raygui.ComboBox(rl.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
raygui.Label(rl.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
||||||
|
|
||||||
raylib.DrawCircleV(ballPosition, 50, raylib.Maroon)
|
rl.DrawCircleV(ballPosition, 50, rl.Maroon)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,20 +35,20 @@ const (
|
||||||
|
|
||||||
// Floppy type
|
// Floppy type
|
||||||
type Floppy struct {
|
type Floppy struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipe type
|
// Pipe type
|
||||||
type Pipe struct {
|
type Pipe struct {
|
||||||
Rec raylib.Rectangle
|
Rec rl.Rectangle
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
Active bool
|
Active bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Particle type
|
// Particle type
|
||||||
type Particle struct {
|
type Particle struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
Alpha float32
|
Alpha float32
|
||||||
Size float32
|
Size float32
|
||||||
Rotation float32
|
Rotation float32
|
||||||
|
@ -57,17 +57,17 @@ type Particle struct {
|
||||||
|
|
||||||
// Game type
|
// Game type
|
||||||
type Game struct {
|
type Game struct {
|
||||||
FxFlap raylib.Sound
|
FxFlap rl.Sound
|
||||||
FxSlap raylib.Sound
|
FxSlap rl.Sound
|
||||||
FxPoint raylib.Sound
|
FxPoint rl.Sound
|
||||||
FxClick raylib.Sound
|
FxClick rl.Sound
|
||||||
|
|
||||||
TxSprites raylib.Texture2D
|
TxSprites rl.Texture2D
|
||||||
TxSmoke raylib.Texture2D
|
TxSmoke rl.Texture2D
|
||||||
TxClouds raylib.Texture2D
|
TxClouds rl.Texture2D
|
||||||
|
|
||||||
CloudRec raylib.Rectangle
|
CloudRec rl.Rectangle
|
||||||
FrameRec raylib.Rectangle
|
FrameRec rl.Rectangle
|
||||||
|
|
||||||
GameOver bool
|
GameOver bool
|
||||||
Dead bool
|
Dead bool
|
||||||
|
@ -84,7 +84,7 @@ type Game struct {
|
||||||
Particles []Particle
|
Particles []Particle
|
||||||
|
|
||||||
Pipes []Pipe
|
Pipes []Pipe
|
||||||
PipesPos []raylib.Vector2
|
PipesPos []rl.Vector2
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGame - Start new game
|
// NewGame - Start new game
|
||||||
|
@ -95,7 +95,7 @@ func NewGame() (g Game) {
|
||||||
|
|
||||||
// On Android this sets callback function to be used for android_main
|
// On Android this sets callback function to be used for android_main
|
||||||
func init() {
|
func init() {
|
||||||
raylib.SetCallbackFunc(main)
|
rl.SetCallbackFunc(main)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -104,16 +104,16 @@ func main() {
|
||||||
game.GameOver = true
|
game.GameOver = true
|
||||||
|
|
||||||
// Initialize window
|
// Initialize window
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "Floppy Gopher")
|
rl.InitWindow(screenWidth, screenHeight, "Floppy Gopher")
|
||||||
|
|
||||||
// Initialize audio
|
// Initialize audio
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
// NOTE: Textures and Sounds MUST be loaded after Window/Audio initialization
|
// NOTE: Textures and Sounds MUST be loaded after Window/Audio initialization
|
||||||
game.Load()
|
game.Load()
|
||||||
|
|
||||||
// Limit FPS
|
// Limit FPS
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
for !game.WindowShouldClose {
|
for !game.WindowShouldClose {
|
||||||
|
@ -128,10 +128,10 @@ func main() {
|
||||||
game.Unload()
|
game.Unload()
|
||||||
|
|
||||||
// Close audio
|
// Close audio
|
||||||
raylib.CloseAudioDevice()
|
rl.CloseAudioDevice()
|
||||||
|
|
||||||
// Close window
|
// Close window
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
|
|
||||||
// Exit
|
// Exit
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -141,37 +141,37 @@ func main() {
|
||||||
func (g *Game) Init() {
|
func (g *Game) Init() {
|
||||||
|
|
||||||
// Gopher
|
// Gopher
|
||||||
g.Floppy = Floppy{raylib.NewVector2(80, float32(screenHeight)/2-spriteSize/2)}
|
g.Floppy = Floppy{rl.NewVector2(80, float32(screenHeight)/2-spriteSize/2)}
|
||||||
|
|
||||||
// Sprite rectangle
|
// Sprite rectangle
|
||||||
g.FrameRec = raylib.NewRectangle(0, 0, spriteSize, spriteSize)
|
g.FrameRec = rl.NewRectangle(0, 0, spriteSize, spriteSize)
|
||||||
|
|
||||||
// Cloud rectangle
|
// Cloud rectangle
|
||||||
g.CloudRec = raylib.NewRectangle(0, 0, float32(screenWidth), float32(g.TxClouds.Height))
|
g.CloudRec = rl.NewRectangle(0, 0, float32(screenWidth), float32(g.TxClouds.Height))
|
||||||
|
|
||||||
// Initialize particles
|
// Initialize particles
|
||||||
g.Particles = make([]Particle, maxParticles)
|
g.Particles = make([]Particle, maxParticles)
|
||||||
for i := 0; i < maxParticles; i++ {
|
for i := 0; i < maxParticles; i++ {
|
||||||
g.Particles[i].Position = raylib.NewVector2(0, 0)
|
g.Particles[i].Position = rl.NewVector2(0, 0)
|
||||||
g.Particles[i].Color = raylib.RayWhite
|
g.Particles[i].Color = rl.RayWhite
|
||||||
g.Particles[i].Alpha = 1.0
|
g.Particles[i].Alpha = 1.0
|
||||||
g.Particles[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
|
g.Particles[i].Size = float32(rl.GetRandomValue(1, 30)) / 20.0
|
||||||
g.Particles[i].Rotation = float32(raylib.GetRandomValue(0, 360))
|
g.Particles[i].Rotation = float32(rl.GetRandomValue(0, 360))
|
||||||
g.Particles[i].Active = false
|
g.Particles[i].Active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipes positions
|
// Pipes positions
|
||||||
g.PipesPos = make([]raylib.Vector2, maxPipes)
|
g.PipesPos = make([]rl.Vector2, maxPipes)
|
||||||
for i := 0; i < maxPipes; i++ {
|
for i := 0; i < maxPipes; i++ {
|
||||||
g.PipesPos[i].X = float32(480 + 360*i)
|
g.PipesPos[i].X = float32(480 + 360*i)
|
||||||
g.PipesPos[i].Y = -float32(raylib.GetRandomValue(0, 240))
|
g.PipesPos[i].Y = -float32(rl.GetRandomValue(0, 240))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipes colors
|
// Pipes colors
|
||||||
colors := []raylib.Color{
|
colors := []rl.Color{
|
||||||
raylib.Orange, raylib.Red, raylib.Gold, raylib.Lime,
|
rl.Orange, rl.Red, rl.Gold, rl.Lime,
|
||||||
raylib.Violet, raylib.Brown, raylib.LightGray, raylib.Blue,
|
rl.Violet, rl.Brown, rl.LightGray, rl.Blue,
|
||||||
raylib.Yellow, raylib.Green, raylib.Purple, raylib.Beige,
|
rl.Yellow, rl.Green, rl.Purple, rl.Beige,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pipes
|
// Pipes
|
||||||
|
@ -181,7 +181,7 @@ func (g *Game) Init() {
|
||||||
g.Pipes[i].Rec.Y = g.PipesPos[i/2].Y
|
g.Pipes[i].Rec.Y = g.PipesPos[i/2].Y
|
||||||
g.Pipes[i].Rec.Width = pipesWidth
|
g.Pipes[i].Rec.Width = pipesWidth
|
||||||
g.Pipes[i].Rec.Height = 550
|
g.Pipes[i].Rec.Height = 550
|
||||||
g.Pipes[i].Color = colors[raylib.GetRandomValue(0, int32(len(colors)-1))]
|
g.Pipes[i].Color = colors[rl.GetRandomValue(0, int32(len(colors)-1))]
|
||||||
|
|
||||||
g.Pipes[i+1].Rec.X = g.PipesPos[i/2].X
|
g.Pipes[i+1].Rec.X = g.PipesPos[i/2].X
|
||||||
g.Pipes[i+1].Rec.Y = 1200 + g.PipesPos[i/2].Y - 550
|
g.Pipes[i+1].Rec.Y = 1200 + g.PipesPos[i/2].Y - 550
|
||||||
|
@ -203,35 +203,35 @@ func (g *Game) Init() {
|
||||||
|
|
||||||
// Load - Load resources
|
// Load - Load resources
|
||||||
func (g *Game) Load() {
|
func (g *Game) Load() {
|
||||||
g.FxFlap = raylib.LoadSound("sounds/flap.wav")
|
g.FxFlap = rl.LoadSound("sounds/flap.wav")
|
||||||
g.FxSlap = raylib.LoadSound("sounds/slap.wav")
|
g.FxSlap = rl.LoadSound("sounds/slap.wav")
|
||||||
g.FxPoint = raylib.LoadSound("sounds/point.wav")
|
g.FxPoint = rl.LoadSound("sounds/point.wav")
|
||||||
g.FxClick = raylib.LoadSound("sounds/click.wav")
|
g.FxClick = rl.LoadSound("sounds/click.wav")
|
||||||
g.TxSprites = raylib.LoadTexture("images/sprite.png")
|
g.TxSprites = rl.LoadTexture("images/sprite.png")
|
||||||
g.TxSmoke = raylib.LoadTexture("images/smoke.png")
|
g.TxSmoke = rl.LoadTexture("images/smoke.png")
|
||||||
g.TxClouds = raylib.LoadTexture("images/clouds.png")
|
g.TxClouds = rl.LoadTexture("images/clouds.png")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unload - Unload resources
|
// Unload - Unload resources
|
||||||
func (g *Game) Unload() {
|
func (g *Game) Unload() {
|
||||||
raylib.UnloadSound(g.FxFlap)
|
rl.UnloadSound(g.FxFlap)
|
||||||
raylib.UnloadSound(g.FxSlap)
|
rl.UnloadSound(g.FxSlap)
|
||||||
raylib.UnloadSound(g.FxPoint)
|
rl.UnloadSound(g.FxPoint)
|
||||||
raylib.UnloadSound(g.FxClick)
|
rl.UnloadSound(g.FxClick)
|
||||||
raylib.UnloadTexture(g.TxSprites)
|
rl.UnloadTexture(g.TxSprites)
|
||||||
raylib.UnloadTexture(g.TxSmoke)
|
rl.UnloadTexture(g.TxSmoke)
|
||||||
raylib.UnloadTexture(g.TxClouds)
|
rl.UnloadTexture(g.TxClouds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update - Update game
|
// Update - Update game
|
||||||
func (g *Game) Update() {
|
func (g *Game) Update() {
|
||||||
if raylib.WindowShouldClose() {
|
if rl.WindowShouldClose() {
|
||||||
g.WindowShouldClose = true
|
g.WindowShouldClose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !g.GameOver {
|
if !g.GameOver {
|
||||||
if raylib.IsKeyPressed(raylib.KeyP) || raylib.IsKeyPressed(raylib.KeyBack) {
|
if rl.IsKeyPressed(rl.KeyP) || rl.IsKeyPressed(rl.KeyBack) {
|
||||||
raylib.PlaySound(g.FxClick)
|
rl.PlaySound(g.FxClick)
|
||||||
|
|
||||||
if runtime.GOOS == "android" && g.Pause {
|
if runtime.GOOS == "android" && g.Pause {
|
||||||
g.WindowShouldClose = true
|
g.WindowShouldClose = true
|
||||||
|
@ -259,8 +259,8 @@ func (g *Game) Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Movement/Controls
|
// Movement/Controls
|
||||||
if raylib.IsKeyDown(raylib.KeySpace) || raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsKeyDown(rl.KeySpace) || rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
raylib.PlaySound(g.FxFlap)
|
rl.PlaySound(g.FxFlap)
|
||||||
|
|
||||||
// Activate one particle every frame
|
// Activate one particle every frame
|
||||||
for i := 0; i < maxParticles; i++ {
|
for i := 0; i < maxParticles; i++ {
|
||||||
|
@ -315,11 +315,11 @@ func (g *Game) Update() {
|
||||||
|
|
||||||
// Check Collisions
|
// Check Collisions
|
||||||
for i := 0; i < maxPipes*2; i++ {
|
for i := 0; i < maxPipes*2; i++ {
|
||||||
if raylib.CheckCollisionRecs(raylib.NewRectangle(g.Floppy.Position.X, g.Floppy.Position.Y, spriteSize, spriteSize), g.Pipes[i].Rec) {
|
if rl.CheckCollisionRecs(rl.NewRectangle(g.Floppy.Position.X, g.Floppy.Position.Y, spriteSize, spriteSize), g.Pipes[i].Rec) {
|
||||||
// OMG You killed Gopher you bastard!
|
// OMG You killed Gopher you bastard!
|
||||||
g.Dead = true
|
g.Dead = true
|
||||||
|
|
||||||
raylib.PlaySound(g.FxSlap)
|
rl.PlaySound(g.FxSlap)
|
||||||
} else if (g.PipesPos[i/2].X < g.Floppy.Position.X-spriteSize) && g.Pipes[i/2].Active && !g.GameOver {
|
} else if (g.PipesPos[i/2].X < g.Floppy.Position.X-spriteSize) && g.Pipes[i/2].Active && !g.GameOver {
|
||||||
// Score point
|
// Score point
|
||||||
g.Score += 1
|
g.Score += 1
|
||||||
|
@ -333,7 +333,7 @@ func (g *Game) Update() {
|
||||||
g.HiScore = g.Score
|
g.HiScore = g.Score
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.PlaySound(g.FxPoint)
|
rl.PlaySound(g.FxPoint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,17 +351,17 @@ func (g *Game) Update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
g.Pause = !g.Pause
|
g.Pause = !g.Pause
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if raylib.IsKeyPressed(raylib.KeyEnter) || raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsKeyPressed(rl.KeyEnter) || rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
raylib.PlaySound(g.FxClick)
|
rl.PlaySound(g.FxClick)
|
||||||
|
|
||||||
// Return of the Gopher!
|
// Return of the Gopher!
|
||||||
g.Init()
|
g.Init()
|
||||||
} else if runtime.GOOS == "android" && raylib.IsKeyDown(raylib.KeyBack) {
|
} else if runtime.GOOS == "android" && rl.IsKeyDown(rl.KeyBack) {
|
||||||
g.WindowShouldClose = true
|
g.WindowShouldClose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,32 +379,32 @@ func (g *Game) Update() {
|
||||||
|
|
||||||
// Draw - Draw game
|
// Draw - Draw game
|
||||||
func (g *Game) Draw() {
|
func (g *Game) Draw() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.SkyBlue)
|
rl.ClearBackground(rl.SkyBlue)
|
||||||
|
|
||||||
if !g.GameOver {
|
if !g.GameOver {
|
||||||
// Draw clouds
|
// Draw clouds
|
||||||
raylib.DrawTextureRec(g.TxClouds, g.CloudRec, raylib.NewVector2(0, float32(screenHeight-g.TxClouds.Height)), raylib.RayWhite)
|
rl.DrawTextureRec(g.TxClouds, g.CloudRec, rl.NewVector2(0, float32(screenHeight-g.TxClouds.Height)), rl.RayWhite)
|
||||||
|
|
||||||
// Draw rotated clouds
|
// Draw rotated clouds
|
||||||
raylib.DrawTexturePro(g.TxClouds, raylib.NewRectangle(-g.CloudRec.X, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)),
|
rl.DrawTexturePro(g.TxClouds, rl.NewRectangle(-g.CloudRec.X, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)),
|
||||||
raylib.NewRectangle(0, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)), raylib.NewVector2(float32(g.TxClouds.Width), float32(g.TxClouds.Height)), 180, raylib.White)
|
rl.NewRectangle(0, 0, float32(g.TxClouds.Width), float32(g.TxClouds.Height)), rl.NewVector2(float32(g.TxClouds.Width), float32(g.TxClouds.Height)), 180, rl.White)
|
||||||
|
|
||||||
// Draw Gopher
|
// Draw Gopher
|
||||||
raylib.DrawTextureRec(g.TxSprites, g.FrameRec, g.Floppy.Position, raylib.RayWhite)
|
rl.DrawTextureRec(g.TxSprites, g.FrameRec, g.Floppy.Position, rl.RayWhite)
|
||||||
|
|
||||||
// Draw active particles
|
// Draw active particles
|
||||||
if !g.Dead {
|
if !g.Dead {
|
||||||
for i := 0; i < maxParticles; i++ {
|
for i := 0; i < maxParticles; i++ {
|
||||||
if g.Particles[i].Active {
|
if g.Particles[i].Active {
|
||||||
raylib.DrawTexturePro(
|
rl.DrawTexturePro(
|
||||||
g.TxSmoke,
|
g.TxSmoke,
|
||||||
raylib.NewRectangle(0, 0, float32(g.TxSmoke.Width), float32(g.TxSmoke.Height)),
|
rl.NewRectangle(0, 0, float32(g.TxSmoke.Width), float32(g.TxSmoke.Height)),
|
||||||
raylib.NewRectangle(g.Particles[i].Position.X, g.Particles[i].Position.Y, float32(g.TxSmoke.Width)*g.Particles[i].Size, float32(g.TxSmoke.Height)*g.Particles[i].Size),
|
rl.NewRectangle(g.Particles[i].Position.X, g.Particles[i].Position.Y, float32(g.TxSmoke.Width)*g.Particles[i].Size, float32(g.TxSmoke.Height)*g.Particles[i].Size),
|
||||||
raylib.NewVector2(float32(g.TxSmoke.Width)*g.Particles[i].Size/2, float32(g.TxSmoke.Height)*g.Particles[i].Size/2),
|
rl.NewVector2(float32(g.TxSmoke.Width)*g.Particles[i].Size/2, float32(g.TxSmoke.Height)*g.Particles[i].Size/2),
|
||||||
g.Particles[i].Rotation,
|
g.Particles[i].Rotation,
|
||||||
raylib.Fade(g.Particles[i].Color, g.Particles[i].Alpha),
|
rl.Fade(g.Particles[i].Color, g.Particles[i].Alpha),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,41 +412,41 @@ func (g *Game) Draw() {
|
||||||
|
|
||||||
// Draw pipes
|
// Draw pipes
|
||||||
for i := 0; i < maxPipes; i++ {
|
for i := 0; i < maxPipes; i++ {
|
||||||
raylib.DrawRectangle(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), g.Pipes[i*2].Color)
|
rl.DrawRectangle(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), g.Pipes[i*2].Color)
|
||||||
raylib.DrawRectangle(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), g.Pipes[i*2].Color)
|
rl.DrawRectangle(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), g.Pipes[i*2].Color)
|
||||||
|
|
||||||
// Draw borders
|
// Draw borders
|
||||||
raylib.DrawRectangleLines(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), raylib.Black)
|
rl.DrawRectangleLines(int32(g.Pipes[i*2].Rec.X), int32(g.Pipes[i*2].Rec.Y), int32(g.Pipes[i*2].Rec.Width), int32(g.Pipes[i*2].Rec.Height), rl.Black)
|
||||||
raylib.DrawRectangleLines(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), raylib.Black)
|
rl.DrawRectangleLines(int32(g.Pipes[i*2+1].Rec.X), int32(g.Pipes[i*2+1].Rec.Y), int32(g.Pipes[i*2+1].Rec.Width), int32(g.Pipes[i*2+1].Rec.Height), rl.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw Super Flashing FX (one frame only)
|
// Draw Super Flashing FX (one frame only)
|
||||||
if g.SuperFX {
|
if g.SuperFX {
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.White)
|
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.White)
|
||||||
g.SuperFX = false
|
g.SuperFX = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw HI-SCORE
|
// Draw HI-SCORE
|
||||||
raylib.DrawText(fmt.Sprintf("%02d", g.Score), 20, 20, 32, raylib.Black)
|
rl.DrawText(fmt.Sprintf("%02d", g.Score), 20, 20, 32, rl.Black)
|
||||||
raylib.DrawText(fmt.Sprintf("HI-SCORE: %02d", g.HiScore), 20, 64, 20, raylib.Black)
|
rl.DrawText(fmt.Sprintf("HI-SCORE: %02d", g.HiScore), 20, 64, 20, rl.Black)
|
||||||
|
|
||||||
if g.Pause {
|
if g.Pause {
|
||||||
// Draw PAUSED text
|
// Draw PAUSED text
|
||||||
raylib.DrawText("PAUSED", screenWidth/2-raylib.MeasureText("PAUSED", 24)/2, screenHeight/2-50, 20, raylib.Black)
|
rl.DrawText("PAUSED", screenWidth/2-rl.MeasureText("PAUSED", 24)/2, screenHeight/2-50, 20, rl.Black)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Draw text
|
// Draw text
|
||||||
raylib.DrawText("Floppy Gopher", raylib.GetScreenWidth()/2-raylib.MeasureText("Floppy Gopher", 40)/2, raylib.GetScreenHeight()/2-150, 40, raylib.RayWhite)
|
rl.DrawText("Floppy Gopher", rl.GetScreenWidth()/2-rl.MeasureText("Floppy Gopher", 40)/2, rl.GetScreenHeight()/2-150, 40, rl.RayWhite)
|
||||||
|
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
raylib.DrawText("[TAP] TO PLAY", raylib.GetScreenWidth()/2-raylib.MeasureText("[TAP] TO PLAY", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Black)
|
rl.DrawText("[TAP] TO PLAY", rl.GetScreenWidth()/2-rl.MeasureText("[TAP] TO PLAY", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Black)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("[ENTER] TO PLAY", raylib.GetScreenWidth()/2-raylib.MeasureText("[ENTER] TO PLAY", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Black)
|
rl.DrawText("[ENTER] TO PLAY", rl.GetScreenWidth()/2-rl.MeasureText("[ENTER] TO PLAY", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw Gopher
|
// Draw Gopher
|
||||||
raylib.DrawTextureRec(g.TxSprites, g.FrameRec, raylib.NewVector2(float32(raylib.GetScreenWidth()/2-spriteSize/2), float32(raylib.GetScreenHeight()/2)), raylib.RayWhite)
|
rl.DrawTextureRec(g.TxSprites, g.FrameRec, rl.NewVector2(float32(rl.GetScreenWidth()/2-spriteSize/2), float32(rl.GetScreenHeight()/2)), rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ const (
|
||||||
|
|
||||||
// Cell type
|
// Cell type
|
||||||
type Cell struct {
|
type Cell struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Size raylib.Vector2
|
Size rl.Vector2
|
||||||
Alive bool
|
Alive bool
|
||||||
Next bool
|
Next bool
|
||||||
Visited bool
|
Visited bool
|
||||||
|
@ -37,10 +37,10 @@ func main() {
|
||||||
game := Game{}
|
game := Game{}
|
||||||
game.Init(false)
|
game.Init(false)
|
||||||
|
|
||||||
raylib.InitWindow(game.ScreenWidth, game.ScreenHeight, "Conway's Game of Life")
|
rl.InitWindow(game.ScreenWidth, game.ScreenHeight, "Conway's Game of Life")
|
||||||
raylib.SetTargetFPS(20)
|
rl.SetTargetFPS(20)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if game.Playing {
|
if game.Playing {
|
||||||
game.Update()
|
game.Update()
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ func main() {
|
||||||
game.Draw()
|
game.Draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init - Initialize game
|
// Init - Initialize game
|
||||||
|
@ -70,8 +70,8 @@ func (g *Game) Init(clear bool) {
|
||||||
for x := int32(0); x <= g.Cols; x++ {
|
for x := int32(0); x <= g.Cols; x++ {
|
||||||
for y := int32(0); y <= g.Rows; y++ {
|
for y := int32(0); y <= g.Rows; y++ {
|
||||||
g.Cells[x][y] = &Cell{}
|
g.Cells[x][y] = &Cell{}
|
||||||
g.Cells[x][y].Position = raylib.NewVector2((float32(x) * squareSize), (float32(y)*squareSize)+1)
|
g.Cells[x][y].Position = rl.NewVector2((float32(x) * squareSize), (float32(y)*squareSize)+1)
|
||||||
g.Cells[x][y].Size = raylib.NewVector2(squareSize-1, squareSize-1)
|
g.Cells[x][y].Size = rl.NewVector2(squareSize-1, squareSize-1)
|
||||||
if rand.Float64() < 0.1 && clear == false {
|
if rand.Float64() < 0.1 && clear == false {
|
||||||
g.Cells[x][y].Alive = true
|
g.Cells[x][y].Alive = true
|
||||||
}
|
}
|
||||||
|
@ -82,19 +82,19 @@ func (g *Game) Init(clear bool) {
|
||||||
// Input - Game input
|
// Input - Game input
|
||||||
func (g *Game) Input() {
|
func (g *Game) Input() {
|
||||||
// control
|
// control
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
if rl.IsKeyPressed(rl.KeyR) {
|
||||||
g.Init(false)
|
g.Init(false)
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyC) {
|
if rl.IsKeyPressed(rl.KeyC) {
|
||||||
g.Init(true)
|
g.Init(true)
|
||||||
}
|
}
|
||||||
if raylib.IsKeyDown(raylib.KeyRight) && !g.Playing {
|
if rl.IsKeyDown(rl.KeyRight) && !g.Playing {
|
||||||
g.Update()
|
g.Update()
|
||||||
}
|
}
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
g.Click(raylib.GetMouseX(), raylib.GetMouseY())
|
g.Click(rl.GetMouseX(), rl.GetMouseY())
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
g.Playing = !g.Playing
|
g.Playing = !g.Playing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,36 +165,36 @@ func (g *Game) CountNeighbors(x, y int32) int {
|
||||||
|
|
||||||
// Draw - Draw game
|
// Draw - Draw game
|
||||||
func (g *Game) Draw() {
|
func (g *Game) Draw() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
// Draw cells
|
// Draw cells
|
||||||
for x := int32(0); x <= g.Cols; x++ {
|
for x := int32(0); x <= g.Cols; x++ {
|
||||||
for y := int32(0); y <= g.Rows; y++ {
|
for y := int32(0); y <= g.Rows; y++ {
|
||||||
if g.Cells[x][y].Alive {
|
if g.Cells[x][y].Alive {
|
||||||
raylib.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, raylib.Blue)
|
rl.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, rl.Blue)
|
||||||
} else if g.Cells[x][y].Visited {
|
} else if g.Cells[x][y].Visited {
|
||||||
raylib.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, raylib.Color{R: 128, G: 177, B: 136, A: 255})
|
rl.DrawRectangleV(g.Cells[x][y].Position, g.Cells[x][y].Size, rl.Color{R: 128, G: 177, B: 136, A: 255})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw grid lines
|
// Draw grid lines
|
||||||
for i := int32(0); i < g.Cols+1; i++ {
|
for i := int32(0); i < g.Cols+1; i++ {
|
||||||
raylib.DrawLineV(
|
rl.DrawLineV(
|
||||||
raylib.NewVector2(float32(squareSize*i), 0),
|
rl.NewVector2(float32(squareSize*i), 0),
|
||||||
raylib.NewVector2(float32(squareSize*i), float32(g.ScreenHeight)),
|
rl.NewVector2(float32(squareSize*i), float32(g.ScreenHeight)),
|
||||||
raylib.LightGray,
|
rl.LightGray,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := int32(0); i < g.Rows+1; i++ {
|
for i := int32(0); i < g.Rows+1; i++ {
|
||||||
raylib.DrawLineV(
|
rl.DrawLineV(
|
||||||
raylib.NewVector2(0, float32(squareSize*i)),
|
rl.NewVector2(0, float32(squareSize*i)),
|
||||||
raylib.NewVector2(float32(g.ScreenWidth), float32(squareSize*i)),
|
rl.NewVector2(float32(g.ScreenWidth), float32(squareSize*i)),
|
||||||
raylib.LightGray,
|
rl.LightGray,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,18 @@ const (
|
||||||
|
|
||||||
// Snake type
|
// Snake type
|
||||||
type Snake struct {
|
type Snake struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Size raylib.Vector2
|
Size rl.Vector2
|
||||||
Speed raylib.Vector2
|
Speed rl.Vector2
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
// Food type
|
// Food type
|
||||||
type Food struct {
|
type Food struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Size raylib.Vector2
|
Size rl.Vector2
|
||||||
Active bool
|
Active bool
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game type
|
// Game type
|
||||||
|
@ -36,9 +36,9 @@ type Game struct {
|
||||||
|
|
||||||
Fruit Food
|
Fruit Food
|
||||||
Snake []Snake
|
Snake []Snake
|
||||||
SnakePosition []raylib.Vector2
|
SnakePosition []rl.Vector2
|
||||||
AllowMove bool
|
AllowMove bool
|
||||||
Offset raylib.Vector2
|
Offset rl.Vector2
|
||||||
CounterTail int
|
CounterTail int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,17 +46,17 @@ func main() {
|
||||||
game := Game{}
|
game := Game{}
|
||||||
game.Init()
|
game.Init()
|
||||||
|
|
||||||
raylib.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
|
rl.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
game.Update()
|
game.Update()
|
||||||
|
|
||||||
game.Draw()
|
game.Draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init - Initialize game
|
// Init - Initialize game
|
||||||
|
@ -71,58 +71,58 @@ func (g *Game) Init() {
|
||||||
g.CounterTail = 1
|
g.CounterTail = 1
|
||||||
g.AllowMove = false
|
g.AllowMove = false
|
||||||
|
|
||||||
g.Offset = raylib.Vector2{}
|
g.Offset = rl.Vector2{}
|
||||||
g.Offset.X = float32(g.ScreenWidth % squareSize)
|
g.Offset.X = float32(g.ScreenWidth % squareSize)
|
||||||
g.Offset.Y = float32(g.ScreenHeight % squareSize)
|
g.Offset.Y = float32(g.ScreenHeight % squareSize)
|
||||||
|
|
||||||
g.Snake = make([]Snake, snakeLength)
|
g.Snake = make([]Snake, snakeLength)
|
||||||
|
|
||||||
for i := 0; i < snakeLength; i++ {
|
for i := 0; i < snakeLength; i++ {
|
||||||
g.Snake[i].Position = raylib.NewVector2(g.Offset.X/2, g.Offset.Y/2)
|
g.Snake[i].Position = rl.NewVector2(g.Offset.X/2, g.Offset.Y/2)
|
||||||
g.Snake[i].Size = raylib.NewVector2(squareSize, squareSize)
|
g.Snake[i].Size = rl.NewVector2(squareSize, squareSize)
|
||||||
g.Snake[i].Speed = raylib.NewVector2(squareSize, 0)
|
g.Snake[i].Speed = rl.NewVector2(squareSize, 0)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
g.Snake[i].Color = raylib.DarkBlue
|
g.Snake[i].Color = rl.DarkBlue
|
||||||
} else {
|
} else {
|
||||||
g.Snake[i].Color = raylib.Blue
|
g.Snake[i].Color = rl.Blue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.SnakePosition = make([]raylib.Vector2, snakeLength)
|
g.SnakePosition = make([]rl.Vector2, snakeLength)
|
||||||
|
|
||||||
for i := 0; i < snakeLength; i++ {
|
for i := 0; i < snakeLength; i++ {
|
||||||
g.SnakePosition[i] = raylib.NewVector2(0.0, 0.0)
|
g.SnakePosition[i] = rl.NewVector2(0.0, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.Fruit.Size = raylib.NewVector2(squareSize, squareSize)
|
g.Fruit.Size = rl.NewVector2(squareSize, squareSize)
|
||||||
g.Fruit.Color = raylib.SkyBlue
|
g.Fruit.Color = rl.SkyBlue
|
||||||
g.Fruit.Active = false
|
g.Fruit.Active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update - Update game
|
// Update - Update game
|
||||||
func (g *Game) Update() {
|
func (g *Game) Update() {
|
||||||
if !g.GameOver {
|
if !g.GameOver {
|
||||||
if raylib.IsKeyPressed(raylib.KeyP) {
|
if rl.IsKeyPressed('P') {
|
||||||
g.Pause = !g.Pause
|
g.Pause = !g.Pause
|
||||||
}
|
}
|
||||||
|
|
||||||
if !g.Pause {
|
if !g.Pause {
|
||||||
// control
|
// control
|
||||||
if raylib.IsKeyPressed(raylib.KeyRight) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
if rl.IsKeyPressed(rl.KeyRight) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||||
g.Snake[0].Speed = raylib.NewVector2(squareSize, 0)
|
g.Snake[0].Speed = rl.NewVector2(squareSize, 0)
|
||||||
g.AllowMove = false
|
g.AllowMove = false
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyLeft) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
if rl.IsKeyPressed(rl.KeyLeft) && g.Snake[0].Speed.X == 0 && g.AllowMove {
|
||||||
g.Snake[0].Speed = raylib.NewVector2(-squareSize, 0)
|
g.Snake[0].Speed = rl.NewVector2(-squareSize, 0)
|
||||||
g.AllowMove = false
|
g.AllowMove = false
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyUp) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
if rl.IsKeyPressed(rl.KeyUp) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||||
g.Snake[0].Speed = raylib.NewVector2(0, -squareSize)
|
g.Snake[0].Speed = rl.NewVector2(0, -squareSize)
|
||||||
g.AllowMove = false
|
g.AllowMove = false
|
||||||
}
|
}
|
||||||
if raylib.IsKeyPressed(raylib.KeyDown) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
if rl.IsKeyPressed(rl.KeyDown) && g.Snake[0].Speed.Y == 0 && g.AllowMove {
|
||||||
g.Snake[0].Speed = raylib.NewVector2(0, squareSize)
|
g.Snake[0].Speed = rl.NewVector2(0, squareSize)
|
||||||
g.AllowMove = false
|
g.AllowMove = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,16 +159,16 @@ func (g *Game) Update() {
|
||||||
|
|
||||||
if !g.Fruit.Active {
|
if !g.Fruit.Active {
|
||||||
g.Fruit.Active = true
|
g.Fruit.Active = true
|
||||||
g.Fruit.Position = raylib.NewVector2(
|
g.Fruit.Position = rl.NewVector2(
|
||||||
float32(raylib.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize+int32(g.Offset.X)/2),
|
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize+int32(g.Offset.X)/2),
|
||||||
float32(raylib.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize+int32(g.Offset.Y)/2),
|
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize+int32(g.Offset.Y)/2),
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < g.CounterTail; i++ {
|
for i := 0; i < g.CounterTail; i++ {
|
||||||
for (g.Fruit.Position.X == g.Snake[i].Position.X) && (g.Fruit.Position.Y == g.Snake[i].Position.Y) {
|
for (g.Fruit.Position.X == g.Snake[i].Position.X) && (g.Fruit.Position.Y == g.Snake[i].Position.Y) {
|
||||||
g.Fruit.Position = raylib.NewVector2(
|
g.Fruit.Position = rl.NewVector2(
|
||||||
float32(raylib.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize),
|
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize),
|
||||||
float32(raylib.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize),
|
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize),
|
||||||
)
|
)
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
|
@ -176,9 +176,9 @@ func (g *Game) Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// collision
|
// collision
|
||||||
if raylib.CheckCollisionRecs(
|
if rl.CheckCollisionRecs(
|
||||||
raylib.NewRectangle(g.Snake[0].Position.X, g.Snake[0].Position.Y, g.Snake[0].Size.X, g.Snake[0].Size.Y),
|
rl.NewRectangle(g.Snake[0].Position.X, g.Snake[0].Position.Y, g.Snake[0].Size.X, g.Snake[0].Size.Y),
|
||||||
raylib.NewRectangle(g.Fruit.Position.X, g.Fruit.Position.Y, g.Fruit.Size.X, g.Fruit.Size.Y),
|
rl.NewRectangle(g.Fruit.Position.X, g.Fruit.Position.Y, g.Fruit.Size.X, g.Fruit.Size.Y),
|
||||||
) {
|
) {
|
||||||
g.Snake[g.CounterTail].Position = g.SnakePosition[g.CounterTail-1]
|
g.Snake[g.CounterTail].Position = g.SnakePosition[g.CounterTail-1]
|
||||||
g.CounterTail += 1
|
g.CounterTail += 1
|
||||||
|
@ -188,7 +188,7 @@ func (g *Game) Update() {
|
||||||
g.FramesCounter++
|
g.FramesCounter++
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
g.Init()
|
g.Init()
|
||||||
g.GameOver = false
|
g.GameOver = false
|
||||||
}
|
}
|
||||||
|
@ -197,42 +197,42 @@ func (g *Game) Update() {
|
||||||
|
|
||||||
// Draw - Draw game
|
// Draw - Draw game
|
||||||
func (g *Game) Draw() {
|
func (g *Game) Draw() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
if !g.GameOver {
|
if !g.GameOver {
|
||||||
// Draw grid lines
|
// Draw grid lines
|
||||||
for i := int32(0); i < g.ScreenWidth/squareSize+1; i++ {
|
for i := int32(0); i < g.ScreenWidth/squareSize+1; i++ {
|
||||||
raylib.DrawLineV(
|
rl.DrawLineV(
|
||||||
raylib.NewVector2(float32(squareSize*i)+g.Offset.X/2, g.Offset.Y/2),
|
rl.NewVector2(float32(squareSize*i)+g.Offset.X/2, g.Offset.Y/2),
|
||||||
raylib.NewVector2(float32(squareSize*i)+g.Offset.X/2, float32(g.ScreenHeight)-g.Offset.Y/2),
|
rl.NewVector2(float32(squareSize*i)+g.Offset.X/2, float32(g.ScreenHeight)-g.Offset.Y/2),
|
||||||
raylib.LightGray,
|
rl.LightGray,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := int32(0); i < g.ScreenHeight/squareSize+1; i++ {
|
for i := int32(0); i < g.ScreenHeight/squareSize+1; i++ {
|
||||||
raylib.DrawLineV(
|
rl.DrawLineV(
|
||||||
raylib.NewVector2(g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
rl.NewVector2(g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||||
raylib.NewVector2(float32(g.ScreenWidth)-g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
rl.NewVector2(float32(g.ScreenWidth)-g.Offset.X/2, float32(squareSize*i)+g.Offset.Y/2),
|
||||||
raylib.LightGray,
|
rl.LightGray,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw snake
|
// Draw snake
|
||||||
for i := 0; i < g.CounterTail; i++ {
|
for i := 0; i < g.CounterTail; i++ {
|
||||||
raylib.DrawRectangleV(g.Snake[i].Position, g.Snake[i].Size, g.Snake[i].Color)
|
rl.DrawRectangleV(g.Snake[i].Position, g.Snake[i].Size, g.Snake[i].Color)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw fruit to pick
|
// Draw fruit to pick
|
||||||
raylib.DrawRectangleV(g.Fruit.Position, g.Fruit.Size, g.Fruit.Color)
|
rl.DrawRectangleV(g.Fruit.Position, g.Fruit.Size, g.Fruit.Color)
|
||||||
|
|
||||||
if g.Pause {
|
if g.Pause {
|
||||||
raylib.DrawText("GAME PAUSED", g.ScreenWidth/2-raylib.MeasureText("GAME PAUSED", 40)/2, g.ScreenHeight/2-40, 40, raylib.Gray)
|
rl.DrawText("GAME PAUSED", g.ScreenWidth/2-rl.MeasureText("GAME PAUSED", 40)/2, g.ScreenHeight/2-40, 40, rl.Gray)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("PRESS [ENTER] TO PLAY AGAIN", raylib.GetScreenWidth()/2-raylib.MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, raylib.GetScreenHeight()/2-50, 20, raylib.Gray)
|
rl.DrawText("PRESS [ENTER] TO PLAY AGAIN", rl.GetScreenWidth()/2-rl.MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, rl.GetScreenHeight()/2-50, 20, rl.Gray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [gui] example - basic controls")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [gui] example - basic controls")
|
||||||
|
|
||||||
buttonToggle := true
|
buttonToggle := true
|
||||||
buttonClicked := false
|
buttonClicked := false
|
||||||
|
@ -33,9 +33,9 @@ func main() {
|
||||||
|
|
||||||
var inputText string
|
var inputText string
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if buttonClicked {
|
if buttonClicked {
|
||||||
progressValue += 0.1
|
progressValue += 0.1
|
||||||
if progressValue >= 1.1 {
|
if progressValue >= 1.1 {
|
||||||
|
@ -43,50 +43,50 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Beige)
|
rl.ClearBackground(rl.Beige)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(50, 50, 80, 20), "Label")
|
raygui.Label(rl.NewRectangle(50, 50, 80, 20), "Label")
|
||||||
|
|
||||||
buttonClicked = raygui.Button(raylib.NewRectangle(50, 70, 80, 40), "Button")
|
buttonClicked = raygui.Button(rl.NewRectangle(50, 70, 80, 40), "Button")
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(70, 140, 20, 20), "Checkbox")
|
raygui.Label(rl.NewRectangle(70, 140, 20, 20), "Checkbox")
|
||||||
checkboxChecked = raygui.CheckBox(raylib.NewRectangle(50, 140, 20, 20), checkboxChecked)
|
checkboxChecked = raygui.CheckBox(rl.NewRectangle(50, 140, 20, 20), checkboxChecked)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(50, 190, 200, 20), "ProgressBar")
|
raygui.Label(rl.NewRectangle(50, 190, 200, 20), "ProgressBar")
|
||||||
raygui.ProgressBar(raylib.NewRectangle(50, 210, 200, 20), progressValue)
|
raygui.ProgressBar(rl.NewRectangle(50, 210, 200, 20), progressValue)
|
||||||
raygui.Label(raylib.NewRectangle(200+50+5, 210, 20, 20), fmt.Sprintf("%.1f", progressValue))
|
raygui.Label(rl.NewRectangle(200+50+5, 210, 20, 20), fmt.Sprintf("%.1f", progressValue))
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(50, 260, 200, 20), "Slider")
|
raygui.Label(rl.NewRectangle(50, 260, 200, 20), "Slider")
|
||||||
sliderValue = raygui.Slider(raylib.NewRectangle(50, 280, 200, 20), sliderValue, 0, 100)
|
sliderValue = raygui.Slider(rl.NewRectangle(50, 280, 200, 20), sliderValue, 0, 100)
|
||||||
raygui.Label(raylib.NewRectangle(200+50+5, 280, 20, 20), fmt.Sprintf("%.0f", sliderValue))
|
raygui.Label(rl.NewRectangle(200+50+5, 280, 20, 20), fmt.Sprintf("%.0f", sliderValue))
|
||||||
|
|
||||||
buttonToggle = raygui.ToggleButton(raylib.NewRectangle(50, 350, 100, 40), "ToggleButton", buttonToggle)
|
buttonToggle = raygui.ToggleButton(rl.NewRectangle(50, 350, 100, 40), "ToggleButton", buttonToggle)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(500, 50, 200, 20), "ToggleGroup")
|
raygui.Label(rl.NewRectangle(500, 50, 200, 20), "ToggleGroup")
|
||||||
toggleActive = raygui.ToggleGroup(raylib.NewRectangle(500, 70, 60, 30), toggleText, toggleActive)
|
toggleActive = raygui.ToggleGroup(rl.NewRectangle(500, 70, 60, 30), toggleText, toggleActive)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(500, 120, 200, 20), "SliderBar")
|
raygui.Label(rl.NewRectangle(500, 120, 200, 20), "SliderBar")
|
||||||
sliderBarValue = raygui.SliderBar(raylib.NewRectangle(500, 140, 200, 20), sliderBarValue, 0, 100)
|
sliderBarValue = raygui.SliderBar(rl.NewRectangle(500, 140, 200, 20), sliderBarValue, 0, 100)
|
||||||
raygui.Label(raylib.NewRectangle(500+200+5, 140, 20, 20), fmt.Sprintf("%.0f", sliderBarValue))
|
raygui.Label(rl.NewRectangle(500+200+5, 140, 20, 20), fmt.Sprintf("%.0f", sliderBarValue))
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(500, 190, 200, 20), "Spinner")
|
raygui.Label(rl.NewRectangle(500, 190, 200, 20), "Spinner")
|
||||||
spinnerValue = raygui.Spinner(raylib.NewRectangle(500, 210, 200, 20), spinnerValue, 0, 100)
|
spinnerValue = raygui.Spinner(rl.NewRectangle(500, 210, 200, 20), spinnerValue, 0, 100)
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(500, 260, 200, 20), "ComboBox")
|
raygui.Label(rl.NewRectangle(500, 260, 200, 20), "ComboBox")
|
||||||
comboActive = raygui.ComboBox(raylib.NewRectangle(500, 280, 200, 20), comboText, comboActive)
|
comboActive = raygui.ComboBox(rl.NewRectangle(500, 280, 200, 20), comboText, comboActive)
|
||||||
|
|
||||||
if comboLastActive != comboActive {
|
if comboLastActive != comboActive {
|
||||||
raygui.LoadGuiStyle(fmt.Sprintf("styles/%s.style", comboText[comboActive]))
|
raygui.LoadGuiStyle(fmt.Sprintf("styles/%s.style", comboText[comboActive]))
|
||||||
comboLastActive = comboActive
|
comboLastActive = comboActive
|
||||||
}
|
}
|
||||||
|
|
||||||
raygui.Label(raylib.NewRectangle(500, 330, 200, 20), "TextBox")
|
raygui.Label(rl.NewRectangle(500, 330, 200, 20), "TextBox")
|
||||||
inputText = raygui.TextBox(raylib.NewRectangle(500, 350, 200, 20), inputText)
|
inputText = raygui.TextBox(rl.NewRectangle(500, 350, 200, 20), inputText)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,41 +8,41 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(5.0, 4.0, 5.0)
|
camera.Position = rl.NewVector3(5.0, 4.0, 5.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 2.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
bill := raylib.LoadTexture("billboard.png") // Our texture billboard
|
bill := rl.LoadTexture("billboard.png") // Our texture billboard
|
||||||
billPosition := raylib.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
billPosition := rl.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawBillboard(camera, bill, billPosition, 2.0, raylib.White)
|
rl.DrawBillboard(camera, bill, billPosition, 2.0, rl.White)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(bill) // Unload texture
|
rl.UnloadTexture(bill) // Unload texture
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,62 +8,62 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(0.0, 10.0, 10.0)
|
camera.Position = rl.NewVector3(0.0, 10.0, 10.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
playerPosition := raylib.NewVector3(0.0, 1.0, 2.0)
|
playerPosition := rl.NewVector3(0.0, 1.0, 2.0)
|
||||||
playerSize := raylib.NewVector3(1.0, 2.0, 1.0)
|
playerSize := rl.NewVector3(1.0, 2.0, 1.0)
|
||||||
playerColor := raylib.Green
|
playerColor := rl.Green
|
||||||
|
|
||||||
enemyBoxPos := raylib.NewVector3(-4.0, 1.0, 0.0)
|
enemyBoxPos := rl.NewVector3(-4.0, 1.0, 0.0)
|
||||||
enemyBoxSize := raylib.NewVector3(2.0, 2.0, 2.0)
|
enemyBoxSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||||
|
|
||||||
enemySpherePos := raylib.NewVector3(4.0, 0.0, 0.0)
|
enemySpherePos := rl.NewVector3(4.0, 0.0, 0.0)
|
||||||
enemySphereSize := float32(1.5)
|
enemySphereSize := float32(1.5)
|
||||||
|
|
||||||
collision := false
|
collision := false
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
// Move player
|
// Move player
|
||||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
if rl.IsKeyDown(rl.KeyRight) {
|
||||||
playerPosition.X += 0.2
|
playerPosition.X += 0.2
|
||||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
playerPosition.X -= 0.2
|
playerPosition.X -= 0.2
|
||||||
} else if raylib.IsKeyDown(raylib.KeyDown) {
|
} else if rl.IsKeyDown(rl.KeyDown) {
|
||||||
playerPosition.Z += 0.2
|
playerPosition.Z += 0.2
|
||||||
} else if raylib.IsKeyDown(raylib.KeyUp) {
|
} else if rl.IsKeyDown(rl.KeyUp) {
|
||||||
playerPosition.Z -= 0.2
|
playerPosition.Z -= 0.2
|
||||||
}
|
}
|
||||||
|
|
||||||
collision = false
|
collision = false
|
||||||
|
|
||||||
// Check collisions player vs enemy-box
|
// Check collisions player vs enemy-box
|
||||||
if raylib.CheckCollisionBoxes(
|
if rl.CheckCollisionBoxes(
|
||||||
raylib.NewBoundingBox(
|
rl.NewBoundingBox(
|
||||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
rl.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
rl.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||||
raylib.NewBoundingBox(
|
rl.NewBoundingBox(
|
||||||
raylib.NewVector3(enemyBoxPos.X-enemyBoxSize.X/2, enemyBoxPos.Y-enemyBoxSize.Y/2, enemyBoxPos.Z-enemyBoxSize.Z/2),
|
rl.NewVector3(enemyBoxPos.X-enemyBoxSize.X/2, enemyBoxPos.Y-enemyBoxSize.Y/2, enemyBoxPos.Z-enemyBoxSize.Z/2),
|
||||||
raylib.NewVector3(enemyBoxPos.X+enemyBoxSize.X/2, enemyBoxPos.Y+enemyBoxSize.Y/2, enemyBoxPos.Z+enemyBoxSize.Z/2)),
|
rl.NewVector3(enemyBoxPos.X+enemyBoxSize.X/2, enemyBoxPos.Y+enemyBoxSize.Y/2, enemyBoxPos.Z+enemyBoxSize.Z/2)),
|
||||||
) {
|
) {
|
||||||
collision = true
|
collision = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check collisions player vs enemy-sphere
|
// Check collisions player vs enemy-sphere
|
||||||
if raylib.CheckCollisionBoxSphere(
|
if rl.CheckCollisionBoxSphere(
|
||||||
raylib.NewBoundingBox(
|
rl.NewBoundingBox(
|
||||||
raylib.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
rl.NewVector3(playerPosition.X-playerSize.X/2, playerPosition.Y-playerSize.Y/2, playerPosition.Z-playerSize.Z/2),
|
||||||
raylib.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
rl.NewVector3(playerPosition.X+playerSize.X/2, playerPosition.Y+playerSize.Y/2, playerPosition.Z+playerSize.Z/2)),
|
||||||
enemySpherePos,
|
enemySpherePos,
|
||||||
enemySphereSize,
|
enemySphereSize,
|
||||||
) {
|
) {
|
||||||
|
@ -71,40 +71,40 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if collision {
|
if collision {
|
||||||
playerColor = raylib.Red
|
playerColor = rl.Red
|
||||||
} else {
|
} else {
|
||||||
playerColor = raylib.Green
|
playerColor = rl.Green
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
// Draw enemy-box
|
// Draw enemy-box
|
||||||
raylib.DrawCube(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.Gray)
|
rl.DrawCube(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, rl.Gray)
|
||||||
raylib.DrawCubeWires(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, raylib.DarkGray)
|
rl.DrawCubeWires(enemyBoxPos, enemyBoxSize.X, enemyBoxSize.Y, enemyBoxSize.Z, rl.DarkGray)
|
||||||
|
|
||||||
// Draw enemy-sphere
|
// Draw enemy-sphere
|
||||||
raylib.DrawSphere(enemySpherePos, enemySphereSize, raylib.Gray)
|
rl.DrawSphere(enemySpherePos, enemySphereSize, rl.Gray)
|
||||||
raylib.DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, raylib.DarkGray)
|
rl.DrawSphereWires(enemySpherePos, enemySphereSize, 16, 16, rl.DarkGray)
|
||||||
|
|
||||||
// Draw player
|
// Draw player
|
||||||
raylib.DrawCubeV(playerPosition, playerSize, playerColor)
|
rl.DrawCubeV(playerPosition, playerSize, playerColor)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("Move player with cursors to collide", 220, 40, 20, raylib.Gray)
|
rl.DrawText("Move player with cursors to collide", 220, 40, 20, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,64 +8,64 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(16.0, 14.0, 16.0)
|
camera.Position = rl.NewVector3(16.0, 14.0, 16.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Type = raylib.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
image := raylib.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||||
cubicmap := raylib.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||||
|
|
||||||
mesh := raylib.GenMeshCubicmap(*image, raylib.NewVector3(1.0, 1.0, 1.0))
|
mesh := rl.GenMeshCubicmap(*image, rl.NewVector3(1.0, 1.0, 1.0))
|
||||||
model := raylib.LoadModelFromMesh(mesh)
|
model := rl.LoadModelFromMesh(mesh)
|
||||||
|
|
||||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
texture := raylib.LoadTexture("cubicmap_atlas.png") // Load map texture
|
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||||
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
|
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||||
|
|
||||||
mapPosition := raylib.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||||
|
|
||||||
raylib.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
rl.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(model, mapPosition, 1.0, raylib.White)
|
rl.DrawModel(model, mapPosition, 1.0, rl.White)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawTextureEx(cubicmap, raylib.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, raylib.White)
|
rl.DrawTextureEx(cubicmap, rl.NewVector2(float32(screenWidth-cubicmap.Width*4-20), 20), 0.0, 4.0, rl.White)
|
||||||
raylib.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, raylib.Green)
|
rl.DrawRectangleLines(screenWidth-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, rl.Green)
|
||||||
|
|
||||||
raylib.DrawText("cubicmap image used to", 658, 90, 10, raylib.Gray)
|
rl.DrawText("cubicmap image used to", 658, 90, 10, rl.Gray)
|
||||||
raylib.DrawText("generate map 3d model", 658, 104, 10, raylib.Gray)
|
rl.DrawText("generate map 3d model", 658, 104, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(cubicmap) // Unload cubicmap texture
|
rl.UnloadTexture(cubicmap) // Unload cubicmap texture
|
||||||
raylib.UnloadTexture(texture) // Unload map texture
|
rl.UnloadTexture(texture) // Unload map texture
|
||||||
raylib.UnloadModel(model) // Unload map model
|
rl.UnloadModel(model) // Unload map model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(0.0, 10.0, 10.0)
|
camera.Position = rl.NewVector3(0.0, 10.0, 10.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawCube(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Red)
|
rl.DrawCube(rl.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, rl.Red)
|
||||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, raylib.Gold)
|
rl.DrawCubeWires(rl.NewVector3(-4.0, 0.0, 2.0), 2.0, 5.0, 2.0, rl.Gold)
|
||||||
raylib.DrawCubeWires(raylib.NewVector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, raylib.Maroon)
|
rl.DrawCubeWires(rl.NewVector3(-4.0, 0.0, -2.0), 3.0, 6.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawSphere(raylib.NewVector3(-1.0, 0.0, -2.0), 1.0, raylib.Green)
|
rl.DrawSphere(rl.NewVector3(-1.0, 0.0, -2.0), 1.0, rl.Green)
|
||||||
raylib.DrawSphereWires(raylib.NewVector3(1.0, 0.0, 2.0), 2.0, 16, 16, raylib.Lime)
|
rl.DrawSphereWires(rl.NewVector3(1.0, 0.0, 2.0), 2.0, 16, 16, rl.Lime)
|
||||||
|
|
||||||
raylib.DrawCylinder(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.SkyBlue)
|
rl.DrawCylinder(rl.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, rl.SkyBlue)
|
||||||
raylib.DrawCylinderWires(raylib.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, raylib.DarkBlue)
|
rl.DrawCylinderWires(rl.NewVector3(4.0, 0.0, -2.0), 1.0, 2.0, 3.0, 4, rl.DarkBlue)
|
||||||
raylib.DrawCylinderWires(raylib.NewVector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, raylib.Brown)
|
rl.DrawCylinderWires(rl.NewVector3(4.5, -1.0, 2.0), 1.0, 1.0, 2.0, 6, rl.Brown)
|
||||||
|
|
||||||
raylib.DrawCylinder(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Gold)
|
rl.DrawCylinder(rl.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, rl.Gold)
|
||||||
raylib.DrawCylinderWires(raylib.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, raylib.Pink)
|
rl.DrawCylinderWires(rl.NewVector3(1.0, 0.0, -4.0), 0.0, 1.5, 3.0, 8, rl.Pink)
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,58 +8,58 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(18.0, 16.0, 18.0)
|
camera.Position = rl.NewVector3(18.0, 16.0, 18.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
image := raylib.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
image := rl.LoadImage("heightmap.png") // Load heightmap image (RAM)
|
||||||
texture := raylib.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
texture := rl.LoadTextureFromImage(image) // Convert image to texture (VRAM)
|
||||||
|
|
||||||
mesh := raylib.GenMeshHeightmap(*image, raylib.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
||||||
model := raylib.LoadModelFromMesh(mesh) // Load model from generated mesh
|
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||||
|
|
||||||
model.Material.Maps[raylib.MapDiffuse].Texture = texture // Set map diffuse texture
|
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||||
mapPosition := raylib.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||||
|
|
||||||
raylib.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(model, mapPosition, 1.0, raylib.Red)
|
rl.DrawModel(model, mapPosition, 1.0, rl.Red)
|
||||||
|
|
||||||
raylib.DrawGrid(20, 1.0)
|
rl.DrawGrid(20, 1.0)
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawTexture(texture, screenWidth-texture.Width-20, 20, raylib.White)
|
rl.DrawTexture(texture, screenWidth-texture.Width-20, 20, rl.White)
|
||||||
raylib.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, raylib.Green)
|
rl.DrawRectangleLines(screenWidth-texture.Width-20, 20, texture.Width, texture.Height, rl.Green)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture) // Unload map texture
|
rl.UnloadTexture(texture) // Unload map texture
|
||||||
raylib.UnloadModel(model) // Unload map model
|
rl.UnloadModel(model) // Unload map model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
|
|
||||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.DrawGizmo(position) // Draw gizmo
|
rl.DrawGizmo(position) // Draw gizmo
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture) // Unload texture
|
rl.UnloadTexture(texture) // Unload texture
|
||||||
raylib.UnloadModel(dwarf) // Unload model
|
rl.UnloadModel(dwarf) // Unload model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,36 +16,36 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
raylib.SetCallbackFunc(main)
|
rl.SetCallbackFunc(main)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "Android example")
|
rl.InitWindow(screenWidth, screenHeight, "Android example")
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
currentScreen := Logo
|
currentScreen := Logo
|
||||||
windowShouldClose := false
|
windowShouldClose := false
|
||||||
|
|
||||||
texture := raylib.LoadTexture("raylib_logo.png") // Load texture (placed on assets folder)
|
texture := rl.LoadTexture("raylib_logo.png") // Load texture (placed on assets folder)
|
||||||
fx := raylib.LoadSound("coin.wav") // Load WAV audio file (placed on assets folder)
|
fx := rl.LoadSound("coin.wav") // Load WAV audio file (placed on assets folder)
|
||||||
ambient := raylib.LoadMusicStream("ambient.ogg") // Load music
|
ambient := rl.LoadMusicStream("ambient.ogg") // Load music
|
||||||
|
|
||||||
raylib.PlayMusicStream(ambient)
|
rl.PlayMusicStream(ambient)
|
||||||
|
|
||||||
framesCounter := 0 // Used to count frames
|
framesCounter := 0 // Used to count frames
|
||||||
|
|
||||||
//raylib.SetTargetFPS(60)
|
//rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !windowShouldClose {
|
for !windowShouldClose {
|
||||||
raylib.UpdateMusicStream(ambient)
|
rl.UpdateMusicStream(ambient)
|
||||||
|
|
||||||
if runtime.GOOS == "android" && raylib.IsKeyDown(raylib.KeyBack) || raylib.WindowShouldClose() {
|
if runtime.GOOS == "android" && rl.IsKeyDown(rl.KeyBack) || rl.WindowShouldClose() {
|
||||||
windowShouldClose = true
|
windowShouldClose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,64 +60,64 @@ func main() {
|
||||||
break
|
break
|
||||||
case Title:
|
case Title:
|
||||||
// Press enter to change to GamePlay screen
|
// Press enter to change to GamePlay screen
|
||||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
if rl.IsGestureDetected(rl.GestureTap) {
|
||||||
raylib.PlaySound(fx)
|
rl.PlaySound(fx)
|
||||||
currentScreen = GamePlay
|
currentScreen = GamePlay
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case GamePlay:
|
case GamePlay:
|
||||||
// Press enter to change to Ending screen
|
// Press enter to change to Ending screen
|
||||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
if rl.IsGestureDetected(rl.GestureTap) {
|
||||||
raylib.PlaySound(fx)
|
rl.PlaySound(fx)
|
||||||
currentScreen = Ending
|
currentScreen = Ending
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case Ending:
|
case Ending:
|
||||||
// Press enter to return to Title screen
|
// Press enter to return to Title screen
|
||||||
if raylib.IsGestureDetected(raylib.GestureTap) {
|
if rl.IsGestureDetected(rl.GestureTap) {
|
||||||
raylib.PlaySound(fx)
|
rl.PlaySound(fx)
|
||||||
currentScreen = Title
|
currentScreen = Title
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
switch currentScreen {
|
switch currentScreen {
|
||||||
case Logo:
|
case Logo:
|
||||||
raylib.DrawText("LOGO SCREEN", 20, 20, 40, raylib.LightGray)
|
rl.DrawText("LOGO SCREEN", 20, 20, 40, rl.LightGray)
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||||
raylib.DrawText("WAIT for 4 SECONDS...", 290, 400, 20, raylib.Gray)
|
rl.DrawText("WAIT for 4 SECONDS...", 290, 400, 20, rl.Gray)
|
||||||
break
|
break
|
||||||
case Title:
|
case Title:
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Green)
|
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Green)
|
||||||
raylib.DrawText("TITLE SCREEN", 20, 20, 40, raylib.DarkGreen)
|
rl.DrawText("TITLE SCREEN", 20, 20, 40, rl.DarkGreen)
|
||||||
raylib.DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, raylib.DarkGreen)
|
rl.DrawText("TAP SCREEN to JUMP to GAMEPLAY SCREEN", 160, 220, 20, rl.DarkGreen)
|
||||||
break
|
break
|
||||||
case GamePlay:
|
case GamePlay:
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Purple)
|
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Purple)
|
||||||
raylib.DrawText("GAMEPLAY SCREEN", 20, 20, 40, raylib.Maroon)
|
rl.DrawText("GAMEPLAY SCREEN", 20, 20, 40, rl.Maroon)
|
||||||
raylib.DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, raylib.Maroon)
|
rl.DrawText("TAP SCREEN to JUMP to ENDING SCREEN", 170, 220, 20, rl.Maroon)
|
||||||
break
|
break
|
||||||
case Ending:
|
case Ending:
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, screenHeight, raylib.Blue)
|
rl.DrawRectangle(0, 0, screenWidth, screenHeight, rl.Blue)
|
||||||
raylib.DrawText("ENDING SCREEN", 20, 20, 40, raylib.DarkBlue)
|
rl.DrawText("ENDING SCREEN", 20, 20, 40, rl.DarkBlue)
|
||||||
raylib.DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, raylib.DarkBlue)
|
rl.DrawText("TAP SCREEN to RETURN to TITLE SCREEN", 160, 220, 20, rl.DarkBlue)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadSound(fx) // Unload sound data
|
rl.UnloadSound(fx) // Unload sound data
|
||||||
raylib.UnloadMusicStream(ambient) // Unload music stream data
|
rl.UnloadMusicStream(ambient) // Unload music stream data
|
||||||
raylib.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||||
raylib.UnloadTexture(texture) // Unload texture data
|
rl.UnloadTexture(texture) // Unload texture data
|
||||||
raylib.CloseWindow() // Close window
|
rl.CloseWindow() // Close window
|
||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,33 +8,33 @@ import (
|
||||||
|
|
||||||
// Bunny type
|
// Bunny type
|
||||||
type Bunny struct {
|
type Bunny struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Speed raylib.Vector2
|
Speed rl.Vector2
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(1280)
|
screenWidth := int32(1280)
|
||||||
screenHeight := int32(960)
|
screenHeight := int32(960)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
|
||||||
|
|
||||||
texture := raylib.LoadTexture("wabbit_alpha.png")
|
texture := rl.LoadTexture("wabbit_alpha.png")
|
||||||
|
|
||||||
bunnies := make([]*Bunny, 0)
|
bunnies := make([]*Bunny, 0)
|
||||||
bunniesCount := 0
|
bunniesCount := 0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
// Create more bunnies
|
// Create more bunnies
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
b := &Bunny{}
|
b := &Bunny{}
|
||||||
b.Position = raylib.GetMousePosition()
|
b.Position = rl.GetMousePosition()
|
||||||
b.Speed.X = float32(raylib.GetRandomValue(250, 500)) / 60.0
|
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0
|
||||||
b.Speed.Y = float32(raylib.GetRandomValue(250, 500)-500) / 60.0
|
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0
|
||||||
|
|
||||||
bunnies = append(bunnies, b)
|
bunnies = append(bunnies, b)
|
||||||
bunniesCount++
|
bunniesCount++
|
||||||
|
@ -55,27 +55,27 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
for _, b := range bunnies {
|
for _, b := range bunnies {
|
||||||
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
|
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
|
||||||
// batching buffer starts being filled again; before launching the draw call,
|
// batching buffer starts being filled again; before launching the draw call,
|
||||||
// updated vertex data from internal buffer is send to GPU... it seems it generates
|
// updated vertex data from internal buffer is send to GPU... it seems it generates
|
||||||
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
|
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
|
||||||
raylib.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), raylib.RayWhite)
|
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangle(0, 0, screenWidth, 40, raylib.LightGray)
|
rl.DrawRectangle(0, 0, screenWidth, 40, rl.LightGray)
|
||||||
raylib.DrawText("raylib bunnymark", 10, 10, 20, raylib.DarkGray)
|
rl.DrawText("raylib bunnymark", 10, 10, 20, rl.DarkGray)
|
||||||
raylib.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, raylib.Red)
|
rl.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, rl.Red)
|
||||||
|
|
||||||
raylib.DrawFPS(260, 10)
|
rl.DrawFPS(260, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,14 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - resources loading")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - resources loading")
|
||||||
|
|
||||||
raylib.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
// OpenAsset() will also work on Android (reads files from assets/)
|
// OpenAsset() will also work on Android (reads files from assets/)
|
||||||
reader, err := raylib.OpenAsset("data.rres")
|
reader, err := rl.OpenAsset("data.rres")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogWarning, "[%s] rRES raylib resource file could not be opened: %v", "data.rres", err)
|
rl.TraceLog(rl.LogWarning, "[%s] rRES raylib resource file could not be opened: %v", "data.rres", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer reader.Close()
|
defer reader.Close()
|
||||||
|
@ -30,67 +30,67 @@ func main() {
|
||||||
//reader := bytes.NewReader(b)
|
//reader := bytes.NewReader(b)
|
||||||
|
|
||||||
res := rres.LoadResource(reader, 0, []byte("passwordpassword"))
|
res := rres.LoadResource(reader, 0, []byte("passwordpassword"))
|
||||||
wav := raylib.LoadWaveEx(res.Data, int32(res.Param1), int32(res.Param2), int32(res.Param3), int32(res.Param4))
|
wav := rl.LoadWaveEx(res.Data, int32(res.Param1), int32(res.Param2), int32(res.Param3), int32(res.Param4))
|
||||||
snd := raylib.LoadSoundFromWave(wav)
|
snd := rl.LoadSoundFromWave(wav)
|
||||||
raylib.UnloadWave(wav)
|
rl.UnloadWave(wav)
|
||||||
|
|
||||||
textures := make([]raylib.Texture2D, numTextures)
|
textures := make([]rl.Texture2D, numTextures)
|
||||||
for i := 0; i < numTextures; i++ {
|
for i := 0; i < numTextures; i++ {
|
||||||
r := rres.LoadResource(reader, i+1, []byte("passwordpassword"))
|
r := rres.LoadResource(reader, i+1, []byte("passwordpassword"))
|
||||||
image := raylib.LoadImagePro(r.Data, int32(r.Param1), int32(r.Param2), raylib.PixelFormat(r.Param3))
|
image := rl.LoadImagePro(r.Data, int32(r.Param1), int32(r.Param2), rl.PixelFormat(r.Param3))
|
||||||
textures[i] = raylib.LoadTextureFromImage(image)
|
textures[i] = rl.LoadTextureFromImage(image)
|
||||||
raylib.UnloadImage(image)
|
rl.UnloadImage(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentTexture := 0
|
currentTexture := 0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
raylib.PlaySound(snd)
|
rl.PlaySound(snd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(textures[currentTexture], screenWidth/2-textures[currentTexture].Width/2, screenHeight/2-textures[currentTexture].Height/2, raylib.RayWhite)
|
rl.DrawTexture(textures[currentTexture], screenWidth/2-textures[currentTexture].Width/2, screenHeight/2-textures[currentTexture].Height/2, rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE TEXTURES", 40, 410, 10, raylib.Gray)
|
rl.DrawText("MOUSE LEFT BUTTON to CYCLE TEXTURES", 40, 410, 10, rl.Gray)
|
||||||
raylib.DrawText("SPACE to PLAY SOUND", 40, 430, 10, raylib.Gray)
|
rl.DrawText("SPACE to PLAY SOUND", 40, 430, 10, rl.Gray)
|
||||||
|
|
||||||
switch currentTexture {
|
switch currentTexture {
|
||||||
case 0:
|
case 0:
|
||||||
raylib.DrawText("GIF", 272, 70, 20, raylib.Gray)
|
rl.DrawText("GIF", 272, 70, 20, rl.Gray)
|
||||||
break
|
break
|
||||||
case 1:
|
case 1:
|
||||||
raylib.DrawText("JPEG", 272, 70, 20, raylib.Gray)
|
rl.DrawText("JPEG", 272, 70, 20, rl.Gray)
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
raylib.DrawText("PNG", 272, 70, 20, raylib.Gray)
|
rl.DrawText("PNG", 272, 70, 20, rl.Gray)
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
raylib.DrawText("TGA", 272, 70, 20, raylib.Gray)
|
rl.DrawText("TGA", 272, 70, 20, rl.Gray)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadSound(snd)
|
rl.UnloadSound(snd)
|
||||||
|
|
||||||
for _, t := range textures {
|
for _, t := range textures {
|
||||||
raylib.UnloadTexture(t)
|
rl.UnloadTexture(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseAudioDevice()
|
rl.CloseAudioDevice()
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,19 @@ package main
|
||||||
import "github.com/gen2brain/raylib-go/raylib"
|
import "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [rpi] example - basic window")
|
rl.InitWindow(800, 450, "raylib [rpi] example - basic window")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LightGray)
|
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,28 +30,28 @@ func (g *Game) Init() {
|
||||||
// Update - Update game
|
// Update - Update game
|
||||||
func (g *Game) Update() {
|
func (g *Game) Update() {
|
||||||
// Keys 1-9 switch demos
|
// Keys 1-9 switch demos
|
||||||
switch raylib.GetKeyPressed() {
|
switch rl.GetKeyPressed() {
|
||||||
case raylib.KeyOne:
|
case rl.KeyOne:
|
||||||
g.Demo1()
|
g.Demo1()
|
||||||
case raylib.KeyTwo:
|
case rl.KeyTwo:
|
||||||
g.Demo2()
|
g.Demo2()
|
||||||
case raylib.KeyThree:
|
case rl.KeyThree:
|
||||||
g.Demo3()
|
g.Demo3()
|
||||||
case raylib.KeyFour:
|
case rl.KeyFour:
|
||||||
g.Demo4()
|
g.Demo4()
|
||||||
case raylib.KeyFive:
|
case rl.KeyFive:
|
||||||
g.Demo5()
|
g.Demo5()
|
||||||
case raylib.KeySix:
|
case rl.KeySix:
|
||||||
g.Demo6()
|
g.Demo6()
|
||||||
case raylib.KeySeven:
|
case rl.KeySeven:
|
||||||
g.Demo7()
|
g.Demo7()
|
||||||
case raylib.KeyEight:
|
case rl.KeyEight:
|
||||||
g.Demo8()
|
g.Demo8()
|
||||||
case raylib.KeyNine:
|
case rl.KeyNine:
|
||||||
g.Demo9()
|
g.Demo9()
|
||||||
}
|
}
|
||||||
|
|
||||||
g.TimeStep = float64(raylib.GetFrameTime())
|
g.TimeStep = float64(rl.GetFrameTime())
|
||||||
|
|
||||||
// Physics steps calculations
|
// Physics steps calculations
|
||||||
g.World.Step(g.TimeStep)
|
g.World.Step(g.TimeStep)
|
||||||
|
@ -66,7 +66,7 @@ func (g *Game) Draw() {
|
||||||
g.DrawJoint(j)
|
g.DrawJoint(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Use keys 1-9 to switch current demo", 20, 20, 10, raylib.RayWhite)
|
rl.DrawText("Use keys 1-9 to switch current demo", 20, 20, 10, rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawBody - Draw body
|
// DrawBody - Draw body
|
||||||
|
@ -83,10 +83,10 @@ func (g *Game) DrawBody(b *box2d.Body) {
|
||||||
v3 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{h.X, h.Y}))))
|
v3 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{h.X, h.Y}))))
|
||||||
v4 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{-h.X, h.Y}))))
|
v4 := o.Add(S.MulV(x.Add(R.MulV(box2d.Vec2{-h.X, h.Y}))))
|
||||||
|
|
||||||
raylib.DrawLine(int32(v1.X), int32(v1.Y), int32(v2.X), int32(v2.Y), raylib.RayWhite)
|
rl.DrawLine(int32(v1.X), int32(v1.Y), int32(v2.X), int32(v2.Y), rl.RayWhite)
|
||||||
raylib.DrawLine(int32(v2.X), int32(v2.Y), int32(v3.X), int32(v3.Y), raylib.RayWhite)
|
rl.DrawLine(int32(v2.X), int32(v2.Y), int32(v3.X), int32(v3.Y), rl.RayWhite)
|
||||||
raylib.DrawLine(int32(v3.X), int32(v3.Y), int32(v4.X), int32(v4.Y), raylib.RayWhite)
|
rl.DrawLine(int32(v3.X), int32(v3.Y), int32(v4.X), int32(v4.Y), rl.RayWhite)
|
||||||
raylib.DrawLine(int32(v4.X), int32(v4.Y), int32(v1.X), int32(v1.Y), raylib.RayWhite)
|
rl.DrawLine(int32(v4.X), int32(v4.Y), int32(v1.X), int32(v1.Y), rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawJoint - Draw joint
|
// DrawJoint - Draw joint
|
||||||
|
@ -111,8 +111,8 @@ func (g *Game) DrawJoint(j *box2d.Joint) {
|
||||||
x2 = o.Add(S.MulV(x2))
|
x2 = o.Add(S.MulV(x2))
|
||||||
p2 = o.Add(S.MulV(p2))
|
p2 = o.Add(S.MulV(p2))
|
||||||
|
|
||||||
raylib.DrawLine(int32(x1.X), int32(x1.Y), int32(p1.X), int32(p1.Y), raylib.RayWhite)
|
rl.DrawLine(int32(x1.X), int32(x1.Y), int32(p1.X), int32(p1.Y), rl.RayWhite)
|
||||||
raylib.DrawLine(int32(x2.X), int32(x2.Y), int32(p2.X), int32(p2.Y), raylib.RayWhite)
|
rl.DrawLine(int32(x2.X), int32(x2.Y), int32(p2.X), int32(p2.Y), rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Demo1 - Single box
|
// Demo1 - Single box
|
||||||
|
@ -489,25 +489,25 @@ func (g *Game) Demo9() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [physics] example - box2d")
|
rl.InitWindow(800, 450, "raylib [physics] example - box2d")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
game := NewGame()
|
game := NewGame()
|
||||||
|
|
||||||
game.Demo1()
|
game.Demo1()
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
game.Update()
|
game.Update()
|
||||||
|
|
||||||
game.Draw()
|
game.Draw()
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,163 +1,139 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
|
||||||
"github.com/gen2brain/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
"github.com/jakecoffman/cp"
|
|
||||||
|
"github.com/vova616/chipmunk"
|
||||||
|
"github.com/vova616/chipmunk/vect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var grabbableMaskBit uint = 1 << 31
|
const (
|
||||||
var grabFilter = cp.ShapeFilter{
|
ballRadius = 25
|
||||||
cp.NO_GROUP, grabbableMaskBit, grabbableMaskBit,
|
ballMass = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Game type
|
||||||
|
type Game struct {
|
||||||
|
Space *chipmunk.Space
|
||||||
|
Balls []*chipmunk.Shape
|
||||||
|
StaticLines []*chipmunk.Shape
|
||||||
|
|
||||||
|
ticksToNextBall int
|
||||||
}
|
}
|
||||||
|
|
||||||
func randUnitCircle() cp.Vector {
|
// NewGame - Start new game
|
||||||
v := cp.Vector{X: rand.Float64()*2.0 - 1.0, Y: rand.Float64()*2.0 - 1.0}
|
func NewGame() (g Game) {
|
||||||
if v.LengthSq() < 1.0 {
|
g.Init()
|
||||||
return v
|
return
|
||||||
}
|
|
||||||
return randUnitCircle()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var simpleTerrainVerts = []cp.Vector{
|
// Init - Initialize game
|
||||||
{350.00, 425.07}, {336.00, 436.55}, {272.00, 435.39}, {258.00, 427.63}, {225.28, 420.00}, {202.82, 396.00},
|
func (g *Game) Init() {
|
||||||
{191.81, 388.00}, {189.00, 381.89}, {173.00, 380.39}, {162.59, 368.00}, {150.47, 319.00}, {128.00, 311.55},
|
g.createBodies()
|
||||||
{119.14, 286.00}, {126.84, 263.00}, {120.56, 227.00}, {141.14, 178.00}, {137.52, 162.00}, {146.51, 142.00},
|
|
||||||
{156.23, 136.00}, {158.00, 118.27}, {170.00, 100.77}, {208.43, 84.00}, {224.00, 69.65}, {249.30, 68.00},
|
g.ticksToNextBall = 10
|
||||||
{257.00, 54.77}, {363.00, 45.94}, {374.15, 54.00}, {386.00, 69.60}, {413.00, 70.73}, {456.00, 84.89},
|
|
||||||
{468.09, 99.00}, {467.09, 123.00}, {464.92, 135.00}, {469.00, 141.03}, {497.00, 148.67}, {513.85, 180.00},
|
|
||||||
{509.56, 223.00}, {523.51, 247.00}, {523.00, 277.00}, {497.79, 311.00}, {478.67, 348.00}, {467.90, 360.00},
|
|
||||||
{456.76, 382.00}, {432.95, 389.00}, {417.00, 411.32}, {373.00, 433.19}, {361.00, 430.02}, {350.00, 425.07},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a circle with random placement
|
// Update - Update game
|
||||||
func addCircle(space *cp.Space, radius float64) {
|
func (g *Game) Update() {
|
||||||
mass := radius * radius / 25.0
|
g.ticksToNextBall--
|
||||||
body := space.AddBody(cp.NewBody(mass, cp.MomentForCircle(mass, 0, radius, cp.Vector{})))
|
if g.ticksToNextBall == 0 {
|
||||||
body.SetPosition(randUnitCircle().Mult(180))
|
g.ticksToNextBall = rand.Intn(100) + 1
|
||||||
|
g.addBall()
|
||||||
shape := space.AddShape(cp.NewCircle(body, radius, cp.Vector{}))
|
|
||||||
shape.SetElasticity(0)
|
|
||||||
shape.SetFriction(0.9)
|
|
||||||
}
|
|
||||||
|
|
||||||
// creates a simple terrain to contain bodies
|
|
||||||
func simpleTerrain() *cp.Space {
|
|
||||||
space := cp.NewSpace()
|
|
||||||
space.Iterations = 10
|
|
||||||
space.SetGravity(cp.Vector{0, -100})
|
|
||||||
space.SetCollisionSlop(0.5)
|
|
||||||
|
|
||||||
offset := cp.Vector{X: -320, Y: -240}
|
|
||||||
for i := 0; i < len(simpleTerrainVerts)-1; i++ {
|
|
||||||
a := simpleTerrainVerts[i]
|
|
||||||
b := simpleTerrainVerts[i+1]
|
|
||||||
space.AddShape(cp.NewSegment(space.StaticBody, a.Add(offset), b.Add(offset), 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return space
|
// Physics steps calculations
|
||||||
|
g.step(rl.GetFrameTime())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw - Draw game
|
||||||
|
func (g *Game) Draw() {
|
||||||
|
for i := range g.StaticLines {
|
||||||
|
x := g.StaticLines[i].GetAsSegment().A.X
|
||||||
|
y := g.StaticLines[i].GetAsSegment().A.Y
|
||||||
|
|
||||||
|
x2 := g.StaticLines[i].GetAsSegment().B.X
|
||||||
|
y2 := g.StaticLines[i].GetAsSegment().B.Y
|
||||||
|
|
||||||
|
rl.DrawLine(int32(x), int32(y), int32(x2), int32(y2), rl.DarkBlue)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, b := range g.Balls {
|
||||||
|
pos := b.Body.Position()
|
||||||
|
rl.DrawCircleLines(int32(pos.X), int32(pos.Y), float32(ballRadius), rl.DarkBlue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// createBodies sets up the chipmunk space and static bodies
|
||||||
|
func (g *Game) createBodies() {
|
||||||
|
g.Space = chipmunk.NewSpace()
|
||||||
|
g.Space.Gravity = vect.Vect{0, 900}
|
||||||
|
|
||||||
|
staticBody := chipmunk.NewBodyStatic()
|
||||||
|
g.StaticLines = []*chipmunk.Shape{
|
||||||
|
chipmunk.NewSegment(vect.Vect{250.0, 240.0}, vect.Vect{550.0, 280.0}, 0),
|
||||||
|
chipmunk.NewSegment(vect.Vect{550.0, 280.0}, vect.Vect{550.0, 180.0}, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, segment := range g.StaticLines {
|
||||||
|
segment.SetElasticity(0.6)
|
||||||
|
staticBody.AddShape(segment)
|
||||||
|
}
|
||||||
|
|
||||||
|
g.Space.AddBody(staticBody)
|
||||||
|
}
|
||||||
|
|
||||||
|
// addBall adds ball to chipmunk space and body
|
||||||
|
func (g *Game) addBall() {
|
||||||
|
x := rand.Intn(600-200) + 200
|
||||||
|
ball := chipmunk.NewCircle(vect.Vector_Zero, float32(ballRadius))
|
||||||
|
ball.SetElasticity(0.95)
|
||||||
|
|
||||||
|
body := chipmunk.NewBody(vect.Float(ballMass), ball.Moment(float32(ballMass)))
|
||||||
|
body.SetPosition(vect.Vect{vect.Float(x), 0.0})
|
||||||
|
body.SetAngle(vect.Float(rand.Float32() * 2 * math.Pi))
|
||||||
|
body.AddShape(ball)
|
||||||
|
|
||||||
|
g.Space.AddBody(body)
|
||||||
|
g.Balls = append(g.Balls, ball)
|
||||||
|
}
|
||||||
|
|
||||||
|
// step advances the physics engine and cleans up any balls that are off-screen
|
||||||
|
func (g *Game) step(dt float32) {
|
||||||
|
g.Space.Step(vect.Float(dt))
|
||||||
|
|
||||||
|
for i := 0; i < len(g.Balls); i++ {
|
||||||
|
p := g.Balls[i].Body.Position()
|
||||||
|
if p.Y < -100 {
|
||||||
|
g.Space.RemoveBody(g.Balls[i].Body)
|
||||||
|
g.Balls[i] = nil
|
||||||
|
g.Balls = append(g.Balls[:i], g.Balls[i+1:]...)
|
||||||
|
i-- // consider same index again
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
const width, height = 800, 450
|
rl.InitWindow(800, 450, "raylib [physics] example - chipmunk")
|
||||||
const physicsTickrate = 1.0 / 60.0
|
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
rl.SetTargetFPS(60)
|
||||||
raylib.InitWindow(width, height, "raylib [physics] example - chipmunk")
|
|
||||||
|
|
||||||
offset := raylib.Vector2{X: width / 2, Y: height / 2}
|
game := NewGame()
|
||||||
// since the example ported from elsewhere, flip the camera 180 and offset to center it
|
|
||||||
camera := raylib.NewCamera2D(offset, raylib.Vector2{}, 180, 1)
|
|
||||||
|
|
||||||
space := simpleTerrain()
|
for !rl.WindowShouldClose() {
|
||||||
for i := 0; i < 1000; i++ {
|
rl.BeginDrawing()
|
||||||
addCircle(space, 5)
|
|
||||||
}
|
|
||||||
mouseBody := cp.NewKinematicBody()
|
|
||||||
var mouse cp.Vector
|
|
||||||
var mouseJoint *cp.Constraint
|
|
||||||
|
|
||||||
var accumulator, dt float32
|
rl.ClearBackground(rl.RayWhite)
|
||||||
lastTime := raylib.GetTime()
|
|
||||||
for !raylib.WindowShouldClose() {
|
|
||||||
// calculate dt
|
|
||||||
now := raylib.GetTime()
|
|
||||||
dt = now - lastTime
|
|
||||||
lastTime = now
|
|
||||||
|
|
||||||
// update the mouse position
|
game.Update()
|
||||||
mousePos := raylib.GetMousePosition()
|
|
||||||
// alter the mouse coordinates based on the camera position, rotation
|
|
||||||
mouse.X = float64(mousePos.X-camera.Offset.X) * -1
|
|
||||||
mouse.Y = float64(mousePos.Y-camera.Offset.Y) * -1
|
|
||||||
// smooth mouse movements to new position
|
|
||||||
newPoint := mouseBody.Position().Lerp(mouse, 0.25)
|
|
||||||
mouseBody.SetVelocityVector(newPoint.Sub(mouseBody.Position()).Mult(60.0))
|
|
||||||
mouseBody.SetPosition(newPoint)
|
|
||||||
|
|
||||||
// handle grabbing
|
game.Draw()
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
|
||||||
result := space.PointQueryNearest(mouse, 5, grabFilter)
|
|
||||||
if result.Shape != nil && result.Shape.Body().Mass() < cp.INFINITY {
|
|
||||||
var nearest cp.Vector
|
|
||||||
if result.Distance > 0 {
|
|
||||||
nearest = result.Point
|
|
||||||
} else {
|
|
||||||
nearest = mouse
|
|
||||||
}
|
|
||||||
|
|
||||||
// create a new constraint where the mouse is to draw the body towards the mouse
|
rl.EndDrawing()
|
||||||
body := result.Shape.Body()
|
|
||||||
mouseJoint = cp.NewPivotJoint2(mouseBody, body, cp.Vector{}, body.WorldToLocal(nearest))
|
|
||||||
mouseJoint.SetMaxForce(50000)
|
|
||||||
mouseJoint.SetErrorBias(math.Pow(1.0-0.15, 60.0))
|
|
||||||
space.AddConstraint(mouseJoint)
|
|
||||||
}
|
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) && mouseJoint != nil {
|
|
||||||
space.RemoveConstraint(mouseJoint)
|
|
||||||
mouseJoint = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform a fixed rate physics tick
|
|
||||||
accumulator += dt
|
|
||||||
for accumulator >= physicsTickrate {
|
|
||||||
space.Step(physicsTickrate)
|
|
||||||
accumulator -= physicsTickrate
|
|
||||||
}
|
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
|
||||||
raylib.BeginMode2D(camera)
|
|
||||||
|
|
||||||
// this is a generic way to iterate over the shapes in a space,
|
|
||||||
// to avoid the type switch just keep a pointer to the shapes when they've been created
|
|
||||||
space.EachShape(func(s *cp.Shape) {
|
|
||||||
switch s.Class.(type) {
|
|
||||||
case *cp.Segment:
|
|
||||||
segment := s.Class.(*cp.Segment)
|
|
||||||
a := segment.A()
|
|
||||||
b := segment.B()
|
|
||||||
raylib.DrawLineV(v(a), v(b), raylib.Black)
|
|
||||||
case *cp.Circle:
|
|
||||||
circle := s.Class.(*cp.Circle)
|
|
||||||
pos := circle.Body().Position()
|
|
||||||
raylib.DrawCircleV(v(pos), float32(circle.Radius()), raylib.Red)
|
|
||||||
default:
|
|
||||||
fmt.Println("unexpected shape", s.Class)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
raylib.EndMode2D()
|
|
||||||
raylib.DrawFPS(0, 0)
|
|
||||||
raylib.EndDrawing()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
|
||||||
|
|
||||||
func v(v cp.Vector) raylib.Vector2 {
|
|
||||||
return raylib.Vector2{X: float32(v.X), Y: float32(v.Y)}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,46 +9,46 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics demo")
|
||||||
|
|
||||||
// Physac logo drawing position
|
// Physac logo drawing position
|
||||||
logoX := screenWidth - raylib.MeasureText("Physac", 30) - 10
|
logoX := screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||||
logoY := int32(15)
|
logoY := int32(15)
|
||||||
|
|
||||||
// Initialize physics and default physics bodies
|
// Initialize physics and default physics bodies
|
||||||
physics.Init()
|
physics.Init()
|
||||||
|
|
||||||
// Create floor rectangle physics body
|
// Create floor rectangle physics body
|
||||||
floor := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
floor := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
|
||||||
// Create obstacle circle physics body
|
// Create obstacle circle physics body
|
||||||
circle := physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
circle := physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||||
circle.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
circle.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
|
|
||||||
// Update created physics objects
|
// Update created physics objects
|
||||||
physics.Update()
|
physics.Update()
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||||
physics.Reset()
|
physics.Reset()
|
||||||
|
|
||||||
floor = physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
floor = physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), 500, 100, 10)
|
||||||
floor.Enabled = false
|
floor.Enabled = false
|
||||||
|
|
||||||
circle = physics.NewBodyCircle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
circle = physics.NewBodyCircle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)/2), 45, 10)
|
||||||
circle.Enabled = false
|
circle.Enabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Physics body creation inputs
|
// Physics body creation inputs
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
physics.NewBodyPolygon(raylib.GetMousePosition(), float32(raylib.GetRandomValue(20, 80)), int(raylib.GetRandomValue(3, 8)), 10)
|
physics.NewBodyPolygon(rl.GetMousePosition(), float32(rl.GetRandomValue(20, 80)), int(rl.GetRandomValue(3, 8)), 10)
|
||||||
} else if raylib.IsMouseButtonPressed(raylib.MouseRightButton) {
|
} else if rl.IsMouseButtonPressed(rl.MouseRightButton) {
|
||||||
physics.NewBodyCircle(raylib.GetMousePosition(), float32(raylib.GetRandomValue(10, 45)), 10)
|
physics.NewBodyCircle(rl.GetMousePosition(), float32(rl.GetRandomValue(10, 45)), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy falling physics bodies
|
// Destroy falling physics bodies
|
||||||
|
@ -58,11 +58,11 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
raylib.DrawFPS(screenWidth-90, screenHeight-30)
|
rl.DrawFPS(screenWidth-90, screenHeight-30)
|
||||||
|
|
||||||
// Draw created physics bodies
|
// Draw created physics bodies
|
||||||
for i, body := range physics.GetBodies() {
|
for i, body := range physics.GetBodies() {
|
||||||
|
@ -79,21 +79,21 @@ func main() {
|
||||||
|
|
||||||
vertexB := body.GetShapeVertex(jj)
|
vertexB := body.GetShapeVertex(jj)
|
||||||
|
|
||||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Left mouse button to create a polygon", 10, 10, 10, raylib.White)
|
rl.DrawText("Left mouse button to create a polygon", 10, 10, 10, rl.White)
|
||||||
raylib.DrawText("Right mouse button to create a circle", 10, 25, 10, raylib.White)
|
rl.DrawText("Right mouse button to create a circle", 10, 25, 10, rl.White)
|
||||||
raylib.DrawText("Press 'R' to reset example", 10, 40, 10, raylib.White)
|
rl.DrawText("Press 'R' to reset example", 10, 40, 10, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.Close() // Unitialize physics
|
physics.Close() // Unitialize physics
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,67 +9,67 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics friction")
|
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib] - physics friction")
|
||||||
|
|
||||||
// Physac logo drawing position
|
// Physac logo drawing position
|
||||||
logoX := screenWidth - raylib.MeasureText("Physac", 30) - 10
|
logoX := screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||||
logoY := int32(15)
|
logoY := int32(15)
|
||||||
|
|
||||||
// Initialize physics and default physics bodies
|
// Initialize physics and default physics bodies
|
||||||
physics.Init()
|
physics.Init()
|
||||||
|
|
||||||
// Create floor rectangle physics body
|
// Create floor rectangle physics body
|
||||||
floor := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)), float32(screenHeight), 100, 10)
|
floor := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)), float32(screenHeight), 100, 10)
|
||||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
wall := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)/2, float32(screenHeight)*0.8), 10, 80, 10)
|
wall := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)/2, float32(screenHeight)*0.8), 10, 80, 10)
|
||||||
wall.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
wall.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
|
|
||||||
// Create left ramp physics body
|
// Create left ramp physics body
|
||||||
rectLeft := physics.NewBodyRectangle(raylib.NewVector2(25, float32(screenHeight)-5), 250, 250, 10)
|
rectLeft := physics.NewBodyRectangle(rl.NewVector2(25, float32(screenHeight)-5), 250, 250, 10)
|
||||||
rectLeft.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
rectLeft.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
rectLeft.SetRotation(30 * raylib.Deg2rad)
|
rectLeft.SetRotation(30 * rl.Deg2rad)
|
||||||
|
|
||||||
// Create right ramp physics body
|
// Create right ramp physics body
|
||||||
rectRight := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)-25, float32(screenHeight)-5), 250, 250, 10)
|
rectRight := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)-25, float32(screenHeight)-5), 250, 250, 10)
|
||||||
rectRight.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
rectRight.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
rectRight.SetRotation(330 * raylib.Deg2rad)
|
rectRight.SetRotation(330 * rl.Deg2rad)
|
||||||
|
|
||||||
// Create dynamic physics bodies
|
// Create dynamic physics bodies
|
||||||
bodyA := physics.NewBodyRectangle(raylib.NewVector2(35, float32(screenHeight)*0.6), 40, 40, 10)
|
bodyA := physics.NewBodyRectangle(rl.NewVector2(35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||||
bodyA.StaticFriction = 0.1
|
bodyA.StaticFriction = 0.1
|
||||||
bodyA.DynamicFriction = 0.1
|
bodyA.DynamicFriction = 0.1
|
||||||
bodyA.SetRotation(30 * raylib.Deg2rad)
|
bodyA.SetRotation(30 * rl.Deg2rad)
|
||||||
|
|
||||||
bodyB := physics.NewBodyRectangle(raylib.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6), 40, 40, 10)
|
bodyB := physics.NewBodyRectangle(rl.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6), 40, 40, 10)
|
||||||
bodyB.StaticFriction = 1
|
bodyB.StaticFriction = 1
|
||||||
bodyB.DynamicFriction = 1
|
bodyB.DynamicFriction = 1
|
||||||
bodyB.SetRotation(330 * raylib.Deg2rad)
|
bodyB.SetRotation(330 * rl.Deg2rad)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Physics steps calculations
|
// Physics steps calculations
|
||||||
physics.Update()
|
physics.Update()
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||||
// Reset dynamic physics bodies position, velocity and rotation
|
// Reset dynamic physics bodies position, velocity and rotation
|
||||||
bodyA.Position = raylib.NewVector2(35, float32(screenHeight)*0.6)
|
bodyA.Position = rl.NewVector2(35, float32(screenHeight)*0.6)
|
||||||
bodyA.Velocity = raylib.NewVector2(0, 0)
|
bodyA.Velocity = rl.NewVector2(0, 0)
|
||||||
bodyA.AngularVelocity = 0
|
bodyA.AngularVelocity = 0
|
||||||
bodyA.SetRotation(30 * raylib.Deg2rad)
|
bodyA.SetRotation(30 * rl.Deg2rad)
|
||||||
|
|
||||||
bodyB.Position = raylib.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6)
|
bodyB.Position = rl.NewVector2(float32(screenWidth)-35, float32(screenHeight)*0.6)
|
||||||
bodyB.Velocity = raylib.NewVector2(0, 0)
|
bodyB.Velocity = rl.NewVector2(0, 0)
|
||||||
bodyB.AngularVelocity = 0
|
bodyB.AngularVelocity = 0
|
||||||
bodyB.SetRotation(330 * raylib.Deg2rad)
|
bodyB.SetRotation(330 * rl.Deg2rad)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
raylib.DrawFPS(screenWidth-90, screenHeight-30)
|
rl.DrawFPS(screenWidth-90, screenHeight-30)
|
||||||
|
|
||||||
// Draw created physics bodies
|
// Draw created physics bodies
|
||||||
bodiesCount := physics.GetBodiesCount()
|
bodiesCount := physics.GetBodiesCount()
|
||||||
|
@ -89,25 +89,25 @@ func main() {
|
||||||
|
|
||||||
vertexB := body.GetShapeVertex(jj)
|
vertexB := body.GetShapeVertex(jj)
|
||||||
|
|
||||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangle(0, screenHeight-49, screenWidth, 49, raylib.Black)
|
rl.DrawRectangle(0, screenHeight-49, screenWidth, 49, rl.Black)
|
||||||
|
|
||||||
raylib.DrawText("Friction amount", (screenWidth-raylib.MeasureText("Friction amount", 30))/2, 75, 30, raylib.White)
|
rl.DrawText("Friction amount", (screenWidth-rl.MeasureText("Friction amount", 30))/2, 75, 30, rl.White)
|
||||||
raylib.DrawText("0.1", int32(bodyA.Position.X)-raylib.MeasureText("0.1", 20)/2, int32(bodyA.Position.Y)-7, 20, raylib.White)
|
rl.DrawText("0.1", int32(bodyA.Position.X)-rl.MeasureText("0.1", 20)/2, int32(bodyA.Position.Y)-7, 20, rl.White)
|
||||||
raylib.DrawText("1", int32(bodyB.Position.X)-raylib.MeasureText("1", 20)/2, int32(bodyB.Position.Y)-7, 20, raylib.White)
|
rl.DrawText("1", int32(bodyB.Position.X)-rl.MeasureText("1", 20)/2, int32(bodyB.Position.Y)-7, 20, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Press 'R' to reset example", 10, 10, 10, raylib.White)
|
rl.DrawText("Press 'R' to reset example", 10, 10, 10, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.Close() // Unitialize physics
|
physics.Close() // Unitialize physics
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,22 @@ func main() {
|
||||||
screenWidth := float32(800)
|
screenWidth := float32(800)
|
||||||
screenHeight := float32(450)
|
screenHeight := float32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics movement")
|
||||||
|
|
||||||
// Physac logo drawing position
|
// Physac logo drawing position
|
||||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||||
logoY := int32(15)
|
logoY := int32(15)
|
||||||
|
|
||||||
// Initialize physics and default physics bodies
|
// Initialize physics and default physics bodies
|
||||||
physics.Init()
|
physics.Init()
|
||||||
|
|
||||||
// Create floor and walls rectangle physics body
|
// Create floor and walls rectangle physics body
|
||||||
floor := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||||
platformLeft := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
platformLeft := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.25, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||||
platformRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
platformRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth*0.75, screenHeight*0.6), screenWidth*0.25, 10, 10)
|
||||||
wallLeft := physics.NewBodyRectangle(raylib.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
wallLeft := physics.NewBodyRectangle(rl.NewVector2(-5, screenHeight/2), 10, screenHeight, 10)
|
||||||
wallRight := physics.NewBodyRectangle(raylib.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
wallRight := physics.NewBodyRectangle(rl.NewVector2(screenWidth+5, screenHeight/2), 10, screenHeight, 10)
|
||||||
|
|
||||||
// Disable dynamics to floor and walls physics bodies
|
// Disable dynamics to floor and walls physics bodies
|
||||||
floor.Enabled = false
|
floor.Enabled = false
|
||||||
|
@ -38,38 +38,38 @@ func main() {
|
||||||
wallRight.Enabled = false
|
wallRight.Enabled = false
|
||||||
|
|
||||||
// Create movement physics body
|
// Create movement physics body
|
||||||
body := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
body := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight/2), 50, 50, 1)
|
||||||
body.FreezeOrient = true // Constrain body rotation to avoid little collision torque amounts
|
body.FreezeOrient = true // Constrain body rotation to avoid little collision torque amounts
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update created physics objects
|
// Update created physics objects
|
||||||
physics.Update()
|
physics.Update()
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||||
// Reset movement physics body position, velocity and rotation
|
// Reset movement physics body position, velocity and rotation
|
||||||
body.Position = raylib.NewVector2(screenWidth/2, screenHeight/2)
|
body.Position = rl.NewVector2(screenWidth/2, screenHeight/2)
|
||||||
body.Velocity = raylib.NewVector2(0, 0)
|
body.Velocity = rl.NewVector2(0, 0)
|
||||||
body.SetRotation(0)
|
body.SetRotation(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Physics body creation inputs
|
// Physics body creation inputs
|
||||||
if raylib.IsKeyDown(raylib.KeyRight) {
|
if rl.IsKeyDown(rl.KeyRight) {
|
||||||
body.Velocity.X = velocity
|
body.Velocity.X = velocity
|
||||||
} else if raylib.IsKeyDown(raylib.KeyLeft) {
|
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
body.Velocity.X = -velocity
|
body.Velocity.X = -velocity
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyDown(raylib.KeyUp) && body.IsGrounded {
|
if rl.IsKeyDown(rl.KeyUp) && body.IsGrounded {
|
||||||
body.Velocity.Y = -velocity * 4
|
body.Velocity.Y = -velocity * 4
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
raylib.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
rl.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||||
|
|
||||||
// Draw created physics bodies
|
// Draw created physics bodies
|
||||||
for i, body := range physics.GetBodies() {
|
for i, body := range physics.GetBodies() {
|
||||||
|
@ -86,20 +86,20 @@ func main() {
|
||||||
|
|
||||||
vertexB := body.GetShapeVertex(jj)
|
vertexB := body.GetShapeVertex(jj)
|
||||||
|
|
||||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Use 'ARROWS' to move player", 10, 10, 10, raylib.White)
|
rl.DrawText("Use 'ARROWS' to move player", 10, 10, 10, rl.White)
|
||||||
raylib.DrawText("Press 'R' to reset example", 10, 30, 10, raylib.White)
|
rl.DrawText("Press 'R' to reset example", 10, 30, 10, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.Close() // Unitialize physics
|
physics.Close() // Unitialize physics
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,50 +13,50 @@ func main() {
|
||||||
screenWidth := float32(800)
|
screenWidth := float32(800)
|
||||||
screenHeight := float32(450)
|
screenHeight := float32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - physics restitution")
|
||||||
|
|
||||||
// Physac logo drawing position
|
// Physac logo drawing position
|
||||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||||
logoY := int32(15)
|
logoY := int32(15)
|
||||||
|
|
||||||
// Initialize physics and default physics bodies
|
// Initialize physics and default physics bodies
|
||||||
physics.Init()
|
physics.Init()
|
||||||
|
|
||||||
// Create floor rectangle physics body
|
// Create floor rectangle physics body
|
||||||
floor := physics.NewBodyRectangle(raylib.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
floor := physics.NewBodyRectangle(rl.NewVector2(screenWidth/2, screenHeight), screenWidth, 100, 10)
|
||||||
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
floor.Enabled = false // Disable body state to convert it to static (no dynamics, but collisions)
|
||||||
floor.Restitution = 1
|
floor.Restitution = 1
|
||||||
|
|
||||||
// Create circles physics body
|
// Create circles physics body
|
||||||
circleA := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
circleA := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.25, screenHeight/2), 30, 10)
|
||||||
circleA.Restitution = 0
|
circleA.Restitution = 0
|
||||||
circleB := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
circleB := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.5, screenHeight/2), 30, 10)
|
||||||
circleB.Restitution = 0.5
|
circleB.Restitution = 0.5
|
||||||
circleC := physics.NewBodyCircle(raylib.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
circleC := physics.NewBodyCircle(rl.NewVector2(screenWidth*0.75, screenHeight/2), 30, 10)
|
||||||
circleC.Restitution = 1
|
circleC.Restitution = 1
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update created physics objects
|
// Update created physics objects
|
||||||
physics.Update()
|
physics.Update()
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||||
// Reset circles physics bodies position and velocity
|
// Reset circles physics bodies position and velocity
|
||||||
circleA.Position = raylib.NewVector2(screenWidth*0.25, screenHeight/2)
|
circleA.Position = rl.NewVector2(screenWidth*0.25, screenHeight/2)
|
||||||
circleA.Velocity = raylib.NewVector2(0, 0)
|
circleA.Velocity = rl.NewVector2(0, 0)
|
||||||
circleB.Position = raylib.NewVector2(screenWidth*0.5, screenHeight/2)
|
circleB.Position = rl.NewVector2(screenWidth*0.5, screenHeight/2)
|
||||||
circleB.Velocity = raylib.NewVector2(0, 0)
|
circleB.Velocity = rl.NewVector2(0, 0)
|
||||||
circleC.Position = raylib.NewVector2(screenWidth*0.75, screenHeight/2)
|
circleC.Position = rl.NewVector2(screenWidth*0.75, screenHeight/2)
|
||||||
circleC.Velocity = raylib.NewVector2(0, 0)
|
circleC.Velocity = rl.NewVector2(0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
raylib.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
rl.DrawFPS(int32(screenWidth)-90, int32(screenHeight)-30)
|
||||||
|
|
||||||
// Draw created physics bodies
|
// Draw created physics bodies
|
||||||
for i, body := range physics.GetBodies() {
|
for i, body := range physics.GetBodies() {
|
||||||
|
@ -73,24 +73,24 @@ func main() {
|
||||||
|
|
||||||
vertexB := body.GetShapeVertex(jj)
|
vertexB := body.GetShapeVertex(jj)
|
||||||
|
|
||||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Restitution amount", (int32(screenWidth)-raylib.MeasureText("Restitution amount", 30))/2, 75, 30, raylib.White)
|
rl.DrawText("Restitution amount", (int32(screenWidth)-rl.MeasureText("Restitution amount", 30))/2, 75, 30, rl.White)
|
||||||
raylib.DrawText("0", int32(circleA.Position.X)-raylib.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, raylib.White)
|
rl.DrawText("0", int32(circleA.Position.X)-rl.MeasureText("0", 20)/2, int32(circleA.Position.Y)-7, 20, rl.White)
|
||||||
raylib.DrawText("0.5", int32(circleB.Position.X)-raylib.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, raylib.White)
|
rl.DrawText("0.5", int32(circleB.Position.X)-rl.MeasureText("0.5", 20)/2, int32(circleB.Position.Y)-7, 20, rl.White)
|
||||||
raylib.DrawText("1", int32(circleC.Position.X)-raylib.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, raylib.White)
|
rl.DrawText("1", int32(circleC.Position.X)-rl.MeasureText("1", 20)/2, int32(circleC.Position.Y)-7, 20, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Press 'R' to reset example", 10, 10, 10, raylib.White)
|
rl.DrawText("Press 'R' to reset example", 10, 10, 10, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.Close() // Unitialize physics
|
physics.Close() // Unitialize physics
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ func main() {
|
||||||
screenWidth := float32(800)
|
screenWidth := float32(800)
|
||||||
screenHeight := float32(450)
|
screenHeight := float32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint)
|
||||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - body shatter")
|
rl.InitWindow(int32(screenWidth), int32(screenHeight), "Physac [raylib] - body shatter")
|
||||||
|
|
||||||
// Physac logo drawing position
|
// Physac logo drawing position
|
||||||
logoX := int32(screenWidth) - raylib.MeasureText("Physac", 30) - 10
|
logoX := int32(screenWidth) - rl.MeasureText("Physac", 30) - 10
|
||||||
logoY := int32(15)
|
logoY := int32(15)
|
||||||
|
|
||||||
// Initialize physics and default physics bodies
|
// Initialize physics and default physics bodies
|
||||||
|
@ -25,30 +25,30 @@ func main() {
|
||||||
physics.SetGravity(0, 0)
|
physics.SetGravity(0, 0)
|
||||||
|
|
||||||
// Create random polygon physics body to shatter
|
// Create random polygon physics body to shatter
|
||||||
physics.NewBodyPolygon(raylib.NewVector2(screenWidth/2, screenHeight/2), float32(raylib.GetRandomValue(80, 200)), int(raylib.GetRandomValue(3, 8)), 10)
|
physics.NewBodyPolygon(rl.NewVector2(screenWidth/2, screenHeight/2), float32(rl.GetRandomValue(80, 200)), int(rl.GetRandomValue(3, 8)), 10)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update created physics objects
|
// Update created physics objects
|
||||||
physics.Update()
|
physics.Update()
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) { // Reset physics input
|
if rl.IsKeyPressed(rl.KeyR) { // Reset physics input
|
||||||
physics.Reset()
|
physics.Reset()
|
||||||
|
|
||||||
// Create random polygon physics body to shatter
|
// Create random polygon physics body to shatter
|
||||||
physics.NewBodyPolygon(raylib.NewVector2(screenWidth/2, screenHeight/2), float32(raylib.GetRandomValue(80, 200)), int(raylib.GetRandomValue(3, 8)), 10)
|
physics.NewBodyPolygon(rl.NewVector2(screenWidth/2, screenHeight/2), float32(rl.GetRandomValue(80, 200)), int(rl.GetRandomValue(3, 8)), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
for _, b := range physics.GetBodies() {
|
for _, b := range physics.GetBodies() {
|
||||||
b.Shatter(raylib.GetMousePosition(), 10/b.InverseMass)
|
b.Shatter(rl.GetMousePosition(), 10/b.InverseMass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.Black)
|
rl.ClearBackground(rl.Black)
|
||||||
|
|
||||||
// Draw created physics bodies
|
// Draw created physics bodies
|
||||||
for i, body := range physics.GetBodies() {
|
for i, body := range physics.GetBodies() {
|
||||||
|
@ -65,19 +65,19 @@ func main() {
|
||||||
|
|
||||||
vertexB := body.GetShapeVertex(jj)
|
vertexB := body.GetShapeVertex(jj)
|
||||||
|
|
||||||
raylib.DrawLineV(vertexA, vertexB, raylib.Green) // Draw a line between two vertex positions
|
rl.DrawLineV(vertexA, vertexB, rl.Green) // Draw a line between two vertex positions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, raylib.White)
|
rl.DrawText("Left mouse button in polygon area to shatter body\nPress 'R' to reset example", 10, 10, 10, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("Physac", logoX, logoY, 30, raylib.White)
|
rl.DrawText("Physac", logoX, logoY, 30, rl.White)
|
||||||
raylib.DrawText("Powered by", logoX+50, logoY-7, 10, raylib.White)
|
rl.DrawText("Powered by", logoX+50, logoY-7, 10, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
physics.Close() // Unitialize physics
|
physics.Close() // Unitialize physics
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,90 +8,90 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
|
|
||||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
shader := rl.LoadShader("glsl330/base.vs", "glsl330/swirl.fs") // Load postpro shader
|
||||||
|
|
||||||
// Get variable (uniform) location on the shader to connect with the program
|
// Get variable (uniform) location on the shader to connect with the program
|
||||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||||
swirlCenterLoc := raylib.GetShaderLocation(shader, "center")
|
swirlCenterLoc := rl.GetShaderLocation(shader, "center")
|
||||||
|
|
||||||
swirlCenter := make([]float32, 2)
|
swirlCenter := make([]float32, 2)
|
||||||
swirlCenter[0] = float32(screenWidth) / 2
|
swirlCenter[0] = float32(screenWidth) / 2
|
||||||
swirlCenter[1] = float32(screenHeight) / 2
|
swirlCenter[1] = float32(screenHeight) / 2
|
||||||
|
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
target := rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set an orbital camera mode
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
mousePosition := raylib.GetMousePosition()
|
mousePosition := rl.GetMousePosition()
|
||||||
|
|
||||||
swirlCenter[0] = mousePosition.X
|
swirlCenter[0] = mousePosition.X
|
||||||
swirlCenter[1] = float32(screenHeight) - mousePosition.Y
|
swirlCenter[1] = float32(screenHeight) - mousePosition.Y
|
||||||
|
|
||||||
// Send new value to the shader to be used on drawing
|
// Send new value to the shader to be used on drawing
|
||||||
raylib.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
rl.SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2)
|
||||||
|
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
rl.BeginTextureMode(target) // Enable drawing to texture
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, raylib.Red)
|
rl.DrawText("TEXT DRAWN IN RENDER TEXTURE", 200, 10, 30, rl.Red)
|
||||||
|
|
||||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
rl.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
raylib.BeginShaderMode(shader)
|
rl.BeginShaderMode(shader)
|
||||||
|
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
raylib.DrawTextureRec(target.Texture, raylib.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), raylib.NewVector2(0, 0), raylib.White)
|
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.White)
|
||||||
|
|
||||||
raylib.EndShaderMode()
|
rl.EndShaderMode()
|
||||||
|
|
||||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadShader(shader) // Unload shader
|
rl.UnloadShader(shader) // Unload shader
|
||||||
raylib.UnloadTexture(texture) // Unload texture
|
rl.UnloadTexture(texture) // Unload texture
|
||||||
raylib.UnloadModel(dwarf) // Unload model
|
rl.UnloadModel(dwarf) // Unload model
|
||||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
rl.UnloadRenderTexture(target) // Unload render texture
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,57 +10,57 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs") // Load model shader
|
||||||
|
|
||||||
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
dwarf.Material.Shader = shader // Set shader effect to 3d model
|
||||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraFree) // Set free camera mode
|
rl.SetCameraMode(camera, rl.CameraFree) // Set free camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("Camera position: (%.2f, %.2f, %.2f)", camera.Position.X, camera.Position.Y, camera.Position.Z), 600, 20, 10, raylib.Black)
|
rl.DrawText(fmt.Sprintf("Camera position: (%.2f, %.2f, %.2f)", camera.Position.X, camera.Position.Y, camera.Position.Z), 600, 20, 10, rl.Black)
|
||||||
raylib.DrawText(fmt.Sprintf("Camera target: (%.2f, %.2f, %.2f)", camera.Target.X, camera.Target.Y, camera.Target.Z), 600, 40, 10, raylib.Gray)
|
rl.DrawText(fmt.Sprintf("Camera target: (%.2f, %.2f, %.2f)", camera.Target.X, camera.Target.Y, camera.Target.Z), 600, 40, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadShader(shader) // Unload shader
|
rl.UnloadShader(shader) // Unload shader
|
||||||
raylib.UnloadTexture(texture) // Unload texture
|
rl.UnloadTexture(texture) // Unload texture
|
||||||
raylib.UnloadModel(dwarf) // Unload model
|
rl.UnloadModel(dwarf) // Unload model
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,53 +40,53 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.SetConfigFlags(raylib.FlagMsaa4xHint | raylib.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
rl.SetConfigFlags(rl.FlagMsaa4xHint | rl.FlagVsyncHint) // Enable Multi Sampling Anti Aliasing 4x (if available)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader")
|
||||||
|
|
||||||
camera := raylib.Camera{}
|
camera := rl.Camera{}
|
||||||
camera.Position = raylib.NewVector3(3.0, 3.0, 3.0)
|
camera.Position = rl.NewVector3(3.0, 3.0, 3.0)
|
||||||
camera.Target = raylib.NewVector3(0.0, 1.5, 0.0)
|
camera.Target = rl.NewVector3(0.0, 1.5, 0.0)
|
||||||
camera.Up = raylib.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
|
||||||
dwarf := raylib.LoadModel("dwarf.obj") // Load OBJ model
|
dwarf := rl.LoadModel("dwarf.obj") // Load OBJ model
|
||||||
texture := raylib.LoadTexture("dwarf_diffuse.png") // Load model texture
|
texture := rl.LoadTexture("dwarf_diffuse.png") // Load model texture
|
||||||
dwarf.Material.Maps[raylib.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
dwarf.Material.Maps[rl.MapDiffuse].Texture = texture // Set dwarf model diffuse texture
|
||||||
|
|
||||||
position := raylib.NewVector3(0.0, 0.0, 0.0) // Set model position
|
position := rl.NewVector3(0.0, 0.0, 0.0) // Set model position
|
||||||
|
|
||||||
// Load all postpro shaders
|
// Load all postpro shaders
|
||||||
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
// NOTE 1: All postpro shader use the base vertex shader (DEFAULT_VERTEX_SHADER)
|
||||||
shaders := make([]raylib.Shader, MaxPostproShaders)
|
shaders := make([]rl.Shader, MaxPostproShaders)
|
||||||
shaders[FxGrayscale] = raylib.LoadShader("", "glsl330/grayscale.fs")
|
shaders[FxGrayscale] = rl.LoadShader("", "glsl330/grayscale.fs")
|
||||||
shaders[FxPosterization] = raylib.LoadShader("", "glsl330/posterization.fs")
|
shaders[FxPosterization] = rl.LoadShader("", "glsl330/posterization.fs")
|
||||||
shaders[FxDreamVision] = raylib.LoadShader("", "glsl330/dream_vision.fs")
|
shaders[FxDreamVision] = rl.LoadShader("", "glsl330/dream_vision.fs")
|
||||||
shaders[FxPixelizer] = raylib.LoadShader("", "glsl330/pixelizer.fs")
|
shaders[FxPixelizer] = rl.LoadShader("", "glsl330/pixelizer.fs")
|
||||||
shaders[FxCrossHatching] = raylib.LoadShader("", "glsl330/cross_hatching.fs")
|
shaders[FxCrossHatching] = rl.LoadShader("", "glsl330/cross_hatching.fs")
|
||||||
shaders[FxCrossStitching] = raylib.LoadShader("", "glsl330/cross_stitching.fs")
|
shaders[FxCrossStitching] = rl.LoadShader("", "glsl330/cross_stitching.fs")
|
||||||
shaders[FxPredatorView] = raylib.LoadShader("", "glsl330/predator.fs")
|
shaders[FxPredatorView] = rl.LoadShader("", "glsl330/predator.fs")
|
||||||
shaders[FxScanlines] = raylib.LoadShader("", "glsl330/scanlines.fs")
|
shaders[FxScanlines] = rl.LoadShader("", "glsl330/scanlines.fs")
|
||||||
shaders[FxFisheye] = raylib.LoadShader("", "glsl330/fisheye.fs")
|
shaders[FxFisheye] = rl.LoadShader("", "glsl330/fisheye.fs")
|
||||||
shaders[FxSobel] = raylib.LoadShader("", "glsl330/sobel.fs")
|
shaders[FxSobel] = rl.LoadShader("", "glsl330/sobel.fs")
|
||||||
shaders[FxBlur] = raylib.LoadShader("", "glsl330/blur.fs")
|
shaders[FxBlur] = rl.LoadShader("", "glsl330/blur.fs")
|
||||||
shaders[FxBloom] = raylib.LoadShader("", "glsl330/bloom.fs")
|
shaders[FxBloom] = rl.LoadShader("", "glsl330/bloom.fs")
|
||||||
|
|
||||||
currentShader := FxGrayscale
|
currentShader := FxGrayscale
|
||||||
|
|
||||||
// Create a RenderTexture2D to be used for render to texture
|
// Create a RenderTexture2D to be used for render to texture
|
||||||
target := raylib.LoadRenderTexture(screenWidth, screenHeight)
|
target := rl.LoadRenderTexture(screenWidth, screenHeight)
|
||||||
|
|
||||||
raylib.SetCameraMode(camera, raylib.CameraOrbital) // Set free camera mode
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set free camera mode
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.UpdateCamera(&camera) // Update camera
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
if rl.IsKeyPressed(rl.KeyRight) {
|
||||||
currentShader++
|
currentShader++
|
||||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
} else if rl.IsKeyPressed(rl.KeyLeft) {
|
||||||
currentShader--
|
currentShader--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,51 +96,51 @@ func main() {
|
||||||
currentShader = MaxPostproShaders - 1
|
currentShader = MaxPostproShaders - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.BeginTextureMode(target) // Enable drawing to texture
|
rl.BeginTextureMode(target) // Enable drawing to texture
|
||||||
|
|
||||||
raylib.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
raylib.DrawModel(dwarf, position, 2.0, raylib.White) // Draw 3d model with texture
|
rl.DrawModel(dwarf, position, 2.0, rl.White) // Draw 3d model with texture
|
||||||
|
|
||||||
raylib.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
raylib.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
raylib.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
rl.EndTextureMode() // End drawing to texture (now we have a texture available for next passes)
|
||||||
|
|
||||||
// Render previously generated texture using selected postpro shader
|
// Render previously generated texture using selected postpro shader
|
||||||
raylib.BeginShaderMode(shaders[currentShader])
|
rl.BeginShaderMode(shaders[currentShader])
|
||||||
|
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
||||||
raylib.DrawTextureRec(target.Texture, raylib.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), raylib.NewVector2(0, 0), raylib.White)
|
rl.DrawTextureRec(target.Texture, rl.NewRectangle(0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)), rl.NewVector2(0, 0), rl.White)
|
||||||
|
|
||||||
raylib.EndShaderMode()
|
rl.EndShaderMode()
|
||||||
|
|
||||||
raylib.DrawRectangle(0, 9, 580, 30, raylib.Fade(raylib.LightGray, 0.7))
|
rl.DrawRectangle(0, 9, 580, 30, rl.Fade(rl.LightGray, 0.7))
|
||||||
|
|
||||||
raylib.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, raylib.DarkGray)
|
rl.DrawText("(c) Dwarf 3D model by David Moreno", screenWidth-200, screenHeight-20, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, raylib.Black)
|
rl.DrawText("CURRENT POSTPRO SHADER:", 10, 15, 20, rl.Black)
|
||||||
raylib.DrawText(postproShaderText[currentShader], 330, 15, 20, raylib.Red)
|
rl.DrawText(postproShaderText[currentShader], 330, 15, 20, rl.Red)
|
||||||
raylib.DrawText("< >", 540, 10, 30, raylib.DarkBlue)
|
rl.DrawText("< >", 540, 10, 30, rl.DarkBlue)
|
||||||
|
|
||||||
raylib.DrawFPS(700, 15)
|
rl.DrawFPS(700, 15)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unload all postpro shaders
|
// Unload all postpro shaders
|
||||||
for i := 0; i < MaxPostproShaders; i++ {
|
for i := 0; i < MaxPostproShaders; i++ {
|
||||||
raylib.UnloadShader(shaders[i])
|
rl.UnloadShader(shaders[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture) // Unload texture
|
rl.UnloadTexture(texture) // Unload texture
|
||||||
raylib.UnloadModel(dwarf) // Unload model
|
rl.UnloadModel(dwarf) // Unload model
|
||||||
raylib.UnloadRenderTexture(target) // Unload render texture
|
rl.UnloadRenderTexture(target) // Unload render texture
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,67 +8,67 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders")
|
||||||
|
|
||||||
fudesumi := raylib.LoadTexture("fudesumi.png")
|
fudesumi := rl.LoadTexture("fudesumi.png")
|
||||||
|
|
||||||
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
// NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version
|
||||||
shader := raylib.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
shader := rl.LoadShader("glsl330/base.vs", "glsl330/grayscale.fs")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
// Start drawing with default shader
|
// Start drawing with default shader
|
||||||
|
|
||||||
raylib.DrawText("USING DEFAULT SHADER", 20, 40, 10, raylib.Red)
|
rl.DrawText("USING DEFAULT SHADER", 20, 40, 10, rl.Red)
|
||||||
|
|
||||||
raylib.DrawCircle(80, 120, 35, raylib.DarkBlue)
|
rl.DrawCircle(80, 120, 35, rl.DarkBlue)
|
||||||
raylib.DrawCircleGradient(80, 220, 60, raylib.Green, raylib.SkyBlue)
|
rl.DrawCircleGradient(80, 220, 60, rl.Green, rl.SkyBlue)
|
||||||
raylib.DrawCircleLines(80, 340, 80, raylib.DarkBlue)
|
rl.DrawCircleLines(80, 340, 80, rl.DarkBlue)
|
||||||
|
|
||||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||||
raylib.BeginShaderMode(shader)
|
rl.BeginShaderMode(shader)
|
||||||
|
|
||||||
raylib.DrawText("USING CUSTOM SHADER", 190, 40, 10, raylib.Red)
|
rl.DrawText("USING CUSTOM SHADER", 190, 40, 10, rl.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(250-60, 90, 120, 60, raylib.Red)
|
rl.DrawRectangle(250-60, 90, 120, 60, rl.Red)
|
||||||
raylib.DrawRectangleGradientH(250-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
rl.DrawRectangleGradientH(250-90, 170, 180, 130, rl.Maroon, rl.Gold)
|
||||||
raylib.DrawRectangleLines(250-40, 320, 80, 60, raylib.Orange)
|
rl.DrawRectangleLines(250-40, 320, 80, 60, rl.Orange)
|
||||||
|
|
||||||
// Activate our default shader for next drawings
|
// Activate our default shader for next drawings
|
||||||
raylib.EndShaderMode()
|
rl.EndShaderMode()
|
||||||
|
|
||||||
raylib.DrawText("USING DEFAULT SHADER", 370, 40, 10, raylib.Red)
|
rl.DrawText("USING DEFAULT SHADER", 370, 40, 10, rl.Red)
|
||||||
|
|
||||||
raylib.DrawTriangle(raylib.NewVector2(430, 80),
|
rl.DrawTriangle(rl.NewVector2(430, 80),
|
||||||
raylib.NewVector2(430-60, 150),
|
rl.NewVector2(430-60, 150),
|
||||||
raylib.NewVector2(430+60, 150), raylib.Violet)
|
rl.NewVector2(430+60, 150), rl.Violet)
|
||||||
|
|
||||||
raylib.DrawTriangleLines(raylib.NewVector2(430, 160),
|
rl.DrawTriangleLines(rl.NewVector2(430, 160),
|
||||||
raylib.NewVector2(430-20, 230),
|
rl.NewVector2(430-20, 230),
|
||||||
raylib.NewVector2(430+20, 230), raylib.DarkBlue)
|
rl.NewVector2(430+20, 230), rl.DarkBlue)
|
||||||
|
|
||||||
raylib.DrawPoly(raylib.NewVector2(430, 320), 6, 80, 0, raylib.Brown)
|
rl.DrawPoly(rl.NewVector2(430, 320), 6, 80, 0, rl.Brown)
|
||||||
|
|
||||||
// Activate our custom shader to be applied on next shapes/textures drawings
|
// Activate our custom shader to be applied on next shapes/textures drawings
|
||||||
raylib.BeginShaderMode(shader)
|
rl.BeginShaderMode(shader)
|
||||||
|
|
||||||
raylib.DrawTexture(fudesumi, 500, -30, raylib.White) // Using custom shader
|
rl.DrawTexture(fudesumi, 500, -30, rl.White) // Using custom shader
|
||||||
|
|
||||||
// Activate our default shader for next drawings
|
// Activate our default shader for next drawings
|
||||||
raylib.EndShaderMode()
|
rl.EndShaderMode()
|
||||||
|
|
||||||
raylib.DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadShader(shader) // Unload shader
|
rl.UnloadShader(shader) // Unload shader
|
||||||
raylib.UnloadTexture(fudesumi) // Unload texture
|
rl.UnloadTexture(fudesumi) // Unload texture
|
||||||
|
|
||||||
raylib.CloseWindow() // Close window and OpenGL context
|
rl.CloseWindow() // Close window and OpenGL context
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,38 +8,38 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("some basic shapes available on raylib", 20, 20, 20, raylib.DarkGray)
|
rl.DrawText("some basic shapes available on raylib", 20, 20, 20, rl.DarkGray)
|
||||||
|
|
||||||
raylib.DrawLine(18, 42, screenWidth-18, 42, raylib.Black)
|
rl.DrawLine(18, 42, screenWidth-18, 42, rl.Black)
|
||||||
|
|
||||||
raylib.DrawCircle(screenWidth/4, 120, 35, raylib.DarkBlue)
|
rl.DrawCircle(screenWidth/4, 120, 35, rl.DarkBlue)
|
||||||
raylib.DrawCircleGradient(screenWidth/4, 220, 60, raylib.Green, raylib.SkyBlue)
|
rl.DrawCircleGradient(screenWidth/4, 220, 60, rl.Green, rl.SkyBlue)
|
||||||
raylib.DrawCircleLines(screenWidth/4, 340, 80, raylib.DarkBlue)
|
rl.DrawCircleLines(screenWidth/4, 340, 80, rl.DarkBlue)
|
||||||
|
|
||||||
raylib.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, raylib.Red)
|
rl.DrawRectangle(screenWidth/4*2-60, 100, 120, 60, rl.Red)
|
||||||
raylib.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, raylib.Maroon, raylib.Gold)
|
rl.DrawRectangleGradientH(screenWidth/4*2-90, 170, 180, 130, rl.Maroon, rl.Gold)
|
||||||
raylib.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, raylib.Orange)
|
rl.DrawRectangleLines(screenWidth/4*2-40, 320, 80, 60, rl.Orange)
|
||||||
|
|
||||||
raylib.DrawTriangle(raylib.NewVector2(float32(screenWidth)/4*3, 80),
|
rl.DrawTriangle(rl.NewVector2(float32(screenWidth)/4*3, 80),
|
||||||
raylib.NewVector2(float32(screenWidth)/4*3-60, 150),
|
rl.NewVector2(float32(screenWidth)/4*3-60, 150),
|
||||||
raylib.NewVector2(float32(screenWidth)/4*3+60, 150), raylib.Violet)
|
rl.NewVector2(float32(screenWidth)/4*3+60, 150), rl.Violet)
|
||||||
|
|
||||||
raylib.DrawTriangleLines(raylib.NewVector2(float32(screenWidth)/4*3, 160),
|
rl.DrawTriangleLines(rl.NewVector2(float32(screenWidth)/4*3, 160),
|
||||||
raylib.NewVector2(float32(screenWidth)/4*3-20, 230),
|
rl.NewVector2(float32(screenWidth)/4*3-20, 230),
|
||||||
raylib.NewVector2(float32(screenWidth)/4*3+20, 230), raylib.DarkBlue)
|
rl.NewVector2(float32(screenWidth)/4*3+20, 230), rl.DarkBlue)
|
||||||
|
|
||||||
raylib.DrawPoly(raylib.NewVector2(float32(screenWidth)/4*3, 320), 6, 80, 0, raylib.Brown)
|
rl.DrawPoly(rl.NewVector2(float32(screenWidth)/4*3, 320), 6, 80, 0, rl.Brown)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,62 +5,62 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
raylib.InitWindow(800, 450, "raylib [shapes] example - raylib color palette")
|
rl.InitWindow(800, 450, "raylib [shapes] example - raylib color palette")
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("raylib color palette", 28, 42, 20, raylib.Black)
|
rl.DrawText("raylib color palette", 28, 42, 20, rl.Black)
|
||||||
|
|
||||||
raylib.DrawRectangle(26, 80, 100, 100, raylib.DarkGray)
|
rl.DrawRectangle(26, 80, 100, 100, rl.DarkGray)
|
||||||
raylib.DrawRectangle(26, 188, 100, 100, raylib.Gray)
|
rl.DrawRectangle(26, 188, 100, 100, rl.Gray)
|
||||||
raylib.DrawRectangle(26, 296, 100, 100, raylib.LightGray)
|
rl.DrawRectangle(26, 296, 100, 100, rl.LightGray)
|
||||||
raylib.DrawRectangle(134, 80, 100, 100, raylib.Maroon)
|
rl.DrawRectangle(134, 80, 100, 100, rl.Maroon)
|
||||||
raylib.DrawRectangle(134, 188, 100, 100, raylib.Red)
|
rl.DrawRectangle(134, 188, 100, 100, rl.Red)
|
||||||
raylib.DrawRectangle(134, 296, 100, 100, raylib.Pink)
|
rl.DrawRectangle(134, 296, 100, 100, rl.Pink)
|
||||||
raylib.DrawRectangle(242, 80, 100, 100, raylib.Orange)
|
rl.DrawRectangle(242, 80, 100, 100, rl.Orange)
|
||||||
raylib.DrawRectangle(242, 188, 100, 100, raylib.Gold)
|
rl.DrawRectangle(242, 188, 100, 100, rl.Gold)
|
||||||
raylib.DrawRectangle(242, 296, 100, 100, raylib.Yellow)
|
rl.DrawRectangle(242, 296, 100, 100, rl.Yellow)
|
||||||
raylib.DrawRectangle(350, 80, 100, 100, raylib.DarkGreen)
|
rl.DrawRectangle(350, 80, 100, 100, rl.DarkGreen)
|
||||||
raylib.DrawRectangle(350, 188, 100, 100, raylib.Lime)
|
rl.DrawRectangle(350, 188, 100, 100, rl.Lime)
|
||||||
raylib.DrawRectangle(350, 296, 100, 100, raylib.Green)
|
rl.DrawRectangle(350, 296, 100, 100, rl.Green)
|
||||||
raylib.DrawRectangle(458, 80, 100, 100, raylib.DarkBlue)
|
rl.DrawRectangle(458, 80, 100, 100, rl.DarkBlue)
|
||||||
raylib.DrawRectangle(458, 188, 100, 100, raylib.Blue)
|
rl.DrawRectangle(458, 188, 100, 100, rl.Blue)
|
||||||
raylib.DrawRectangle(458, 296, 100, 100, raylib.SkyBlue)
|
rl.DrawRectangle(458, 296, 100, 100, rl.SkyBlue)
|
||||||
raylib.DrawRectangle(566, 80, 100, 100, raylib.DarkPurple)
|
rl.DrawRectangle(566, 80, 100, 100, rl.DarkPurple)
|
||||||
raylib.DrawRectangle(566, 188, 100, 100, raylib.Violet)
|
rl.DrawRectangle(566, 188, 100, 100, rl.Violet)
|
||||||
raylib.DrawRectangle(566, 296, 100, 100, raylib.Purple)
|
rl.DrawRectangle(566, 296, 100, 100, rl.Purple)
|
||||||
raylib.DrawRectangle(674, 80, 100, 100, raylib.DarkBrown)
|
rl.DrawRectangle(674, 80, 100, 100, rl.DarkBrown)
|
||||||
raylib.DrawRectangle(674, 188, 100, 100, raylib.Brown)
|
rl.DrawRectangle(674, 188, 100, 100, rl.Brown)
|
||||||
raylib.DrawRectangle(674, 296, 100, 100, raylib.Beige)
|
rl.DrawRectangle(674, 296, 100, 100, rl.Beige)
|
||||||
|
|
||||||
raylib.DrawText("DARKGRAY", 65, 166, 10, raylib.Black)
|
rl.DrawText("DARKGRAY", 65, 166, 10, rl.Black)
|
||||||
raylib.DrawText("GRAY", 93, 274, 10, raylib.Black)
|
rl.DrawText("GRAY", 93, 274, 10, rl.Black)
|
||||||
raylib.DrawText("LIGHTGRAY", 61, 382, 10, raylib.Black)
|
rl.DrawText("LIGHTGRAY", 61, 382, 10, rl.Black)
|
||||||
raylib.DrawText("MAROON", 186, 166, 10, raylib.Black)
|
rl.DrawText("MAROON", 186, 166, 10, rl.Black)
|
||||||
raylib.DrawText("RED", 208, 274, 10, raylib.Black)
|
rl.DrawText("RED", 208, 274, 10, rl.Black)
|
||||||
raylib.DrawText("PINK", 204, 382, 10, raylib.Black)
|
rl.DrawText("PINK", 204, 382, 10, rl.Black)
|
||||||
raylib.DrawText("ORANGE", 295, 166, 10, raylib.Black)
|
rl.DrawText("ORANGE", 295, 166, 10, rl.Black)
|
||||||
raylib.DrawText("GOLD", 310, 274, 10, raylib.Black)
|
rl.DrawText("GOLD", 310, 274, 10, rl.Black)
|
||||||
raylib.DrawText("YELLOW", 300, 382, 10, raylib.Black)
|
rl.DrawText("YELLOW", 300, 382, 10, rl.Black)
|
||||||
raylib.DrawText("DARKGREEN", 382, 166, 10, raylib.Black)
|
rl.DrawText("DARKGREEN", 382, 166, 10, rl.Black)
|
||||||
raylib.DrawText("LIME", 420, 274, 10, raylib.Black)
|
rl.DrawText("LIME", 420, 274, 10, rl.Black)
|
||||||
raylib.DrawText("GREEN", 410, 382, 10, raylib.Black)
|
rl.DrawText("GREEN", 410, 382, 10, rl.Black)
|
||||||
raylib.DrawText("DARKBLUE", 498, 166, 10, raylib.Black)
|
rl.DrawText("DARKBLUE", 498, 166, 10, rl.Black)
|
||||||
raylib.DrawText("BLUE", 526, 274, 10, raylib.Black)
|
rl.DrawText("BLUE", 526, 274, 10, rl.Black)
|
||||||
raylib.DrawText("SKYBLUE", 505, 382, 10, raylib.Black)
|
rl.DrawText("SKYBLUE", 505, 382, 10, rl.Black)
|
||||||
raylib.DrawText("DARKPURPLE", 592, 166, 10, raylib.Black)
|
rl.DrawText("DARKPURPLE", 592, 166, 10, rl.Black)
|
||||||
raylib.DrawText("VIOLET", 621, 274, 10, raylib.Black)
|
rl.DrawText("VIOLET", 621, 274, 10, rl.Black)
|
||||||
raylib.DrawText("PURPLE", 620, 382, 10, raylib.Black)
|
rl.DrawText("PURPLE", 620, 382, 10, rl.Black)
|
||||||
raylib.DrawText("DARKBROWN", 705, 166, 10, raylib.Black)
|
rl.DrawText("DARKBROWN", 705, 166, 10, rl.Black)
|
||||||
raylib.DrawText("BROWN", 733, 274, 10, raylib.Black)
|
rl.DrawText("BROWN", 733, 274, 10, rl.Black)
|
||||||
raylib.DrawText("BEIGE", 737, 382, 10, raylib.Black)
|
rl.DrawText("BEIGE", 737, 382, 10, rl.Black)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,29 +8,29 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines")
|
||||||
|
|
||||||
start := raylib.NewVector2(0, 0)
|
start := rl.NewVector2(0, 0)
|
||||||
end := raylib.NewVector2(float32(screenWidth), float32(screenHeight))
|
end := rl.NewVector2(float32(screenWidth), float32(screenHeight))
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
start = raylib.GetMousePosition()
|
start = rl.GetMousePosition()
|
||||||
} else if raylib.IsMouseButtonDown(raylib.MouseRightButton) {
|
} else if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
||||||
end = raylib.GetMousePosition()
|
end = rl.GetMousePosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, raylib.Gray)
|
rl.DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawLineBezier(start, end, 2.0, raylib.Red)
|
rl.DrawLineBezier(start, end, 2.0, rl.Red)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,22 +8,22 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawRectangle(screenWidth/2-128, screenHeight/2-128, 256, 256, raylib.Black)
|
rl.DrawRectangle(screenWidth/2-128, screenHeight/2-128, 256, 256, rl.Black)
|
||||||
raylib.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, raylib.RayWhite)
|
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.RayWhite)
|
||||||
raylib.DrawText("raylib", screenWidth/2-44, screenHeight/2+48, 50, raylib.Black)
|
rl.DrawText("raylib", screenWidth/2-44, screenHeight/2+48, 50, rl.Black)
|
||||||
|
|
||||||
raylib.DrawText("this is NOT a texture!", 350, 370, 10, raylib.Gray)
|
rl.DrawText("this is NOT a texture!", 350, 370, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo animation")
|
||||||
|
|
||||||
logoPositionX := screenWidth/2 - 128
|
logoPositionX := screenWidth/2 - 128
|
||||||
logoPositionY := screenHeight/2 - 128
|
logoPositionY := screenHeight/2 - 128
|
||||||
|
@ -25,9 +25,9 @@ func main() {
|
||||||
state := 0 // Tracking animation states (State Machine)
|
state := 0 // Tracking animation states (State Machine)
|
||||||
alpha := float32(1.0) // Useful for fading
|
alpha := float32(1.0) // Useful for fading
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if state == 0 { // State 0: Small box blinking
|
if state == 0 { // State 0: Small box blinking
|
||||||
framesCounter++
|
framesCounter++
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if state == 4 { // State 4: Reset and Replay
|
} else if state == 4 { // State 4: Reset and Replay
|
||||||
if raylib.IsKeyPressed(raylib.KeyR) {
|
if rl.IsKeyPressed(rl.KeyR) {
|
||||||
framesCounter = 0
|
framesCounter = 0
|
||||||
lettersCount = 0
|
lettersCount = 0
|
||||||
|
|
||||||
|
@ -81,30 +81,30 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
if state == 0 {
|
if state == 0 {
|
||||||
if (framesCounter/15)%2 == 0 {
|
if (framesCounter/15)%2 == 0 {
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, 16, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY, 16, 16, rl.Black)
|
||||||
}
|
}
|
||||||
} else if state == 1 {
|
} else if state == 1 {
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
|
||||||
} else if state == 2 {
|
} else if state == 2 {
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Black)
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, rl.Black)
|
||||||
|
|
||||||
raylib.DrawRectangle(logoPositionX+240, logoPositionY, 16, rightSideRecHeight, raylib.Black)
|
rl.DrawRectangle(logoPositionX+240, logoPositionY, 16, rightSideRecHeight, rl.Black)
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, raylib.Black)
|
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Black)
|
||||||
} else if state == 3 {
|
} else if state == 3 {
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, raylib.Fade(raylib.Black, alpha))
|
rl.DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, rl.Fade(rl.Black, alpha))
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY+16, 16, leftSideRecHeight-32, raylib.Fade(raylib.Black, alpha))
|
rl.DrawRectangle(logoPositionX, logoPositionY+16, 16, leftSideRecHeight-32, rl.Fade(rl.Black, alpha))
|
||||||
|
|
||||||
raylib.DrawRectangle(logoPositionX+240, logoPositionY+16, 16, rightSideRecHeight-32, raylib.Fade(raylib.Black, alpha))
|
rl.DrawRectangle(logoPositionX+240, logoPositionY+16, 16, rightSideRecHeight-32, rl.Fade(rl.Black, alpha))
|
||||||
raylib.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, raylib.Fade(raylib.Black, alpha))
|
rl.DrawRectangle(logoPositionX, logoPositionY+240, bottomSideRecWidth, 16, rl.Fade(rl.Black, alpha))
|
||||||
|
|
||||||
raylib.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, raylib.Fade(raylib.RayWhite, alpha))
|
rl.DrawRectangle(screenWidth/2-112, screenHeight/2-112, 224, 224, rl.Fade(rl.RayWhite, alpha))
|
||||||
|
|
||||||
text := "raylib"
|
text := "raylib"
|
||||||
length := int32(len(text))
|
length := int32(len(text))
|
||||||
|
@ -112,13 +112,13 @@ func main() {
|
||||||
lettersCount = length
|
lettersCount = length
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText(text[0:lettersCount], screenWidth/2-44, screenHeight/2+48, 50, raylib.Fade(raylib.Black, alpha))
|
rl.DrawText(text[0:lettersCount], screenWidth/2-44, screenHeight/2+48, 50, rl.Fade(rl.Black, alpha))
|
||||||
} else if state == 4 {
|
} else if state == 4 {
|
||||||
raylib.DrawText("[R] REPLAY", 340, 200, 20, raylib.Gray)
|
rl.DrawText("[R] REPLAY", 340, 200, 20, rl.Gray)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,35 +8,35 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont and ttf sprite fonts loading")
|
||||||
|
|
||||||
msgBm := "THIS IS AN AngelCode SPRITE FONT"
|
msgBm := "THIS IS AN AngelCode SPRITE FONT"
|
||||||
msgTtf := "THIS SPRITE FONT has been GENERATED from a TTF"
|
msgTtf := "THIS SPRITE FONT has been GENERATED from a TTF"
|
||||||
|
|
||||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
fontBm := raylib.LoadFont("fonts/bmfont.fnt") // BMFont (AngelCode)
|
fontBm := rl.LoadFont("fonts/bmfont.fnt") // BMFont (AngelCode)
|
||||||
fontTtf := raylib.LoadFont("fonts/pixantiqua.ttf") // TTF font
|
fontTtf := rl.LoadFont("fonts/pixantiqua.ttf") // TTF font
|
||||||
|
|
||||||
fontPosition := raylib.Vector2{}
|
fontPosition := rl.Vector2{}
|
||||||
|
|
||||||
fontPosition.X = float32(screenWidth)/2 - raylib.MeasureTextEx(fontBm, msgBm, float32(fontBm.BaseSize), 0).X/2
|
fontPosition.X = float32(screenWidth)/2 - rl.MeasureTextEx(fontBm, msgBm, float32(fontBm.BaseSize), 0).X/2
|
||||||
fontPosition.Y = float32(screenHeight)/2 - float32(fontBm.BaseSize)/2 - 80
|
fontPosition.Y = float32(screenHeight)/2 - float32(fontBm.BaseSize)/2 - 80
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTextEx(fontBm, msgBm, fontPosition, float32(fontBm.BaseSize), 0, raylib.Maroon)
|
rl.DrawTextEx(fontBm, msgBm, fontPosition, float32(fontBm.BaseSize), 0, rl.Maroon)
|
||||||
raylib.DrawTextEx(fontTtf, msgTtf, raylib.NewVector2(75.0, 240.0), float32(fontTtf.BaseSize)*0.8, 2, raylib.Lime)
|
rl.DrawTextEx(fontTtf, msgTtf, rl.NewVector2(75.0, 240.0), float32(fontTtf.BaseSize)*0.8, 2, rl.Lime)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadFont(fontBm) // AngelCode Font unloading
|
rl.UnloadFont(fontBm) // AngelCode Font unloading
|
||||||
raylib.UnloadFont(fontTtf) // TTF Font unloading
|
rl.UnloadFont(fontTtf) // TTF Font unloading
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,32 +10,32 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - bmfont unordered loading and drawing")
|
||||||
|
|
||||||
// NOTE: Using chars outside the [32..127] limits!
|
// NOTE: Using chars outside the [32..127] limits!
|
||||||
// NOTE: If a character is not found in the font, it just renders a space
|
// NOTE: If a character is not found in the font, it just renders a space
|
||||||
msg := "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
msg := "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
|
||||||
|
|
||||||
// NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
// NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
|
||||||
font := raylib.LoadFont("fonts/pixantiqua.fnt") // BMFont (AngelCode)
|
font := rl.LoadFont("fonts/pixantiqua.fnt") // BMFont (AngelCode)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Font name: PixAntiqua", 40, 50, 20, raylib.Gray)
|
rl.DrawText("Font name: PixAntiqua", 40, 50, 20, rl.Gray)
|
||||||
raylib.DrawText(fmt.Sprintf("Font base size: %d", font.BaseSize), 40, 80, 20, raylib.Gray)
|
rl.DrawText(fmt.Sprintf("Font base size: %d", font.BaseSize), 40, 80, 20, rl.Gray)
|
||||||
raylib.DrawText(fmt.Sprintf("Font chars number: %d", font.CharsCount), 40, 110, 20, raylib.Gray)
|
rl.DrawText(fmt.Sprintf("Font chars number: %d", font.CharsCount), 40, 110, 20, rl.Gray)
|
||||||
|
|
||||||
raylib.DrawTextEx(font, msg, raylib.NewVector2(40, 180), float32(font.BaseSize), 0, raylib.Maroon)
|
rl.DrawTextEx(font, msg, rl.NewVector2(40, 180), float32(font.BaseSize), 0, rl.Maroon)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadFont(font) // AngelCode Font unloading
|
rl.UnloadFont(font) // AngelCode Font unloading
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,29 +10,29 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - text formatting")
|
||||||
|
|
||||||
score := 100020
|
score := 100020
|
||||||
hiscore := 200450
|
hiscore := 200450
|
||||||
lives := 5
|
lives := 5
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("Score: %08d", score), 200, 80, 20, raylib.Red)
|
rl.DrawText(fmt.Sprintf("Score: %08d", score), 200, 80, 20, rl.Red)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("HiScore: %08d", hiscore), 200, 120, 20, raylib.Green)
|
rl.DrawText(fmt.Sprintf("HiScore: %08d", hiscore), 200, 120, 20, rl.Green)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("Lives: %02d", lives), 200, 160, 40, raylib.Blue)
|
rl.DrawText(fmt.Sprintf("Lives: %02d", lives), 200, 160, 40, rl.Blue)
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("Elapsed Time: %02.02f ms", raylib.GetFrameTime()*1000), 200, 220, 20, raylib.Black)
|
rl.DrawText(fmt.Sprintf("Elapsed Time: %02.02f ms", rl.GetFrameTime()*1000), 200, 220, 20, rl.Black)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,17 +10,17 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts")
|
||||||
|
|
||||||
fonts := make([]raylib.Font, maxFonts)
|
fonts := make([]rl.Font, maxFonts)
|
||||||
fonts[0] = raylib.LoadFont("fonts/alagard.png")
|
fonts[0] = rl.LoadFont("fonts/alagard.png")
|
||||||
fonts[1] = raylib.LoadFont("fonts/pixelplay.png")
|
fonts[1] = rl.LoadFont("fonts/pixelplay.png")
|
||||||
fonts[2] = raylib.LoadFont("fonts/mecha.png")
|
fonts[2] = rl.LoadFont("fonts/mecha.png")
|
||||||
fonts[3] = raylib.LoadFont("fonts/setback.png")
|
fonts[3] = rl.LoadFont("fonts/setback.png")
|
||||||
fonts[4] = raylib.LoadFont("fonts/romulus.png")
|
fonts[4] = rl.LoadFont("fonts/romulus.png")
|
||||||
fonts[5] = raylib.LoadFont("fonts/pixantiqua.png")
|
fonts[5] = rl.LoadFont("fonts/pixantiqua.png")
|
||||||
fonts[6] = raylib.LoadFont("fonts/alpha_beta.png")
|
fonts[6] = rl.LoadFont("fonts/alpha_beta.png")
|
||||||
fonts[7] = raylib.LoadFont("fonts/jupiter_crash.png")
|
fonts[7] = rl.LoadFont("fonts/jupiter_crash.png")
|
||||||
|
|
||||||
messages := []string{
|
messages := []string{
|
||||||
"ALAGARD FONT designed by Hewett Tsoi",
|
"ALAGARD FONT designed by Hewett Tsoi",
|
||||||
|
@ -34,13 +34,13 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
spacings := []float32{2, 4, 8, 4, 3, 4, 4, 1}
|
spacings := []float32{2, 4, 8, 4, 3, 4, 4, 1}
|
||||||
positions := make([]raylib.Vector2, maxFonts)
|
positions := make([]rl.Vector2, maxFonts)
|
||||||
|
|
||||||
var i int32
|
var i int32
|
||||||
for i = 0; i < maxFonts; i++ {
|
for i = 0; i < maxFonts; i++ {
|
||||||
x := screenWidth/2 - int32(raylib.MeasureTextEx(fonts[i], messages[i], float32(fonts[i].BaseSize*2), spacings[i]).X/2)
|
x := screenWidth/2 - int32(rl.MeasureTextEx(fonts[i], messages[i], float32(fonts[i].BaseSize*2), spacings[i]).X/2)
|
||||||
y := 60 + fonts[i].BaseSize + 45*i
|
y := 60 + fonts[i].BaseSize + 45*i
|
||||||
positions[i] = raylib.NewVector2(float32(x), float32(y))
|
positions[i] = rl.NewVector2(float32(x), float32(y))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Small Y position corrections
|
// Small Y position corrections
|
||||||
|
@ -48,27 +48,27 @@ func main() {
|
||||||
positions[4].Y += 2
|
positions[4].Y += 2
|
||||||
positions[7].Y -= 8
|
positions[7].Y -= 8
|
||||||
|
|
||||||
colors := []raylib.Color{raylib.Maroon, raylib.Orange, raylib.DarkGreen, raylib.DarkBlue, raylib.DarkPurple, raylib.Lime, raylib.Gold, raylib.DarkBrown}
|
colors := []rl.Color{rl.Maroon, rl.Orange, rl.DarkGreen, rl.DarkBlue, rl.DarkPurple, rl.Lime, rl.Gold, rl.DarkBrown}
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
raylib.DrawText("free fonts included with raylib", 250, 20, 20, raylib.DarkGray)
|
rl.DrawText("free fonts included with raylib", 250, 20, 20, rl.DarkGray)
|
||||||
raylib.DrawLine(220, 50, 590, 50, raylib.DarkGray)
|
rl.DrawLine(220, 50, 590, 50, rl.DarkGray)
|
||||||
|
|
||||||
for i = 0; i < maxFonts; i++ {
|
for i = 0; i < maxFonts; i++ {
|
||||||
raylib.DrawTextEx(fonts[i], messages[i], positions[i], float32(fonts[i].BaseSize*2), spacings[i], colors[i])
|
rl.DrawTextEx(fonts[i], messages[i], positions[i], float32(fonts[i].BaseSize*2), spacings[i], colors[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i = 0; i < maxFonts; i++ {
|
for i = 0; i < maxFonts; i++ {
|
||||||
raylib.UnloadFont(fonts[i])
|
rl.UnloadFont(fonts[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,45 +8,45 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - sprite fonts usage")
|
||||||
|
|
||||||
msg1 := "THIS IS A custom SPRITE FONT..."
|
msg1 := "THIS IS A custom SPRITE FONT..."
|
||||||
msg2 := "...and this is ANOTHER CUSTOM font..."
|
msg2 := "...and this is ANOTHER CUSTOM font..."
|
||||||
msg3 := "...and a THIRD one! GREAT! :D"
|
msg3 := "...and a THIRD one! GREAT! :D"
|
||||||
|
|
||||||
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
font1 := raylib.LoadFont("fonts/custom_mecha.png") // Font loading
|
font1 := rl.LoadFont("fonts/custom_mecha.png") // Font loading
|
||||||
font2 := raylib.LoadFont("fonts/custom_alagard.png") // Font loading
|
font2 := rl.LoadFont("fonts/custom_alagard.png") // Font loading
|
||||||
font3 := raylib.LoadFont("fonts/custom_jupiter_crash.png") // Font loading
|
font3 := rl.LoadFont("fonts/custom_jupiter_crash.png") // Font loading
|
||||||
|
|
||||||
var fontPosition1, fontPosition2, fontPosition3 raylib.Vector2
|
var fontPosition1, fontPosition2, fontPosition3 rl.Vector2
|
||||||
|
|
||||||
fontPosition1.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font1, msg1, float32(font1.BaseSize), -3).X/2
|
fontPosition1.X = float32(screenWidth)/2 - rl.MeasureTextEx(font1, msg1, float32(font1.BaseSize), -3).X/2
|
||||||
fontPosition1.Y = float32(screenHeight)/2 - float32(font1.BaseSize)/2 - 80
|
fontPosition1.Y = float32(screenHeight)/2 - float32(font1.BaseSize)/2 - 80
|
||||||
|
|
||||||
fontPosition2.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font2, msg2, float32(font2.BaseSize), -2).X/2
|
fontPosition2.X = float32(screenWidth)/2 - rl.MeasureTextEx(font2, msg2, float32(font2.BaseSize), -2).X/2
|
||||||
fontPosition2.Y = float32(screenHeight)/2 - float32(font2.BaseSize)/2 - 10
|
fontPosition2.Y = float32(screenHeight)/2 - float32(font2.BaseSize)/2 - 10
|
||||||
|
|
||||||
fontPosition3.X = float32(screenWidth)/2 - raylib.MeasureTextEx(font3, msg3, float32(font3.BaseSize), 2).X/2
|
fontPosition3.X = float32(screenWidth)/2 - rl.MeasureTextEx(font3, msg3, float32(font3.BaseSize), 2).X/2
|
||||||
fontPosition3.Y = float32(screenHeight)/2 - float32(font3.BaseSize)/2 + 50
|
fontPosition3.Y = float32(screenHeight)/2 - float32(font3.BaseSize)/2 + 50
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTextEx(font1, msg1, fontPosition1, float32(font1.BaseSize), -3, raylib.White)
|
rl.DrawTextEx(font1, msg1, fontPosition1, float32(font1.BaseSize), -3, rl.White)
|
||||||
raylib.DrawTextEx(font2, msg2, fontPosition2, float32(font2.BaseSize), -2, raylib.White)
|
rl.DrawTextEx(font2, msg2, fontPosition2, float32(font2.BaseSize), -2, rl.White)
|
||||||
raylib.DrawTextEx(font3, msg3, fontPosition3, float32(font3.BaseSize), 2, raylib.White)
|
rl.DrawTextEx(font3, msg3, fontPosition3, float32(font3.BaseSize), 2, rl.White)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadFont(font1) // Font unloading
|
rl.UnloadFont(font1) // Font unloading
|
||||||
raylib.UnloadFont(font2) // Font unloading
|
rl.UnloadFont(font2) // Font unloading
|
||||||
raylib.UnloadFont(font3) // Font unloading
|
rl.UnloadFont(font3) // Font unloading
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading")
|
||||||
|
|
||||||
msg := "TTF Font"
|
msg := "TTF Font"
|
||||||
|
|
||||||
|
@ -19,94 +19,94 @@ func main() {
|
||||||
fontChars := int32(0)
|
fontChars := int32(0)
|
||||||
|
|
||||||
// TTF Font loading with custom generation parameters
|
// TTF Font loading with custom generation parameters
|
||||||
font := raylib.LoadFontEx("fonts/KAISG.ttf", 96, 0, &fontChars)
|
font := rl.LoadFontEx("fonts/KAISG.ttf", 96, 0, &fontChars)
|
||||||
|
|
||||||
// Generate mipmap levels to use trilinear filtering
|
// Generate mipmap levels to use trilinear filtering
|
||||||
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
|
||||||
raylib.GenTextureMipmaps(&font.Texture)
|
rl.GenTextureMipmaps(&font.Texture)
|
||||||
|
|
||||||
fontSize := font.BaseSize
|
fontSize := font.BaseSize
|
||||||
fontPosition := raylib.NewVector2(40, float32(screenHeight)/2+50)
|
fontPosition := rl.NewVector2(40, float32(screenHeight)/2+50)
|
||||||
textSize := raylib.Vector2{}
|
textSize := rl.Vector2{}
|
||||||
|
|
||||||
raylib.SetTextureFilter(font.Texture, raylib.FilterPoint)
|
rl.SetTextureFilter(font.Texture, rl.FilterPoint)
|
||||||
currentFontFilter := 0 // FilterPoint
|
currentFontFilter := 0 // FilterPoint
|
||||||
|
|
||||||
count := int32(0)
|
count := int32(0)
|
||||||
droppedFiles := make([]string, 0)
|
droppedFiles := make([]string, 0)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
fontSize += raylib.GetMouseWheelMove() * 4.0
|
fontSize += rl.GetMouseWheelMove() * 4.0
|
||||||
|
|
||||||
// Choose font texture filter method
|
// Choose font texture filter method
|
||||||
if raylib.IsKeyPressed(raylib.KeyOne) {
|
if rl.IsKeyPressed(rl.KeyOne) {
|
||||||
raylib.SetTextureFilter(font.Texture, raylib.FilterPoint)
|
rl.SetTextureFilter(font.Texture, rl.FilterPoint)
|
||||||
currentFontFilter = 0
|
currentFontFilter = 0
|
||||||
} else if raylib.IsKeyPressed(raylib.KeyTwo) {
|
} else if rl.IsKeyPressed(rl.KeyTwo) {
|
||||||
raylib.SetTextureFilter(font.Texture, raylib.FilterBilinear)
|
rl.SetTextureFilter(font.Texture, rl.FilterBilinear)
|
||||||
currentFontFilter = 1
|
currentFontFilter = 1
|
||||||
} else if raylib.IsKeyPressed(raylib.KeyThree) {
|
} else if rl.IsKeyPressed(rl.KeyThree) {
|
||||||
// NOTE: Trilinear filter won't be noticed on 2D drawing
|
// NOTE: Trilinear filter won't be noticed on 2D drawing
|
||||||
raylib.SetTextureFilter(font.Texture, raylib.FilterTrilinear)
|
rl.SetTextureFilter(font.Texture, rl.FilterTrilinear)
|
||||||
currentFontFilter = 2
|
currentFontFilter = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
textSize = raylib.MeasureTextEx(font, msg, float32(fontSize), 0)
|
textSize = rl.MeasureTextEx(font, msg, float32(fontSize), 0)
|
||||||
|
|
||||||
if raylib.IsKeyDown(raylib.KeyLeft) {
|
if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
fontPosition.X -= 10
|
fontPosition.X -= 10
|
||||||
} else if raylib.IsKeyDown(raylib.KeyRight) {
|
} else if rl.IsKeyDown(rl.KeyRight) {
|
||||||
fontPosition.X += 10
|
fontPosition.X += 10
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load a dropped TTF file dynamically (at current fontSize)
|
// Load a dropped TTF file dynamically (at current fontSize)
|
||||||
if raylib.IsFileDropped() {
|
if rl.IsFileDropped() {
|
||||||
droppedFiles = raylib.GetDroppedFiles(&count)
|
droppedFiles = rl.GetDroppedFiles(&count)
|
||||||
|
|
||||||
if count == 1 { // Only support one ttf file dropped
|
if count == 1 { // Only support one ttf file dropped
|
||||||
raylib.UnloadFont(font)
|
rl.UnloadFont(font)
|
||||||
font = raylib.LoadFontEx(droppedFiles[0], fontSize, 0, &fontChars)
|
font = rl.LoadFontEx(droppedFiles[0], fontSize, 0, &fontChars)
|
||||||
raylib.ClearDroppedFiles()
|
rl.ClearDroppedFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("Use mouse wheel to change font size", 20, 20, 10, raylib.Gray)
|
rl.DrawText("Use mouse wheel to change font size", 20, 20, 10, rl.Gray)
|
||||||
raylib.DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, raylib.Gray)
|
rl.DrawText("Use KEY_RIGHT and KEY_LEFT to move text", 20, 40, 10, rl.Gray)
|
||||||
raylib.DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, raylib.Gray)
|
rl.DrawText("Use 1, 2, 3 to change texture filter", 20, 60, 10, rl.Gray)
|
||||||
raylib.DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, raylib.DarkGray)
|
rl.DrawText("Drop a new TTF font for dynamic loading", 20, 80, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.DrawTextEx(font, msg, fontPosition, float32(fontSize), 0, raylib.Black)
|
rl.DrawTextEx(font, msg, fontPosition, float32(fontSize), 0, rl.Black)
|
||||||
|
|
||||||
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
// TODO: It seems texSize measurement is not accurate due to chars offsets...
|
||||||
//raylib.DrawRectangleLines(int32(fontPosition.X), int32(fontPosition.Y), int32(textSize.X), int32(textSize.Y), raylib.Red)
|
//rl.DrawRectangleLines(int32(fontPosition.X), int32(fontPosition.Y), int32(textSize.X), int32(textSize.Y), rl.Red)
|
||||||
|
|
||||||
raylib.DrawRectangle(0, screenHeight-80, screenWidth, 80, raylib.LightGray)
|
rl.DrawRectangle(0, screenHeight-80, screenWidth, 80, rl.LightGray)
|
||||||
raylib.DrawText(fmt.Sprintf("Font size: %02.02f", float32(fontSize)), 20, screenHeight-50, 10, raylib.DarkGray)
|
rl.DrawText(fmt.Sprintf("Font size: %02.02f", float32(fontSize)), 20, screenHeight-50, 10, rl.DarkGray)
|
||||||
raylib.DrawText(fmt.Sprintf("Text size: [%02.02f, %02.02f]", textSize.X, textSize.Y), 20, screenHeight-30, 10, raylib.DarkGray)
|
rl.DrawText(fmt.Sprintf("Text size: [%02.02f, %02.02f]", textSize.X, textSize.Y), 20, screenHeight-30, 10, rl.DarkGray)
|
||||||
raylib.DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, raylib.Gray)
|
rl.DrawText("CURRENT TEXTURE FILTER:", 250, 400, 20, rl.Gray)
|
||||||
|
|
||||||
if currentFontFilter == 0 {
|
if currentFontFilter == 0 {
|
||||||
raylib.DrawText("POINT", 570, 400, 20, raylib.Black)
|
rl.DrawText("POINT", 570, 400, 20, rl.Black)
|
||||||
} else if currentFontFilter == 1 {
|
} else if currentFontFilter == 1 {
|
||||||
raylib.DrawText("BILINEAR", 570, 400, 20, raylib.Black)
|
rl.DrawText("BILINEAR", 570, 400, 20, rl.Black)
|
||||||
} else if currentFontFilter == 2 {
|
} else if currentFontFilter == 2 {
|
||||||
raylib.DrawText("TRILINEAR", 570, 400, 20, raylib.Black)
|
rl.DrawText("TRILINEAR", 570, 400, 20, rl.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadFont(font) // Font unloading
|
rl.UnloadFont(font) // Font unloading
|
||||||
|
|
||||||
raylib.ClearDroppedFiles() // Clear internal buffers
|
rl.ClearDroppedFiles() // Clear internal buffers
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,24 +8,24 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim")
|
||||||
|
|
||||||
message := "This sample illustrates a text writing\nanimation effect! Check it out! ;)"
|
message := "This sample illustrates a text writing\nanimation effect! Check it out! ;)"
|
||||||
length := len(message)
|
length := len(message)
|
||||||
|
|
||||||
framesCounter := 0
|
framesCounter := 0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
if raylib.IsKeyDown(raylib.KeySpace) {
|
if rl.IsKeyDown(rl.KeySpace) {
|
||||||
framesCounter += 8
|
framesCounter += 8
|
||||||
} else {
|
} else {
|
||||||
framesCounter++
|
framesCounter++
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
framesCounter = 0
|
framesCounter = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,17 +34,17 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText(message[0:framesCounter/10], 210, 160, 20, raylib.Maroon)
|
rl.DrawText(message[0:framesCounter/10], 210, 160, 20, rl.Maroon)
|
||||||
|
|
||||||
raylib.DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, raylib.LightGray)
|
rl.DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, rl.LightGray)
|
||||||
raylib.DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, raylib.LightGray)
|
rl.DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, rl.LightGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,42 +8,42 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
cat := raylib.LoadImage("cat.png") // Load image in CPU memory (RAM)
|
cat := rl.LoadImage("cat.png") // Load image in CPU memory (RAM)
|
||||||
raylib.ImageCrop(cat, raylib.NewRectangle(100, 10, 280, 380)) // Crop an image piece
|
rl.ImageCrop(cat, rl.NewRectangle(100, 10, 280, 380)) // Crop an image piece
|
||||||
raylib.ImageFlipHorizontal(cat) // Flip cropped image horizontally
|
rl.ImageFlipHorizontal(cat) // Flip cropped image horizontally
|
||||||
raylib.ImageResize(cat, 150, 200) // Resize flipped-cropped image
|
rl.ImageResize(cat, 150, 200) // Resize flipped-cropped image
|
||||||
|
|
||||||
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||||
|
|
||||||
// Draw one image over the other with a scaling of 1.5f
|
// Draw one image over the other with a scaling of 1.5f
|
||||||
raylib.ImageDraw(parrots, cat, raylib.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), raylib.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
|
rl.ImageDraw(parrots, cat, rl.NewRectangle(0, 0, float32(cat.Width), float32(cat.Height)), rl.NewRectangle(30, 40, float32(cat.Width)*1.5, float32(cat.Height)*1.5))
|
||||||
raylib.ImageCrop(parrots, raylib.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
|
rl.ImageCrop(parrots, rl.NewRectangle(0, 50, float32(parrots.Width), float32(parrots.Height-100))) // Crop resulting image
|
||||||
|
|
||||||
raylib.UnloadImage(cat) // Unload image from RAM
|
rl.UnloadImage(cat) // Unload image from RAM
|
||||||
|
|
||||||
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
texture := rl.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
|
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, rl.White)
|
||||||
raylib.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, raylib.DarkGray)
|
rl.DrawRectangleLines(screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2-40, texture.Width, texture.Height, rl.DarkGray)
|
||||||
|
|
||||||
raylib.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, raylib.DarkGray)
|
rl.DrawText("We are drawing only one texture from various images composed!", 240, 350, 10, rl.DarkGray)
|
||||||
raylib.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, raylib.DarkGray)
|
rl.DrawText("Source images have been cropped, scaled, flipped and copied one over the other.", 190, 370, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,85 +10,85 @@ func main() {
|
||||||
screenWidth := 800
|
screenWidth := 800
|
||||||
screenHeight := 450
|
screenHeight := 450
|
||||||
|
|
||||||
raylib.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
|
rl.InitWindow(int32(screenWidth), int32(screenHeight), "raylib [textures] example - procedural images generation")
|
||||||
|
|
||||||
verticalGradient := raylib.GenImageGradientV(screenWidth, screenHeight, raylib.Red, raylib.Blue)
|
verticalGradient := rl.GenImageGradientV(screenWidth, screenHeight, rl.Red, rl.Blue)
|
||||||
horizontalGradient := raylib.GenImageGradientH(screenWidth, screenHeight, raylib.Red, raylib.Blue)
|
horizontalGradient := rl.GenImageGradientH(screenWidth, screenHeight, rl.Red, rl.Blue)
|
||||||
radialGradient := raylib.GenImageGradientRadial(screenWidth, screenHeight, 0, raylib.White, raylib.Black)
|
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
|
||||||
checked := raylib.GenImageChecked(screenWidth, screenHeight, 32, 32, raylib.Red, raylib.Blue)
|
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
|
||||||
whiteNoise := raylib.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
|
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
|
||||||
perlinNoise := raylib.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
|
perlinNoise := rl.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
|
||||||
cellular := raylib.GenImageCellular(screenWidth, screenHeight, 32)
|
cellular := rl.GenImageCellular(screenWidth, screenHeight, 32)
|
||||||
|
|
||||||
textures := make([]raylib.Texture2D, numTextures)
|
textures := make([]rl.Texture2D, numTextures)
|
||||||
textures[0] = raylib.LoadTextureFromImage(verticalGradient)
|
textures[0] = rl.LoadTextureFromImage(verticalGradient)
|
||||||
textures[1] = raylib.LoadTextureFromImage(horizontalGradient)
|
textures[1] = rl.LoadTextureFromImage(horizontalGradient)
|
||||||
textures[2] = raylib.LoadTextureFromImage(radialGradient)
|
textures[2] = rl.LoadTextureFromImage(radialGradient)
|
||||||
textures[3] = raylib.LoadTextureFromImage(checked)
|
textures[3] = rl.LoadTextureFromImage(checked)
|
||||||
textures[4] = raylib.LoadTextureFromImage(whiteNoise)
|
textures[4] = rl.LoadTextureFromImage(whiteNoise)
|
||||||
textures[5] = raylib.LoadTextureFromImage(perlinNoise)
|
textures[5] = rl.LoadTextureFromImage(perlinNoise)
|
||||||
textures[6] = raylib.LoadTextureFromImage(cellular)
|
textures[6] = rl.LoadTextureFromImage(cellular)
|
||||||
|
|
||||||
// Unload image data (CPU RAM)
|
// Unload image data (CPU RAM)
|
||||||
raylib.UnloadImage(verticalGradient)
|
rl.UnloadImage(verticalGradient)
|
||||||
raylib.UnloadImage(horizontalGradient)
|
rl.UnloadImage(horizontalGradient)
|
||||||
raylib.UnloadImage(radialGradient)
|
rl.UnloadImage(radialGradient)
|
||||||
raylib.UnloadImage(checked)
|
rl.UnloadImage(checked)
|
||||||
raylib.UnloadImage(whiteNoise)
|
rl.UnloadImage(whiteNoise)
|
||||||
raylib.UnloadImage(perlinNoise)
|
rl.UnloadImage(perlinNoise)
|
||||||
raylib.UnloadImage(cellular)
|
rl.UnloadImage(cellular)
|
||||||
|
|
||||||
currentTexture := 0
|
currentTexture := 0
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(textures[currentTexture], 0, 0, raylib.White)
|
rl.DrawTexture(textures[currentTexture], 0, 0, rl.White)
|
||||||
|
|
||||||
raylib.DrawRectangle(30, 400, 325, 30, raylib.Fade(raylib.SkyBlue, 0.5))
|
rl.DrawRectangle(30, 400, 325, 30, rl.Fade(rl.SkyBlue, 0.5))
|
||||||
raylib.DrawRectangleLines(30, 400, 325, 30, raylib.Fade(raylib.White, 0.5))
|
rl.DrawRectangleLines(30, 400, 325, 30, rl.Fade(rl.White, 0.5))
|
||||||
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, raylib.White)
|
rl.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", 40, 410, 10, rl.White)
|
||||||
|
|
||||||
switch currentTexture {
|
switch currentTexture {
|
||||||
case 0:
|
case 0:
|
||||||
raylib.DrawText("VERTICAL GRADIENT", 560, 10, 20, raylib.RayWhite)
|
rl.DrawText("VERTICAL GRADIENT", 560, 10, 20, rl.RayWhite)
|
||||||
break
|
break
|
||||||
case 1:
|
case 1:
|
||||||
raylib.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, raylib.RayWhite)
|
rl.DrawText("HORIZONTAL GRADIENT", 540, 10, 20, rl.RayWhite)
|
||||||
break
|
break
|
||||||
case 2:
|
case 2:
|
||||||
raylib.DrawText("RADIAL GRADIENT", 580, 10, 20, raylib.LightGray)
|
rl.DrawText("RADIAL GRADIENT", 580, 10, 20, rl.LightGray)
|
||||||
break
|
break
|
||||||
case 3:
|
case 3:
|
||||||
raylib.DrawText("CHECKED", 680, 10, 20, raylib.RayWhite)
|
rl.DrawText("CHECKED", 680, 10, 20, rl.RayWhite)
|
||||||
break
|
break
|
||||||
case 4:
|
case 4:
|
||||||
raylib.DrawText("WHITE NOISE", 640, 10, 20, raylib.Red)
|
rl.DrawText("WHITE NOISE", 640, 10, 20, rl.Red)
|
||||||
break
|
break
|
||||||
case 5:
|
case 5:
|
||||||
raylib.DrawText("PERLIN NOISE", 630, 10, 20, raylib.RayWhite)
|
rl.DrawText("PERLIN NOISE", 630, 10, 20, rl.RayWhite)
|
||||||
break
|
break
|
||||||
case 6:
|
case 6:
|
||||||
raylib.DrawText("CELLULAR", 670, 10, 20, raylib.RayWhite)
|
rl.DrawText("CELLULAR", 670, 10, 20, rl.RayWhite)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range textures {
|
for _, t := range textures {
|
||||||
raylib.UnloadTexture(t)
|
rl.UnloadTexture(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,57 +11,57 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from image.Image")
|
||||||
|
|
||||||
r, err := os.Open("raylib_logo.png")
|
r, err := os.Open("raylib_logo.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogError, err.Error())
|
rl.TraceLog(rl.LogError, err.Error())
|
||||||
}
|
}
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
img, err := png.Decode(r)
|
img, err := png.Decode(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogError, err.Error())
|
rl.TraceLog(rl.LogError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create raylib.Image from Go image.Image and create texture
|
// Create rl.Image from Go image.Image and create texture
|
||||||
im := raylib.NewImageFromImage(img)
|
im := rl.NewImageFromImage(img)
|
||||||
texture := raylib.LoadTextureFromImage(im)
|
texture := rl.LoadTextureFromImage(im)
|
||||||
|
|
||||||
// Unload CPU (RAM) image data
|
// Unload CPU (RAM) image data
|
||||||
raylib.UnloadImage(im)
|
rl.UnloadImage(im)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyPressed(raylib.KeyS) {
|
if rl.IsKeyPressed(rl.KeyS) {
|
||||||
rimg := raylib.GetTextureData(texture)
|
rimg := rl.GetTextureData(texture)
|
||||||
|
|
||||||
f, err := os.Create("image_saved.png")
|
f, err := os.Create("image_saved.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogError, err.Error())
|
rl.TraceLog(rl.LogError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = png.Encode(f, rimg.ToImage())
|
err = png.Encode(f, rimg.ToImage())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogError, err.Error())
|
rl.TraceLog(rl.LogError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Close()
|
f.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, raylib.LightGray)
|
rl.DrawText("PRESS S TO SAVE IMAGE FROM TEXTURE", 20, 20, 12, rl.LightGray)
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||||
raylib.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, raylib.Gray)
|
rl.DrawText("this IS a texture loaded from an image.Image!", 285, 370, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,30 +8,30 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
|
||||||
image := raylib.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
|
image := rl.LoadImage("raylib_logo.png") // Loaded in CPU memory (RAM)
|
||||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
texture := rl.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
|
rl.UnloadImage(image) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,31 +33,31 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image processing")
|
||||||
|
|
||||||
image := raylib.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
|
image := rl.LoadImage("parrots.png") // Loaded in CPU memory (RAM)
|
||||||
raylib.ImageFormat(image, raylib.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
|
rl.ImageFormat(image, rl.UncompressedR8g8b8a8) // Format image to RGBA 32bit (required for texture update)
|
||||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (VRAM)
|
||||||
|
|
||||||
currentProcess := None
|
currentProcess := None
|
||||||
textureReload := false
|
textureReload := false
|
||||||
|
|
||||||
selectRecs := make([]raylib.Rectangle, numProcesses)
|
selectRecs := make([]rl.Rectangle, numProcesses)
|
||||||
|
|
||||||
for i := 0; i < numProcesses; i++ {
|
for i := 0; i < numProcesses; i++ {
|
||||||
selectRecs[i] = raylib.NewRectangle(40, 50+32*float32(i), 150, 30)
|
selectRecs[i] = rl.NewRectangle(40, 50+32*float32(i), 150, 30)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyPressed(raylib.KeyDown) {
|
if rl.IsKeyPressed(rl.KeyDown) {
|
||||||
currentProcess++
|
currentProcess++
|
||||||
if currentProcess > 7 {
|
if currentProcess > 7 {
|
||||||
currentProcess = 0
|
currentProcess = 0
|
||||||
}
|
}
|
||||||
textureReload = true
|
textureReload = true
|
||||||
} else if raylib.IsKeyPressed(raylib.KeyUp) {
|
} else if rl.IsKeyPressed(rl.KeyUp) {
|
||||||
currentProcess--
|
currentProcess--
|
||||||
if currentProcess < 0 {
|
if currentProcess < 0 {
|
||||||
currentProcess = 7
|
currentProcess = 7
|
||||||
|
@ -66,70 +66,70 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if textureReload {
|
if textureReload {
|
||||||
raylib.UnloadImage(image) // Unload current image data
|
rl.UnloadImage(image) // Unload current image data
|
||||||
image = raylib.LoadImage("parrots.png") // Re-load image data
|
image = rl.LoadImage("parrots.png") // Re-load image data
|
||||||
|
|
||||||
// NOTE: Image processing is a costly CPU process to be done every frame,
|
// 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
|
// If image processing is required in a frame-basis, it should be done
|
||||||
// with a texture and by shaders
|
// with a texture and by shaders
|
||||||
switch currentProcess {
|
switch currentProcess {
|
||||||
case ColorGrayscale:
|
case ColorGrayscale:
|
||||||
raylib.ImageColorGrayscale(image)
|
rl.ImageColorGrayscale(image)
|
||||||
break
|
break
|
||||||
case ColorTint:
|
case ColorTint:
|
||||||
raylib.ImageColorTint(image, raylib.Green)
|
rl.ImageColorTint(image, rl.Green)
|
||||||
break
|
break
|
||||||
case ColorInvert:
|
case ColorInvert:
|
||||||
raylib.ImageColorInvert(image)
|
rl.ImageColorInvert(image)
|
||||||
break
|
break
|
||||||
case ColorContrast:
|
case ColorContrast:
|
||||||
raylib.ImageColorContrast(image, -40)
|
rl.ImageColorContrast(image, -40)
|
||||||
break
|
break
|
||||||
case ColorBrightness:
|
case ColorBrightness:
|
||||||
raylib.ImageColorBrightness(image, -80)
|
rl.ImageColorBrightness(image, -80)
|
||||||
break
|
break
|
||||||
case FlipVertical:
|
case FlipVertical:
|
||||||
raylib.ImageFlipVertical(image)
|
rl.ImageFlipVertical(image)
|
||||||
break
|
break
|
||||||
case FlipHorizontal:
|
case FlipHorizontal:
|
||||||
raylib.ImageFlipHorizontal(image)
|
rl.ImageFlipHorizontal(image)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
pixels := raylib.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
pixels := rl.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
||||||
raylib.UpdateTexture(texture, pixels) // Update texture with new image data
|
rl.UpdateTexture(texture, pixels) // Update texture with new image data
|
||||||
|
|
||||||
textureReload = false
|
textureReload = false
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawText("IMAGE PROCESSING:", 40, 30, 10, raylib.DarkGray)
|
rl.DrawText("IMAGE PROCESSING:", 40, 30, 10, rl.DarkGray)
|
||||||
|
|
||||||
// Draw rectangles
|
// Draw rectangles
|
||||||
for i := 0; i < numProcesses; i++ {
|
for i := 0; i < numProcesses; i++ {
|
||||||
if i == currentProcess {
|
if i == currentProcess {
|
||||||
raylib.DrawRectangleRec(selectRecs[i], raylib.SkyBlue)
|
rl.DrawRectangleRec(selectRecs[i], rl.SkyBlue)
|
||||||
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Blue)
|
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Blue)
|
||||||
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkBlue)
|
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkBlue)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawRectangleRec(selectRecs[i], raylib.LightGray)
|
rl.DrawRectangleRec(selectRecs[i], rl.LightGray)
|
||||||
raylib.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), raylib.Gray)
|
rl.DrawRectangleLines(int32(selectRecs[i].X), int32(selectRecs[i].Y), int32(selectRecs[i].Width), int32(selectRecs[i].Height), rl.Gray)
|
||||||
raylib.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-raylib.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, raylib.DarkGray)
|
rl.DrawText(processText[i], int32(selectRecs[i].X+selectRecs[i].Width/2)-rl.MeasureText(processText[i], 10)/2, int32(selectRecs[i].Y)+11, 10, rl.DarkGray)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, rl.White)
|
||||||
raylib.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, raylib.Black)
|
rl.DrawRectangleLines(screenWidth-texture.Width-60, screenHeight/2-texture.Height/2, texture.Width, texture.Height, rl.Black)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,55 +8,55 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - image text drawing")
|
||||||
|
|
||||||
// TTF Font loading with custom generation parameters
|
// TTF Font loading with custom generation parameters
|
||||||
var fontChars int32
|
var fontChars int32
|
||||||
font := raylib.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
|
font := rl.LoadFontEx("fonts/KAISG.ttf", 64, 0, &fontChars)
|
||||||
|
|
||||||
parrots := raylib.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
parrots := rl.LoadImage("parrots.png") // Load image in CPU memory (RAM)
|
||||||
|
|
||||||
// Draw over image using custom font
|
// Draw over image using custom font
|
||||||
raylib.ImageDrawTextEx(parrots, raylib.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, raylib.White)
|
rl.ImageDrawTextEx(parrots, rl.NewVector2(20, 20), font, "[Parrots font drawing]", float32(font.BaseSize), 0, rl.White)
|
||||||
|
|
||||||
texture := raylib.LoadTextureFromImage(parrots) // Image converted to texture, uploaded to GPU memory (VRAM)
|
texture := rl.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
|
rl.UnloadImage(parrots) // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||||
|
|
||||||
position := raylib.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
|
position := rl.NewVector2(float32(screenWidth)/2-float32(texture.Width)/2, float32(screenHeight)/2-float32(texture.Height)/2-20)
|
||||||
|
|
||||||
showFont := false
|
showFont := false
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if raylib.IsKeyDown(raylib.KeySpace) {
|
if rl.IsKeyDown(rl.KeySpace) {
|
||||||
showFont = true
|
showFont = true
|
||||||
} else {
|
} else {
|
||||||
showFont = false
|
showFont = false
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
if !showFont {
|
if !showFont {
|
||||||
// Draw texture with text already drawn inside
|
// Draw texture with text already drawn inside
|
||||||
raylib.DrawTextureV(texture, position, raylib.White)
|
rl.DrawTextureV(texture, position, rl.White)
|
||||||
|
|
||||||
// Draw text directly using sprite font
|
// Draw text directly using sprite font
|
||||||
raylib.DrawTextEx(font, "[Parrots font drawing]", raylib.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, raylib.White)
|
rl.DrawTextEx(font, "[Parrots font drawing]", rl.NewVector2(position.X+20, position.Y+20+280), float32(font.BaseSize), 0, rl.White)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, raylib.Black)
|
rl.DrawTexture(font.Texture, screenWidth/2-font.Texture.Width/2, 50, rl.Black)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, raylib.DarkGray)
|
rl.DrawText("PRESS SPACE to SEE USED SPRITEFONT ", 290, 420, 10, rl.DarkGray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
raylib.UnloadFont(font)
|
rl.UnloadFont(font)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,24 +8,24 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
texture := raylib.LoadTexture("raylib_logo.png")
|
texture := rl.LoadTexture("raylib_logo.png")
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||||
raylib.DrawText("this IS a texture!", 360, 370, 10, raylib.Gray)
|
rl.DrawText("this IS a texture!", 360, 370, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type particle struct {
|
type particle struct {
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
Color raylib.Color
|
Color rl.Color
|
||||||
Alpha float32
|
Alpha float32
|
||||||
Size float32
|
Size float32
|
||||||
Rotation float32
|
Rotation float32
|
||||||
|
@ -21,31 +21,31 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
//raylib.SetConfigFlags(raylib.FlagVsyncHint)
|
//rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending")
|
||||||
|
|
||||||
// Particles pool, reuse them!
|
// Particles pool, reuse them!
|
||||||
mouseTail := make([]particle, maxParticles)
|
mouseTail := make([]particle, maxParticles)
|
||||||
|
|
||||||
// Initialize particles
|
// Initialize particles
|
||||||
for i := 0; i < maxParticles; i++ {
|
for i := 0; i < maxParticles; i++ {
|
||||||
mouseTail[i].Position = raylib.NewVector2(0, 0)
|
mouseTail[i].Position = rl.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].Color = rl.NewColor(byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), byte(rl.GetRandomValue(0, 255)), 255)
|
||||||
mouseTail[i].Alpha = 1.0
|
mouseTail[i].Alpha = 1.0
|
||||||
mouseTail[i].Size = float32(raylib.GetRandomValue(1, 30)) / 20.0
|
mouseTail[i].Size = float32(rl.GetRandomValue(1, 30)) / 20.0
|
||||||
mouseTail[i].Rotation = float32(raylib.GetRandomValue(0, 360))
|
mouseTail[i].Rotation = float32(rl.GetRandomValue(0, 360))
|
||||||
mouseTail[i].Active = false
|
mouseTail[i].Active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
gravity := float32(3.0)
|
gravity := float32(3.0)
|
||||||
|
|
||||||
smoke := raylib.LoadTexture("smoke.png")
|
smoke := rl.LoadTexture("smoke.png")
|
||||||
|
|
||||||
blending := raylib.BlendAlpha
|
blending := rl.BlendAlpha
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
// Activate one particle every frame and Update active particles
|
// Activate one particle every frame and Update active particles
|
||||||
|
@ -56,7 +56,7 @@ func main() {
|
||||||
if !mouseTail[i].Active {
|
if !mouseTail[i].Active {
|
||||||
mouseTail[i].Active = true
|
mouseTail[i].Active = true
|
||||||
mouseTail[i].Alpha = 1.0
|
mouseTail[i].Alpha = 1.0
|
||||||
mouseTail[i].Position = raylib.GetMousePosition()
|
mouseTail[i].Position = rl.GetMousePosition()
|
||||||
i = maxParticles
|
i = maxParticles
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,50 +74,50 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
if blending == raylib.BlendAlpha {
|
if blending == rl.BlendAlpha {
|
||||||
blending = raylib.BlendAdditive
|
blending = rl.BlendAdditive
|
||||||
} else {
|
} else {
|
||||||
blending = raylib.BlendAlpha
|
blending = rl.BlendAlpha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.DarkGray)
|
rl.ClearBackground(rl.DarkGray)
|
||||||
|
|
||||||
raylib.BeginBlendMode(blending)
|
rl.BeginBlendMode(blending)
|
||||||
|
|
||||||
// Draw active particles
|
// Draw active particles
|
||||||
for i := 0; i < maxParticles; i++ {
|
for i := 0; i < maxParticles; i++ {
|
||||||
if mouseTail[i].Active {
|
if mouseTail[i].Active {
|
||||||
raylib.DrawTexturePro(
|
rl.DrawTexturePro(
|
||||||
smoke,
|
smoke,
|
||||||
raylib.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
|
rl.NewRectangle(0, 0, float32(smoke.Width), float32(smoke.Height)),
|
||||||
raylib.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
|
rl.NewRectangle(mouseTail[i].Position.X, mouseTail[i].Position.Y, float32(smoke.Width)*mouseTail[i].Size, float32(smoke.Height)*mouseTail[i].Size),
|
||||||
raylib.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
|
rl.NewVector2(float32(smoke.Width)*mouseTail[i].Size/2, float32(smoke.Height)*mouseTail[i].Size/2),
|
||||||
mouseTail[i].Rotation,
|
mouseTail[i].Rotation,
|
||||||
raylib.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
|
rl.Fade(mouseTail[i].Color, mouseTail[i].Alpha),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndBlendMode()
|
rl.EndBlendMode()
|
||||||
|
|
||||||
raylib.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, raylib.Black)
|
rl.DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, rl.Black)
|
||||||
|
|
||||||
if blending == raylib.BlendAlpha {
|
if blending == rl.BlendAlpha {
|
||||||
raylib.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, raylib.Black)
|
rl.DrawText("ALPHA BLENDING", 290, screenHeight-40, 20, rl.Black)
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, raylib.RayWhite)
|
rl.DrawText("ADDITIVE BLENDING", 280, screenHeight-40, 20, rl.RayWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(smoke)
|
rl.UnloadTexture(smoke)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,56 +8,56 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
|
|
||||||
// Load RAW image data (384x512, 32bit RGBA, no file header)
|
// Load RAW image data (384x512, 32bit RGBA, no file header)
|
||||||
fudesumiRaw := raylib.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, raylib.UncompressedR8g8b8a8, 0)
|
fudesumiRaw := rl.LoadImageRaw("texture_formats/fudesumi.raw", 384, 512, rl.UncompressedR8g8b8a8, 0)
|
||||||
fudesumi := raylib.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
fudesumi := rl.LoadTextureFromImage(fudesumiRaw) // Upload CPU (RAM) image to GPU (VRAM)
|
||||||
raylib.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
|
rl.UnloadImage(fudesumiRaw) // Unload CPU (RAM) image data
|
||||||
|
|
||||||
// Generate a checked texture by code (1024x1024 pixels)
|
// Generate a checked texture by code (1024x1024 pixels)
|
||||||
width := 1024
|
width := 1024
|
||||||
height := 1024
|
height := 1024
|
||||||
|
|
||||||
// Dynamic memory allocation to store pixels data (Color type)
|
// Dynamic memory allocation to store pixels data (Color type)
|
||||||
pixels := make([]raylib.Color, width*height)
|
pixels := make([]rl.Color, width*height)
|
||||||
|
|
||||||
for y := 0; y < height; y++ {
|
for y := 0; y < height; y++ {
|
||||||
for x := 0; x < width; x++ {
|
for x := 0; x < width; x++ {
|
||||||
if ((x/32+y/32)/1)%2 == 0 {
|
if ((x/32+y/32)/1)%2 == 0 {
|
||||||
pixels[y*height+x] = raylib.Orange
|
pixels[y*height+x] = rl.Orange
|
||||||
} else {
|
} else {
|
||||||
pixels[y*height+x] = raylib.Gold
|
pixels[y*height+x] = rl.Gold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load pixels data into an image structure and create texture
|
// Load pixels data into an image structure and create texture
|
||||||
checkedIm := raylib.LoadImageEx(pixels, int32(width), int32(height))
|
checkedIm := rl.LoadImageEx(pixels, int32(width), int32(height))
|
||||||
checked := raylib.LoadTextureFromImage(checkedIm)
|
checked := rl.LoadTextureFromImage(checkedIm)
|
||||||
raylib.UnloadImage(checkedIm) // Unload CPU (RAM) image data
|
rl.UnloadImage(checkedIm) // Unload CPU (RAM) image data
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, raylib.Fade(raylib.White, 0.5))
|
rl.DrawTexture(checked, screenWidth/2-checked.Width/2, screenHeight/2-checked.Height/2, rl.Fade(rl.White, 0.5))
|
||||||
raylib.DrawTexture(fudesumi, 430, -30, raylib.White)
|
rl.DrawTexture(fudesumi, 430, -30, rl.White)
|
||||||
|
|
||||||
raylib.DrawText("CHECKED TEXTURE ", 84, 100, 30, raylib.Brown)
|
rl.DrawText("CHECKED TEXTURE ", 84, 100, 30, rl.Brown)
|
||||||
raylib.DrawText("GENERATED by CODE", 72, 164, 30, raylib.Brown)
|
rl.DrawText("GENERATED by CODE", 72, 164, 30, rl.Brown)
|
||||||
raylib.DrawText("and RAW IMAGE LOADING", 46, 226, 30, raylib.Brown)
|
rl.DrawText("and RAW IMAGE LOADING", 46, 226, 30, rl.Brown)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(fudesumi) // Texture unloading
|
rl.UnloadTexture(fudesumi) // Texture unloading
|
||||||
raylib.UnloadTexture(checked) // Texture unloading
|
rl.UnloadTexture(checked) // Texture unloading
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,21 +15,21 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture loading and drawing")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
|
||||||
|
|
||||||
position := raylib.NewVector2(350.0, 280.0)
|
position := rl.NewVector2(350.0, 280.0)
|
||||||
frameRec := raylib.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
|
frameRec := rl.NewRectangle(0, 0, float32(scarfy.Width/6), float32(scarfy.Height))
|
||||||
currentFrame := float32(0)
|
currentFrame := float32(0)
|
||||||
|
|
||||||
framesCounter := 0
|
framesCounter := 0
|
||||||
framesSpeed := 8 // Number of spritesheet frames shown by second
|
framesSpeed := 8 // Number of spritesheet frames shown by second
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
framesCounter++
|
framesCounter++
|
||||||
|
|
||||||
if framesCounter >= (60 / framesSpeed) {
|
if framesCounter >= (60 / framesSpeed) {
|
||||||
|
@ -43,9 +43,9 @@ func main() {
|
||||||
frameRec.X = currentFrame * float32(scarfy.Width) / 6
|
frameRec.X = currentFrame * float32(scarfy.Width) / 6
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyRight) {
|
if rl.IsKeyPressed(rl.KeyRight) {
|
||||||
framesSpeed++
|
framesSpeed++
|
||||||
} else if raylib.IsKeyPressed(raylib.KeyLeft) {
|
} else if rl.IsKeyPressed(rl.KeyLeft) {
|
||||||
framesSpeed--
|
framesSpeed--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,33 +55,33 @@ func main() {
|
||||||
framesSpeed = minFrameSpeed
|
framesSpeed = minFrameSpeed
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(scarfy, 15, 40, raylib.White)
|
rl.DrawTexture(scarfy, 15, 40, rl.White)
|
||||||
raylib.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, raylib.Lime)
|
rl.DrawRectangleLines(15, 40, scarfy.Width, scarfy.Height, rl.Lime)
|
||||||
raylib.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), raylib.Red)
|
rl.DrawRectangleLines(15+int32(frameRec.X), 40+int32(frameRec.Y), int32(frameRec.Width), int32(frameRec.Height), rl.Red)
|
||||||
|
|
||||||
raylib.DrawText("FRAME SPEED: ", 165, 210, 10, raylib.DarkGray)
|
rl.DrawText("FRAME SPEED: ", 165, 210, 10, rl.DarkGray)
|
||||||
raylib.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, raylib.DarkGray)
|
rl.DrawText(fmt.Sprintf("%02d FPS", framesSpeed), 575, 210, 10, rl.DarkGray)
|
||||||
raylib.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, raylib.DarkGray)
|
rl.DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, rl.DarkGray)
|
||||||
|
|
||||||
for i := 0; i < maxFrameSpeed; i++ {
|
for i := 0; i < maxFrameSpeed; i++ {
|
||||||
if i < framesSpeed {
|
if i < framesSpeed {
|
||||||
raylib.DrawRectangle(int32(250+21*i), 205, 20, 20, raylib.Red)
|
rl.DrawRectangle(int32(250+21*i), 205, 20, 20, rl.Red)
|
||||||
}
|
}
|
||||||
raylib.DrawRectangleLines(int32(250+21*i), 205, 20, 20, raylib.Maroon)
|
rl.DrawRectangleLines(int32(250+21*i), 205, 20, 20, rl.Maroon)
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawTextureRec(scarfy, frameRec, position, raylib.White) // Draw part of the texture
|
rl.DrawTextureRec(scarfy, frameRec, position, rl.White) // Draw part of the texture
|
||||||
|
|
||||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(scarfy)
|
rl.UnloadTexture(scarfy)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,52 +8,52 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles")
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
scarfy := raylib.LoadTexture("scarfy.png") // Texture loading
|
scarfy := rl.LoadTexture("scarfy.png") // Texture loading
|
||||||
|
|
||||||
frameWidth := float32(scarfy.Width) / 7
|
frameWidth := float32(scarfy.Width) / 7
|
||||||
frameHeight := float32(scarfy.Height)
|
frameHeight := float32(scarfy.Height)
|
||||||
|
|
||||||
// NOTE: Source rectangle (part of the texture to use for drawing)
|
// NOTE: Source rectangle (part of the texture to use for drawing)
|
||||||
sourceRec := raylib.NewRectangle(0, 0, frameWidth, frameHeight)
|
sourceRec := rl.NewRectangle(0, 0, frameWidth, frameHeight)
|
||||||
|
|
||||||
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
|
// NOTE: Destination rectangle (screen rectangle where drawing part of texture)
|
||||||
destRec := raylib.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
|
destRec := rl.NewRectangle(float32(screenWidth)/2, float32(screenHeight)/2, frameWidth*2, frameHeight*2)
|
||||||
|
|
||||||
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
|
// NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size
|
||||||
origin := raylib.NewVector2(float32(frameWidth), float32(frameHeight))
|
origin := rl.NewVector2(float32(frameWidth), float32(frameHeight))
|
||||||
|
|
||||||
rotation := float32(0)
|
rotation := float32(0)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
rotation++
|
rotation++
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
// NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw
|
// 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
|
// 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)
|
// 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
|
// origin defines the point of the texture used as reference for rotation and scaling
|
||||||
// rotation defines the texture rotation (using origin as rotation point)
|
// rotation defines the texture rotation (using origin as rotation point)
|
||||||
raylib.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, raylib.White)
|
rl.DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, rl.White)
|
||||||
|
|
||||||
raylib.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, raylib.Gray)
|
rl.DrawLine(int32(destRec.X), 0, int32(destRec.X), screenHeight, rl.Gray)
|
||||||
raylib.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), raylib.Gray)
|
rl.DrawLine(0, int32(destRec.Y), screenWidth, int32(destRec.Y), rl.Gray)
|
||||||
|
|
||||||
raylib.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, raylib.Gray)
|
rl.DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(scarfy)
|
rl.UnloadTexture(scarfy)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,32 +8,32 @@ func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
||||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture to image")
|
||||||
|
|
||||||
image := raylib.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
|
image := rl.LoadImage("raylib_logo.png") // Load image data into CPU memory (RAM)
|
||||||
texture := raylib.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||||
raylib.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
rl.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
||||||
|
|
||||||
image = raylib.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
image = rl.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||||
raylib.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
rl.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
||||||
|
|
||||||
texture = raylib.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
texture = rl.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||||
raylib.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
|
rl.UnloadImage(image) // Unload retrieved image data from CPU memory (RAM)
|
||||||
|
|
||||||
raylib.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !raylib.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
raylib.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
raylib.ClearBackground(raylib.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raylib.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, raylib.White)
|
rl.DrawTexture(texture, screenWidth/2-texture.Width/2, screenHeight/2-texture.Height/2, rl.White)
|
||||||
raylib.DrawText("this IS a texture loaded from an image!", 300, 370, 10, raylib.Gray)
|
rl.DrawText("this IS a texture loaded from an image!", 300, 370, 10, rl.Gray)
|
||||||
|
|
||||||
raylib.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.UnloadTexture(texture)
|
rl.UnloadTexture(texture)
|
||||||
|
|
||||||
raylib.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,11 @@ type Polygon struct {
|
||||||
// Current used vertex and normals count
|
// Current used vertex and normals count
|
||||||
VertexCount int
|
VertexCount int
|
||||||
// Polygon vertex positions vectors
|
// Polygon vertex positions vectors
|
||||||
Vertices [maxVertices]raylib.Vector2
|
Vertices [maxVertices]rl.Vector2
|
||||||
// Polygon vertex normals vectors
|
// Polygon vertex normals vectors
|
||||||
Normals [maxVertices]raylib.Vector2
|
Normals [maxVertices]rl.Vector2
|
||||||
// Vertices transform matrix 2x2
|
// Vertices transform matrix 2x2
|
||||||
Transform raylib.Mat2
|
Transform rl.Mat2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shape type
|
// Shape type
|
||||||
|
@ -50,11 +50,11 @@ type Body struct {
|
||||||
// Enabled dynamics state (collisions are calculated anyway)
|
// Enabled dynamics state (collisions are calculated anyway)
|
||||||
Enabled bool
|
Enabled bool
|
||||||
// Physics body shape pivot
|
// Physics body shape pivot
|
||||||
Position raylib.Vector2
|
Position rl.Vector2
|
||||||
// Current linear velocity applied to position
|
// Current linear velocity applied to position
|
||||||
Velocity raylib.Vector2
|
Velocity rl.Vector2
|
||||||
// Current linear force (reset to 0 every step)
|
// Current linear force (reset to 0 every step)
|
||||||
Force raylib.Vector2
|
Force rl.Vector2
|
||||||
// Current angular velocity applied to orient
|
// Current angular velocity applied to orient
|
||||||
AngularVelocity float32
|
AngularVelocity float32
|
||||||
// Current angular force (reset to 0 every step)
|
// Current angular force (reset to 0 every step)
|
||||||
|
@ -94,9 +94,9 @@ type manifold struct {
|
||||||
// Depth of penetration from collision
|
// Depth of penetration from collision
|
||||||
Penetration float32
|
Penetration float32
|
||||||
// Normal direction vector from 'a' to 'b'
|
// Normal direction vector from 'a' to 'b'
|
||||||
Normal raylib.Vector2
|
Normal rl.Vector2
|
||||||
// Points of contact during collision
|
// Points of contact during collision
|
||||||
Contacts [2]raylib.Vector2
|
Contacts [2]rl.Vector2
|
||||||
// Current collision number of contacts
|
// Current collision number of contacts
|
||||||
ContactsCount int
|
ContactsCount int
|
||||||
// Mixed restitution during collision
|
// Mixed restitution during collision
|
||||||
|
@ -132,20 +132,26 @@ var (
|
||||||
manifolds []*manifold
|
manifolds []*manifold
|
||||||
|
|
||||||
// Physics world gravity force
|
// Physics world gravity force
|
||||||
gravityForce raylib.Vector2
|
gravityForce rl.Vector2
|
||||||
|
|
||||||
// Delta time used for physics steps
|
// Delta time used for physics steps, in milliseconds
|
||||||
deltaTime float32
|
deltaTime float32
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init - initializes physics values
|
// Init - initializes physics values
|
||||||
func Init() {
|
func Init() {
|
||||||
gravityForce = raylib.NewVector2(0, 9.81/1000)
|
deltaTime = 1.0 / 60.0 / 10.0 * 1000
|
||||||
|
gravityForce = rl.NewVector2(0, 9.81)
|
||||||
|
|
||||||
bodies = make([]*Body, 0, maxBodies)
|
bodies = make([]*Body, 0, maxBodies)
|
||||||
manifolds = make([]*manifold, 0, maxManifolds)
|
manifolds = make([]*manifold, 0, maxManifolds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets physics fixed time step in milliseconds. 1.666666 by default
|
||||||
|
func SetPhysicsTimeStep(delta float32) {
|
||||||
|
deltaTime = delta
|
||||||
|
}
|
||||||
|
|
||||||
// SetGravity - Sets physics global gravity force
|
// SetGravity - Sets physics global gravity force
|
||||||
func SetGravity(x, y float32) {
|
func SetGravity(x, y float32) {
|
||||||
gravityForce.X = x
|
gravityForce.X = x
|
||||||
|
@ -153,19 +159,19 @@ func SetGravity(x, y float32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBodyCircle - Creates a new circle physics body with generic parameters
|
// NewBodyCircle - Creates a new circle physics body with generic parameters
|
||||||
func NewBodyCircle(pos raylib.Vector2, radius, density float32) *Body {
|
func NewBodyCircle(pos rl.Vector2, radius, density float32) *Body {
|
||||||
return NewBodyPolygon(pos, radius, circleVertices, density)
|
return NewBodyPolygon(pos, radius, circleVertices, density)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBodyRectangle - Creates a new rectangle physics body with generic parameters
|
// NewBodyRectangle - Creates a new rectangle physics body with generic parameters
|
||||||
func NewBodyRectangle(pos raylib.Vector2, width, height, density float32) *Body {
|
func NewBodyRectangle(pos rl.Vector2, width, height, density float32) *Body {
|
||||||
newBody := &Body{}
|
newBody := &Body{}
|
||||||
|
|
||||||
// Initialize new body with generic values
|
// Initialize new body with generic values
|
||||||
newBody.Enabled = true
|
newBody.Enabled = true
|
||||||
newBody.Position = pos
|
newBody.Position = pos
|
||||||
newBody.Velocity = raylib.Vector2{}
|
newBody.Velocity = rl.Vector2{}
|
||||||
newBody.Force = raylib.Vector2{}
|
newBody.Force = rl.Vector2{}
|
||||||
newBody.AngularVelocity = 0
|
newBody.AngularVelocity = 0
|
||||||
newBody.Torque = 0
|
newBody.Torque = 0
|
||||||
newBody.Orient = 0
|
newBody.Orient = 0
|
||||||
|
@ -173,10 +179,10 @@ func NewBodyRectangle(pos raylib.Vector2, width, height, density float32) *Body
|
||||||
newBody.Shape = Shape{}
|
newBody.Shape = Shape{}
|
||||||
newBody.Shape.Type = PolygonShape
|
newBody.Shape.Type = PolygonShape
|
||||||
newBody.Shape.Body = newBody
|
newBody.Shape.Body = newBody
|
||||||
newBody.Shape.VertexData = newRectanglePolygon(pos, raylib.NewVector2(width, height))
|
newBody.Shape.VertexData = newRectanglePolygon(pos, rl.NewVector2(width, height))
|
||||||
|
|
||||||
// Calculate centroid and moment of inertia
|
// Calculate centroid and moment of inertia
|
||||||
center := raylib.Vector2{}
|
center := rl.Vector2{}
|
||||||
area := float32(0.0)
|
area := float32(0.0)
|
||||||
inertia := float32(0.0)
|
inertia := float32(0.0)
|
||||||
k := float32(1.0) / 3.0
|
k := float32(1.0) / 3.0
|
||||||
|
@ -238,14 +244,14 @@ func NewBodyRectangle(pos raylib.Vector2, width, height, density float32) *Body
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBodyPolygon - Creates a new polygon physics body with generic parameters
|
// NewBodyPolygon - Creates a new polygon physics body with generic parameters
|
||||||
func NewBodyPolygon(pos raylib.Vector2, radius float32, sides int, density float32) *Body {
|
func NewBodyPolygon(pos rl.Vector2, radius float32, sides int, density float32) *Body {
|
||||||
newBody := &Body{}
|
newBody := &Body{}
|
||||||
|
|
||||||
// Initialize new body with generic values
|
// Initialize new body with generic values
|
||||||
newBody.Enabled = true
|
newBody.Enabled = true
|
||||||
newBody.Position = pos
|
newBody.Position = pos
|
||||||
newBody.Velocity = raylib.Vector2{}
|
newBody.Velocity = rl.Vector2{}
|
||||||
newBody.Force = raylib.Vector2{}
|
newBody.Force = rl.Vector2{}
|
||||||
newBody.AngularVelocity = 0
|
newBody.AngularVelocity = 0
|
||||||
newBody.Torque = 0
|
newBody.Torque = 0
|
||||||
newBody.Orient = 0
|
newBody.Orient = 0
|
||||||
|
@ -256,7 +262,7 @@ func NewBodyPolygon(pos raylib.Vector2, radius float32, sides int, density float
|
||||||
newBody.Shape.VertexData = newRandomPolygon(radius, sides)
|
newBody.Shape.VertexData = newRandomPolygon(radius, sides)
|
||||||
|
|
||||||
// Calculate centroid and moment of inertia
|
// Calculate centroid and moment of inertia
|
||||||
center := raylib.Vector2{}
|
center := rl.Vector2{}
|
||||||
area := float32(0.0)
|
area := float32(0.0)
|
||||||
inertia := float32(0.0)
|
inertia := float32(0.0)
|
||||||
alpha := float32(1.0) / 3.0
|
alpha := float32(1.0) / 3.0
|
||||||
|
@ -334,7 +340,7 @@ func GetBody(index int) *Body {
|
||||||
if index < len(bodies) {
|
if index < len(bodies) {
|
||||||
body = bodies[index]
|
body = bodies[index]
|
||||||
} else {
|
} else {
|
||||||
raylib.TraceLog(raylib.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
rl.TraceLog(rl.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
||||||
}
|
}
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
@ -347,7 +353,7 @@ func GetShapeType(index int) ShapeType {
|
||||||
if index < len(bodies) {
|
if index < len(bodies) {
|
||||||
result = bodies[index].Shape.Type
|
result = bodies[index].Shape.Type
|
||||||
} else {
|
} else {
|
||||||
raylib.TraceLog(raylib.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
rl.TraceLog(rl.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -367,7 +373,7 @@ func GetShapeVerticesCount(index int) int {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
raylib.TraceLog(raylib.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
rl.TraceLog(rl.LogDebug, "[PHYSAC] physics body index is out of bounds")
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -388,7 +394,7 @@ func DestroyBody(body *Body) bool {
|
||||||
|
|
||||||
// Update - Physics steps calculations (dynamics, collisions and position corrections)
|
// Update - Physics steps calculations (dynamics, collisions and position corrections)
|
||||||
func Update() {
|
func Update() {
|
||||||
deltaTime = raylib.GetFrameTime() * 1000
|
deltaTime = rl.GetFrameTime() * 1000
|
||||||
|
|
||||||
// Clear previous generated collisions information
|
// Clear previous generated collisions information
|
||||||
for _, m := range manifolds {
|
for _, m := range manifolds {
|
||||||
|
@ -470,7 +476,7 @@ func Update() {
|
||||||
|
|
||||||
// Clear physics bodies forces
|
// Clear physics bodies forces
|
||||||
for _, b := range bodies {
|
for _, b := range bodies {
|
||||||
b.Force = raylib.Vector2{}
|
b.Force = rl.Vector2{}
|
||||||
b.Torque = 0
|
b.Torque = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -495,7 +501,7 @@ func Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddForce - Adds a force to a physics body
|
// AddForce - Adds a force to a physics body
|
||||||
func (b *Body) AddForce(force raylib.Vector2) {
|
func (b *Body) AddForce(force rl.Vector2) {
|
||||||
b.Force = raymath.Vector2Add(b.Force, force)
|
b.Force = raymath.Vector2Add(b.Force, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +511,7 @@ func (b *Body) AddTorque(amount float32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shatter - Shatters a polygon shape physics body to little physics bodies with explosion force
|
// Shatter - Shatters a polygon shape physics body to little physics bodies with explosion force
|
||||||
func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
func (b *Body) Shatter(position rl.Vector2, force float32) {
|
||||||
if b.Shape.Type != PolygonShape {
|
if b.Shape.Type != PolygonShape {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -543,7 +549,7 @@ func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
||||||
count := vertexData.VertexCount
|
count := vertexData.VertexCount
|
||||||
bodyPos := b.Position
|
bodyPos := b.Position
|
||||||
|
|
||||||
vertices := make([]raylib.Vector2, count)
|
vertices := make([]rl.Vector2, count)
|
||||||
trans := vertexData.Transform
|
trans := vertexData.Transform
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
vertices[i] = vertexData.Vertices[i]
|
vertices[i] = vertexData.Vertices[i]
|
||||||
|
@ -558,7 +564,7 @@ func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
||||||
nextIndex = i + 1
|
nextIndex = i + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
center := triangleBarycenter(vertices[i], vertices[nextIndex], raylib.NewVector2(0, 0))
|
center := triangleBarycenter(vertices[i], vertices[nextIndex], rl.NewVector2(0, 0))
|
||||||
center = raymath.Vector2Add(bodyPos, center)
|
center = raymath.Vector2Add(bodyPos, center)
|
||||||
offset := raymath.Vector2Subtract(center, bodyPos)
|
offset := raymath.Vector2Subtract(center, bodyPos)
|
||||||
|
|
||||||
|
@ -589,7 +595,7 @@ func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
||||||
|
|
||||||
face := raymath.Vector2Subtract(newData.Vertices[nextVertex], newData.Vertices[j])
|
face := raymath.Vector2Subtract(newData.Vertices[nextVertex], newData.Vertices[j])
|
||||||
|
|
||||||
newData.Normals[j] = raylib.NewVector2(face.Y, -face.X)
|
newData.Normals[j] = rl.NewVector2(face.Y, -face.X)
|
||||||
normalize(&newData.Normals[j])
|
normalize(&newData.Normals[j])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,7 +603,7 @@ func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
||||||
newBody.Shape.VertexData = newData
|
newBody.Shape.VertexData = newData
|
||||||
|
|
||||||
// Calculate centroid and moment of inertia
|
// Calculate centroid and moment of inertia
|
||||||
center = raylib.NewVector2(0, 0)
|
center = rl.NewVector2(0, 0)
|
||||||
area := float32(0.0)
|
area := float32(0.0)
|
||||||
inertia := float32(0.0)
|
inertia := float32(0.0)
|
||||||
k := float32(1.0) / 3.0
|
k := float32(1.0) / 3.0
|
||||||
|
@ -656,13 +662,13 @@ func (b *Body) Shatter(position raylib.Vector2, force float32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetShapeVertex - Returns transformed position of a body shape (body position + vertex transformed position)
|
// GetShapeVertex - Returns transformed position of a body shape (body position + vertex transformed position)
|
||||||
func (b *Body) GetShapeVertex(vertex int) raylib.Vector2 {
|
func (b *Body) GetShapeVertex(vertex int) rl.Vector2 {
|
||||||
position := raylib.Vector2{}
|
position := rl.Vector2{}
|
||||||
|
|
||||||
switch b.Shape.Type {
|
switch b.Shape.Type {
|
||||||
case CircleShape:
|
case CircleShape:
|
||||||
position.X = b.Position.X + float32(math.Cos(360/float64(circleVertices)*float64(vertex)*raylib.Deg2rad))*b.Shape.Radius
|
position.X = b.Position.X + float32(math.Cos(360/float64(circleVertices)*float64(vertex)*rl.Deg2rad))*b.Shape.Radius
|
||||||
position.Y = b.Position.Y + float32(math.Sin(360/float64(circleVertices)*float64(vertex)*raylib.Deg2rad))*b.Shape.Radius
|
position.Y = b.Position.Y + float32(math.Sin(360/float64(circleVertices)*float64(vertex)*rl.Deg2rad))*b.Shape.Radius
|
||||||
break
|
break
|
||||||
case PolygonShape:
|
case PolygonShape:
|
||||||
position = raymath.Vector2Add(b.Position, raymath.Mat2MultiplyVector2(b.Shape.VertexData.Transform, b.Shape.VertexData.Vertices[vertex]))
|
position = raymath.Vector2Add(b.Position, raymath.Mat2MultiplyVector2(b.Shape.VertexData.Transform, b.Shape.VertexData.Vertices[vertex]))
|
||||||
|
@ -709,8 +715,8 @@ func (b *Body) integrateForces() {
|
||||||
b.Velocity.Y += (b.Force.Y * b.InverseMass) * (deltaTime / 2)
|
b.Velocity.Y += (b.Force.Y * b.InverseMass) * (deltaTime / 2)
|
||||||
|
|
||||||
if b.UseGravity {
|
if b.UseGravity {
|
||||||
b.Velocity.X += gravityForce.X * (deltaTime / 2)
|
b.Velocity.X += gravityForce.X * (deltaTime / 1000 / 2)
|
||||||
b.Velocity.Y += gravityForce.Y * (deltaTime / 2)
|
b.Velocity.Y += gravityForce.Y * (deltaTime / 1000 / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !b.FreezeOrient {
|
if !b.FreezeOrient {
|
||||||
|
@ -723,13 +729,13 @@ func newRandomPolygon(radius float32, sides int) Polygon {
|
||||||
data := Polygon{}
|
data := Polygon{}
|
||||||
data.VertexCount = sides
|
data.VertexCount = sides
|
||||||
|
|
||||||
orient := raylib.GetRandomValue(0, 360)
|
orient := rl.GetRandomValue(0, 360)
|
||||||
data.Transform = raymath.Mat2Radians(float32(orient) * raylib.Deg2rad)
|
data.Transform = raymath.Mat2Radians(float32(orient) * rl.Deg2rad)
|
||||||
|
|
||||||
// Calculate polygon vertices positions
|
// Calculate polygon vertices positions
|
||||||
for i := 0; i < data.VertexCount; i++ {
|
for i := 0; i < data.VertexCount; i++ {
|
||||||
data.Vertices[i].X = float32(math.Cos(360/float64(sides)*float64(i)*raylib.Deg2rad)) * radius
|
data.Vertices[i].X = float32(math.Cos(360/float64(sides)*float64(i)*rl.Deg2rad)) * radius
|
||||||
data.Vertices[i].Y = float32(math.Sin(360/float64(sides)*float64(i)*raylib.Deg2rad)) * radius
|
data.Vertices[i].Y = float32(math.Sin(360/float64(sides)*float64(i)*rl.Deg2rad)) * radius
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate polygon faces normals
|
// Calculate polygon faces normals
|
||||||
|
@ -741,7 +747,7 @@ func newRandomPolygon(radius float32, sides int) Polygon {
|
||||||
|
|
||||||
face := raymath.Vector2Subtract(data.Vertices[nextIndex], data.Vertices[i])
|
face := raymath.Vector2Subtract(data.Vertices[nextIndex], data.Vertices[i])
|
||||||
|
|
||||||
data.Normals[i] = raylib.NewVector2(face.Y, -face.X)
|
data.Normals[i] = rl.NewVector2(face.Y, -face.X)
|
||||||
normalize(&data.Normals[i])
|
normalize(&data.Normals[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,17 +755,17 @@ func newRandomPolygon(radius float32, sides int) Polygon {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRectanglePolygon - Creates a rectangle polygon shape based on a min and max positions
|
// newRectanglePolygon - Creates a rectangle polygon shape based on a min and max positions
|
||||||
func newRectanglePolygon(pos, size raylib.Vector2) Polygon {
|
func newRectanglePolygon(pos, size rl.Vector2) Polygon {
|
||||||
data := Polygon{}
|
data := Polygon{}
|
||||||
|
|
||||||
data.VertexCount = 4
|
data.VertexCount = 4
|
||||||
data.Transform = raymath.Mat2Radians(0)
|
data.Transform = raymath.Mat2Radians(0)
|
||||||
|
|
||||||
// Calculate polygon vertices positions
|
// Calculate polygon vertices positions
|
||||||
data.Vertices[0] = raylib.NewVector2(pos.X+size.X/2, pos.Y-size.Y/2)
|
data.Vertices[0] = rl.NewVector2(pos.X+size.X/2, pos.Y-size.Y/2)
|
||||||
data.Vertices[1] = raylib.NewVector2(pos.X+size.X/2, pos.Y+size.Y/2)
|
data.Vertices[1] = rl.NewVector2(pos.X+size.X/2, pos.Y+size.Y/2)
|
||||||
data.Vertices[2] = raylib.NewVector2(pos.X-size.X/2, pos.Y+size.Y/2)
|
data.Vertices[2] = rl.NewVector2(pos.X-size.X/2, pos.Y+size.Y/2)
|
||||||
data.Vertices[3] = raylib.NewVector2(pos.X-size.X/2, pos.Y-size.Y/2)
|
data.Vertices[3] = rl.NewVector2(pos.X-size.X/2, pos.Y-size.Y/2)
|
||||||
|
|
||||||
// Calculate polygon faces normals
|
// Calculate polygon faces normals
|
||||||
for i := 0; i < data.VertexCount; i++ {
|
for i := 0; i < data.VertexCount; i++ {
|
||||||
|
@ -769,7 +775,7 @@ func newRectanglePolygon(pos, size raylib.Vector2) Polygon {
|
||||||
}
|
}
|
||||||
face := raymath.Vector2Subtract(data.Vertices[nextIndex], data.Vertices[i])
|
face := raymath.Vector2Subtract(data.Vertices[nextIndex], data.Vertices[i])
|
||||||
|
|
||||||
data.Normals[i] = raylib.NewVector2(face.Y, -face.X)
|
data.Normals[i] = rl.NewVector2(face.Y, -face.X)
|
||||||
normalize(&data.Normals[i])
|
normalize(&data.Normals[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,9 +790,9 @@ func newManifold(a, b *Body) *manifold {
|
||||||
newManifold.BodyA = a
|
newManifold.BodyA = a
|
||||||
newManifold.BodyB = b
|
newManifold.BodyB = b
|
||||||
newManifold.Penetration = 0
|
newManifold.Penetration = 0
|
||||||
newManifold.Normal = raylib.Vector2{}
|
newManifold.Normal = rl.Vector2{}
|
||||||
newManifold.Contacts[0] = raylib.Vector2{}
|
newManifold.Contacts[0] = rl.Vector2{}
|
||||||
newManifold.Contacts[1] = raylib.Vector2{}
|
newManifold.Contacts[1] = rl.Vector2{}
|
||||||
newManifold.ContactsCount = 0
|
newManifold.ContactsCount = 0
|
||||||
newManifold.Restitution = 0
|
newManifold.Restitution = 0
|
||||||
newManifold.DynamicFriction = 0
|
newManifold.DynamicFriction = 0
|
||||||
|
@ -862,12 +868,12 @@ func (m *manifold) solveCircleToCircle() {
|
||||||
|
|
||||||
if distance == 0 {
|
if distance == 0 {
|
||||||
m.Penetration = bodyA.Shape.Radius
|
m.Penetration = bodyA.Shape.Radius
|
||||||
m.Normal = raylib.NewVector2(1, 0)
|
m.Normal = rl.NewVector2(1, 0)
|
||||||
m.Contacts[0] = bodyA.Position
|
m.Contacts[0] = bodyA.Position
|
||||||
} else {
|
} else {
|
||||||
m.Penetration = radius - distance
|
m.Penetration = radius - distance
|
||||||
m.Normal = raylib.NewVector2(normal.X/distance, normal.Y/distance) // Faster than using normalize() due to sqrt is already performed
|
m.Normal = rl.NewVector2(normal.X/distance, normal.Y/distance) // Faster than using normalize() due to sqrt is already performed
|
||||||
m.Contacts[0] = raylib.NewVector2(m.Normal.X*bodyA.Shape.Radius+bodyA.Position.X, m.Normal.Y*bodyA.Shape.Radius+bodyA.Position.Y)
|
m.Contacts[0] = rl.NewVector2(m.Normal.X*bodyA.Shape.Radius+bodyA.Position.X, m.Normal.Y*bodyA.Shape.Radius+bodyA.Position.Y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update physics body grounded state if normal direction is down
|
// Update physics body grounded state if normal direction is down
|
||||||
|
@ -915,8 +921,8 @@ func (m *manifold) solveCircleToPolygon() {
|
||||||
if separation < epsilon {
|
if separation < epsilon {
|
||||||
m.ContactsCount = 1
|
m.ContactsCount = 1
|
||||||
normal := raymath.Mat2MultiplyVector2(vertexData.Transform, vertexData.Normals[faceNormal])
|
normal := raymath.Mat2MultiplyVector2(vertexData.Transform, vertexData.Normals[faceNormal])
|
||||||
m.Normal = raylib.NewVector2(-normal.X, -normal.Y)
|
m.Normal = rl.NewVector2(-normal.X, -normal.Y)
|
||||||
m.Contacts[0] = raylib.NewVector2(m.Normal.X*m.BodyA.Shape.Radius+m.BodyA.Position.X, m.Normal.Y*m.BodyA.Shape.Radius+m.BodyA.Position.Y)
|
m.Contacts[0] = rl.NewVector2(m.Normal.X*m.BodyA.Shape.Radius+m.BodyA.Position.X, m.Normal.Y*m.BodyA.Shape.Radius+m.BodyA.Position.Y)
|
||||||
m.Penetration = m.BodyA.Shape.Radius
|
m.Penetration = m.BodyA.Shape.Radius
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -960,8 +966,8 @@ func (m *manifold) solveCircleToPolygon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
normal = raymath.Mat2MultiplyVector2(vertexData.Transform, normal)
|
normal = raymath.Mat2MultiplyVector2(vertexData.Transform, normal)
|
||||||
m.Normal = raylib.NewVector2(-normal.X, -normal.Y)
|
m.Normal = rl.NewVector2(-normal.X, -normal.Y)
|
||||||
m.Contacts[0] = raylib.NewVector2(m.Normal.X*m.BodyA.Shape.Radius+m.BodyA.Position.X, m.Normal.Y*m.BodyA.Shape.Radius+m.BodyA.Position.Y)
|
m.Contacts[0] = rl.NewVector2(m.Normal.X*m.BodyA.Shape.Radius+m.BodyA.Position.X, m.Normal.Y*m.BodyA.Shape.Radius+m.BodyA.Position.Y)
|
||||||
m.ContactsCount = 1
|
m.ContactsCount = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1017,8 +1023,8 @@ func (m *manifold) solvePolygonToPolygon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// World space incident face
|
// World space incident face
|
||||||
incidentFace0 := raylib.Vector2{}
|
incidentFace0 := rl.Vector2{}
|
||||||
incidentFace1 := raylib.Vector2{}
|
incidentFace1 := rl.Vector2{}
|
||||||
findIncidentFace(&incidentFace0, &incidentFace1, refPoly, incPoly, referenceIndex)
|
findIncidentFace(&incidentFace0, &incidentFace1, refPoly, incPoly, referenceIndex)
|
||||||
|
|
||||||
// Setup reference face vertices
|
// Setup reference face vertices
|
||||||
|
@ -1042,13 +1048,13 @@ func (m *manifold) solvePolygonToPolygon() {
|
||||||
normalize(&sidePlaneNormal)
|
normalize(&sidePlaneNormal)
|
||||||
|
|
||||||
// Orthogonalize
|
// Orthogonalize
|
||||||
refFaceNormal := raylib.NewVector2(sidePlaneNormal.Y, -sidePlaneNormal.X)
|
refFaceNormal := rl.NewVector2(sidePlaneNormal.Y, -sidePlaneNormal.X)
|
||||||
refC := raymath.Vector2DotProduct(refFaceNormal, v1)
|
refC := raymath.Vector2DotProduct(refFaceNormal, v1)
|
||||||
negSide := raymath.Vector2DotProduct(sidePlaneNormal, v1) * -1
|
negSide := raymath.Vector2DotProduct(sidePlaneNormal, v1) * -1
|
||||||
posSide := raymath.Vector2DotProduct(sidePlaneNormal, v2)
|
posSide := raymath.Vector2DotProduct(sidePlaneNormal, v2)
|
||||||
|
|
||||||
// clip incident face to reference face side planes (due to floating point error, possible to not have required points
|
// clip incident face to reference face side planes (due to floating point error, possible to not have required points
|
||||||
if clip(raylib.NewVector2(-sidePlaneNormal.X, -sidePlaneNormal.Y), negSide, &incidentFace0, &incidentFace1) < 2 {
|
if clip(rl.NewVector2(-sidePlaneNormal.X, -sidePlaneNormal.Y), negSide, &incidentFace0, &incidentFace1) < 2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if clip(sidePlaneNormal, posSide, &incidentFace0, &incidentFace1) < 2 {
|
if clip(sidePlaneNormal, posSide, &incidentFace0, &incidentFace1) < 2 {
|
||||||
|
@ -1057,7 +1063,7 @@ func (m *manifold) solvePolygonToPolygon() {
|
||||||
|
|
||||||
// Flip normal if required
|
// Flip normal if required
|
||||||
if flip {
|
if flip {
|
||||||
m.Normal = raylib.NewVector2(-refFaceNormal.X, -refFaceNormal.Y)
|
m.Normal = rl.NewVector2(-refFaceNormal.X, -refFaceNormal.Y)
|
||||||
} else {
|
} else {
|
||||||
m.Normal = refFaceNormal
|
m.Normal = refFaceNormal
|
||||||
}
|
}
|
||||||
|
@ -1105,13 +1111,13 @@ func (m *manifold) initializeManifolds() {
|
||||||
crossA := raymath.Vector2Cross(bodyA.AngularVelocity, radiusA)
|
crossA := raymath.Vector2Cross(bodyA.AngularVelocity, radiusA)
|
||||||
crossB := raymath.Vector2Cross(bodyB.AngularVelocity, radiusB)
|
crossB := raymath.Vector2Cross(bodyB.AngularVelocity, radiusB)
|
||||||
|
|
||||||
radiusV := raylib.Vector2{}
|
radiusV := rl.Vector2{}
|
||||||
radiusV.X = bodyB.Velocity.X + crossB.X - bodyA.Velocity.X - crossA.X
|
radiusV.X = bodyB.Velocity.X + crossB.X - bodyA.Velocity.X - crossA.X
|
||||||
radiusV.Y = bodyB.Velocity.Y + crossB.Y - bodyA.Velocity.Y - crossA.Y
|
radiusV.Y = bodyB.Velocity.Y + crossB.Y - bodyA.Velocity.Y - crossA.Y
|
||||||
|
|
||||||
// Determine if we should perform a resting collision or not;
|
// Determine if we should perform a resting collision or not;
|
||||||
// The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution
|
// The idea is if the only thing moving this object is gravity, then the collision should be performed without any restitution
|
||||||
if raymath.Vector2LenSqr(radiusV) < (raymath.Vector2LenSqr(raylib.NewVector2(gravityForce.X*deltaTime, gravityForce.Y*deltaTime)) + epsilon) {
|
if raymath.Vector2LenSqr(radiusV) < (raymath.Vector2LenSqr(rl.NewVector2(gravityForce.X*deltaTime/1000, gravityForce.Y*deltaTime/1000)) + epsilon) {
|
||||||
m.Restitution = 0
|
m.Restitution = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1124,8 +1130,8 @@ func (m *manifold) integrateImpulses() {
|
||||||
|
|
||||||
// Early out and positional correct if both objects have infinite mass
|
// Early out and positional correct if both objects have infinite mass
|
||||||
if math.Abs(float64(bodyA.InverseMass+bodyB.InverseMass)) <= epsilon {
|
if math.Abs(float64(bodyA.InverseMass+bodyB.InverseMass)) <= epsilon {
|
||||||
bodyA.Velocity = raylib.Vector2{}
|
bodyA.Velocity = rl.Vector2{}
|
||||||
bodyB.Velocity = raylib.Vector2{}
|
bodyB.Velocity = rl.Vector2{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1135,7 +1141,7 @@ func (m *manifold) integrateImpulses() {
|
||||||
radiusB := raymath.Vector2Subtract(m.Contacts[i], bodyB.Position)
|
radiusB := raymath.Vector2Subtract(m.Contacts[i], bodyB.Position)
|
||||||
|
|
||||||
// Calculate relative velocity
|
// Calculate relative velocity
|
||||||
radiusV := raylib.Vector2{}
|
radiusV := rl.Vector2{}
|
||||||
radiusV.X = bodyB.Velocity.X + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).X - bodyA.Velocity.X - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).X
|
radiusV.X = bodyB.Velocity.X + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).X - bodyA.Velocity.X - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).X
|
||||||
radiusV.Y = bodyB.Velocity.Y + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).Y - bodyA.Velocity.Y - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).Y
|
radiusV.Y = bodyB.Velocity.Y + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).Y - bodyA.Velocity.Y - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).Y
|
||||||
|
|
||||||
|
@ -1158,13 +1164,13 @@ func (m *manifold) integrateImpulses() {
|
||||||
impulse /= float32(m.ContactsCount)
|
impulse /= float32(m.ContactsCount)
|
||||||
|
|
||||||
// Apply impulse to each physics body
|
// Apply impulse to each physics body
|
||||||
impulseV := raylib.NewVector2(m.Normal.X*impulse, m.Normal.Y*impulse)
|
impulseV := rl.NewVector2(m.Normal.X*impulse, m.Normal.Y*impulse)
|
||||||
|
|
||||||
if bodyA.Enabled {
|
if bodyA.Enabled {
|
||||||
bodyA.Velocity.X += bodyA.InverseMass * (-impulseV.X)
|
bodyA.Velocity.X += bodyA.InverseMass * (-impulseV.X)
|
||||||
bodyA.Velocity.Y += bodyA.InverseMass * (-impulseV.Y)
|
bodyA.Velocity.Y += bodyA.InverseMass * (-impulseV.Y)
|
||||||
if !bodyA.FreezeOrient {
|
if !bodyA.FreezeOrient {
|
||||||
bodyA.AngularVelocity += bodyA.InverseInertia * raymath.Vector2CrossProduct(radiusA, raylib.NewVector2(-impulseV.X, -impulseV.Y))
|
bodyA.AngularVelocity += bodyA.InverseInertia * raymath.Vector2CrossProduct(radiusA, rl.NewVector2(-impulseV.X, -impulseV.Y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1180,7 +1186,7 @@ func (m *manifold) integrateImpulses() {
|
||||||
radiusV.X = bodyB.Velocity.X + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).X - bodyA.Velocity.X - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).X
|
radiusV.X = bodyB.Velocity.X + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).X - bodyA.Velocity.X - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).X
|
||||||
radiusV.Y = bodyB.Velocity.Y + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).Y - bodyA.Velocity.Y - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).Y
|
radiusV.Y = bodyB.Velocity.Y + raymath.Vector2Cross(bodyB.AngularVelocity, radiusB).Y - bodyA.Velocity.Y - raymath.Vector2Cross(bodyA.AngularVelocity, radiusA).Y
|
||||||
|
|
||||||
tangent := raylib.NewVector2(radiusV.X-(m.Normal.X*raymath.Vector2DotProduct(radiusV, m.Normal)), radiusV.Y-(m.Normal.Y*raymath.Vector2DotProduct(radiusV, m.Normal)))
|
tangent := rl.NewVector2(radiusV.X-(m.Normal.X*raymath.Vector2DotProduct(radiusV, m.Normal)), radiusV.Y-(m.Normal.Y*raymath.Vector2DotProduct(radiusV, m.Normal)))
|
||||||
normalize(&tangent)
|
normalize(&tangent)
|
||||||
|
|
||||||
// Calculate impulse tangent magnitude
|
// Calculate impulse tangent magnitude
|
||||||
|
@ -1196,11 +1202,11 @@ func (m *manifold) integrateImpulses() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply coulumb's law
|
// Apply coulumb's law
|
||||||
tangentImpulse := raylib.Vector2{}
|
tangentImpulse := rl.Vector2{}
|
||||||
if absImpulseTangent < impulse*m.StaticFriction {
|
if absImpulseTangent < impulse*m.StaticFriction {
|
||||||
tangentImpulse = raylib.NewVector2(tangent.X*impulseTangent, tangent.Y*impulseTangent)
|
tangentImpulse = rl.NewVector2(tangent.X*impulseTangent, tangent.Y*impulseTangent)
|
||||||
} else {
|
} else {
|
||||||
tangentImpulse = raylib.NewVector2(tangent.X*-impulse*m.DynamicFriction, tangent.Y*-impulse*m.DynamicFriction)
|
tangentImpulse = rl.NewVector2(tangent.X*-impulse*m.DynamicFriction, tangent.Y*-impulse*m.DynamicFriction)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply friction impulse
|
// Apply friction impulse
|
||||||
|
@ -1209,7 +1215,7 @@ func (m *manifold) integrateImpulses() {
|
||||||
bodyA.Velocity.Y += bodyA.InverseMass * (-tangentImpulse.Y)
|
bodyA.Velocity.Y += bodyA.InverseMass * (-tangentImpulse.Y)
|
||||||
|
|
||||||
if !bodyA.FreezeOrient {
|
if !bodyA.FreezeOrient {
|
||||||
bodyA.AngularVelocity += bodyA.InverseInertia * raymath.Vector2CrossProduct(radiusA, raylib.NewVector2(-tangentImpulse.X, -tangentImpulse.Y))
|
bodyA.AngularVelocity += bodyA.InverseInertia * raymath.Vector2CrossProduct(radiusA, rl.NewVector2(-tangentImpulse.X, -tangentImpulse.Y))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1229,7 +1235,7 @@ func (m *manifold) correctPositions() {
|
||||||
bodyA := m.BodyA
|
bodyA := m.BodyA
|
||||||
bodyB := m.BodyB
|
bodyB := m.BodyB
|
||||||
|
|
||||||
correction := raylib.Vector2{}
|
correction := rl.Vector2{}
|
||||||
correction.X = float32(math.Max(float64(m.Penetration-penetrationAllowance), 0)) / (bodyA.InverseMass + bodyB.InverseMass) * m.Normal.X * penetrationCorrection
|
correction.X = float32(math.Max(float64(m.Penetration-penetrationAllowance), 0)) / (bodyA.InverseMass + bodyB.InverseMass) * m.Normal.X * penetrationCorrection
|
||||||
correction.Y = float32(math.Max(float64(m.Penetration-penetrationAllowance), 0)) / (bodyA.InverseMass + bodyB.InverseMass) * m.Normal.Y * penetrationCorrection
|
correction.Y = float32(math.Max(float64(m.Penetration-penetrationAllowance), 0)) / (bodyA.InverseMass + bodyB.InverseMass) * m.Normal.Y * penetrationCorrection
|
||||||
|
|
||||||
|
@ -1245,9 +1251,9 @@ func (m *manifold) correctPositions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSupport - Returns the extreme point along a direction within a polygon
|
// getSupport - Returns the extreme point along a direction within a polygon
|
||||||
func getSupport(shape Shape, dir raylib.Vector2) raylib.Vector2 {
|
func getSupport(shape Shape, dir rl.Vector2) rl.Vector2 {
|
||||||
bestProjection := float32(-fltMax)
|
bestProjection := float32(-fltMax)
|
||||||
bestVertex := raylib.Vector2{}
|
bestVertex := rl.Vector2{}
|
||||||
|
|
||||||
for i := 0; i < shape.VertexData.VertexCount; i++ {
|
for i := 0; i < shape.VertexData.VertexCount; i++ {
|
||||||
vertex := shape.VertexData.Vertices[i]
|
vertex := shape.VertexData.Vertices[i]
|
||||||
|
@ -1280,7 +1286,7 @@ func findAxisLeastPenetration(shapeA, shapeB Shape) (int, float32) {
|
||||||
normal = raymath.Mat2MultiplyVector2(buT, transNormal)
|
normal = raymath.Mat2MultiplyVector2(buT, transNormal)
|
||||||
|
|
||||||
// Retrieve support point from B shape along -n
|
// Retrieve support point from B shape along -n
|
||||||
support := getSupport(shapeB, raylib.NewVector2(-normal.X, -normal.Y))
|
support := getSupport(shapeB, rl.NewVector2(-normal.X, -normal.Y))
|
||||||
|
|
||||||
// Retrieve vertex on face from A shape, transform into B shape's model space
|
// Retrieve vertex on face from A shape, transform into B shape's model space
|
||||||
vertex := dataA.Vertices[i]
|
vertex := dataA.Vertices[i]
|
||||||
|
@ -1303,7 +1309,7 @@ func findAxisLeastPenetration(shapeA, shapeB Shape) (int, float32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// findIncidentFace - Finds two polygon shapes incident face
|
// findIncidentFace - Finds two polygon shapes incident face
|
||||||
func findIncidentFace(v0, v1 *raylib.Vector2, ref, inc Shape, index int) {
|
func findIncidentFace(v0, v1 *rl.Vector2, ref, inc Shape, index int) {
|
||||||
refData := ref.VertexData
|
refData := ref.VertexData
|
||||||
incData := inc.VertexData
|
incData := inc.VertexData
|
||||||
|
|
||||||
|
@ -1341,10 +1347,10 @@ func findIncidentFace(v0, v1 *raylib.Vector2, ref, inc Shape, index int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// clip - Calculates clipping based on a normal and two faces
|
// clip - Calculates clipping based on a normal and two faces
|
||||||
func clip(normal raylib.Vector2, clip float32, faceA, faceB *raylib.Vector2) int {
|
func clip(normal rl.Vector2, clip float32, faceA, faceB *rl.Vector2) int {
|
||||||
sp := 0
|
sp := 0
|
||||||
|
|
||||||
out := make([]raylib.Vector2, 2)
|
out := make([]rl.Vector2, 2)
|
||||||
out[0] = *faceA
|
out[0] = *faceA
|
||||||
out[1] = *faceB
|
out[1] = *faceB
|
||||||
|
|
||||||
|
@ -1387,8 +1393,8 @@ func biasGreaterThan(valueA, valueB float32) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// triangleBarycenter - Returns the barycenter of a triangle given by 3 points
|
// triangleBarycenter - Returns the barycenter of a triangle given by 3 points
|
||||||
func triangleBarycenter(v1, v2, v3 raylib.Vector2) raylib.Vector2 {
|
func triangleBarycenter(v1, v2, v3 rl.Vector2) rl.Vector2 {
|
||||||
result := raylib.Vector2{}
|
result := rl.Vector2{}
|
||||||
|
|
||||||
result.X = (v1.X + v2.X + v3.X) / 3
|
result.X = (v1.X + v2.X + v3.X) / 3
|
||||||
result.Y = (v1.Y + v2.Y + v3.Y) / 3
|
result.Y = (v1.Y + v2.Y + v3.Y) / 3
|
||||||
|
@ -1397,7 +1403,7 @@ func triangleBarycenter(v1, v2, v3 raylib.Vector2) raylib.Vector2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize - Normalize provided vector
|
// normalize - Normalize provided vector
|
||||||
func normalize(v *raylib.Vector2) {
|
func normalize(v *rl.Vector2) {
|
||||||
var length, ilength float32
|
var length, ilength float32
|
||||||
|
|
||||||
aux := *v
|
aux := *v
|
||||||
|
|
382
raygui/raygui.go
382
raygui/raygui.go
|
@ -339,30 +339,30 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// BackgroundColor - Get background color
|
// BackgroundColor - Get background color
|
||||||
func BackgroundColor() raylib.Color {
|
func BackgroundColor() rl.Color {
|
||||||
return raylib.GetColor(int32(style[GlobalBackgroundColor]))
|
return rl.GetColor(int32(style[GlobalBackgroundColor]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinesColor - Get lines color
|
// LinesColor - Get lines color
|
||||||
func LinesColor() raylib.Color {
|
func LinesColor() rl.Color {
|
||||||
return raylib.GetColor(int32(style[GlobalLinesColor]))
|
return rl.GetColor(int32(style[GlobalLinesColor]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextColor - Get text color for normal state
|
// TextColor - Get text color for normal state
|
||||||
func TextColor() raylib.Color {
|
func TextColor() rl.Color {
|
||||||
return raylib.GetColor(int32(style[GlobalTextColor]))
|
return rl.GetColor(int32(style[GlobalTextColor]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Label - Label element, show text
|
// Label - Label element, show text
|
||||||
func Label(bounds raylib.Rectangle, text string) {
|
func Label(bounds rl.Rectangle, text string) {
|
||||||
LabelEx(bounds, text, raylib.GetColor(int32(style[LabelTextColor])), raylib.NewColor(0, 0, 0, 0), raylib.NewColor(0, 0, 0, 0))
|
LabelEx(bounds, text, rl.GetColor(int32(style[LabelTextColor])), rl.NewColor(0, 0, 0, 0), rl.NewColor(0, 0, 0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelEx - Label element extended, configurable colors
|
// LabelEx - Label element extended, configurable colors
|
||||||
func LabelEx(bounds raylib.Rectangle, text string, textColor, border, inner raylib.Color) {
|
func LabelEx(bounds rl.Rectangle, text string, textColor, border, inner rl.Color) {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
// Update control
|
// Update control
|
||||||
textWidth := raylib.MeasureText(text, int32(style[GlobalTextFontsize]))
|
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
|
||||||
textHeight := int32(style[GlobalTextFontsize])
|
textHeight := int32(style[GlobalTextFontsize])
|
||||||
|
|
||||||
if b.Width < textWidth {
|
if b.Width < textWidth {
|
||||||
|
@ -373,19 +373,19 @@ func LabelEx(bounds raylib.Rectangle, text string, textColor, border, inner rayl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, border)
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, border)
|
||||||
raylib.DrawRectangle(b.X+int32(style[LabelBorderWidth]), b.Y+int32(style[LabelBorderWidth]), b.Width-(2*int32(style[LabelBorderWidth])), b.Height-(2*int32(style[LabelBorderWidth])), inner)
|
rl.DrawRectangle(b.X+int32(style[LabelBorderWidth]), b.Y+int32(style[LabelBorderWidth]), b.Width-(2*int32(style[LabelBorderWidth])), b.Height-(2*int32(style[LabelBorderWidth])), inner)
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(textWidth/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), textColor)
|
rl.DrawText(text, b.X+((b.Width/2)-(textWidth/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), textColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Button - Button element, returns true when clicked
|
// Button - Button element, returns true when clicked
|
||||||
func Button(bounds raylib.Rectangle, text string) bool {
|
func Button(bounds rl.Rectangle, text string) bool {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
clicked := false
|
clicked := false
|
||||||
|
|
||||||
textWidth := raylib.MeasureText(text, int32(style[GlobalTextFontsize]))
|
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
|
||||||
textHeight := int32(style[GlobalTextFontsize])
|
textHeight := int32(style[GlobalTextFontsize])
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
|
@ -397,10 +397,10 @@ func Button(bounds raylib.Rectangle, text string) bool {
|
||||||
b.Height = textHeight + int32(style[ButtonTextPadding])/2
|
b.Height = textHeight + int32(style[ButtonTextPadding])/2
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
clicked = true
|
clicked = true
|
||||||
} else {
|
} else {
|
||||||
state = Focused
|
state = Focused
|
||||||
|
@ -410,21 +410,21 @@ func Button(bounds raylib.Rectangle, text string) bool {
|
||||||
// Draw control
|
// Draw control
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ButtonDefaultBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonDefaultBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), raylib.GetColor(int32(style[ButtonDefaultInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonDefaultInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ButtonDefaultTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonDefaultTextColor])))
|
||||||
break
|
break
|
||||||
|
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ButtonHoverBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonHoverBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), raylib.GetColor(int32(style[ButtonHoverInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonHoverInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ButtonHoverTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonHoverTextColor])))
|
||||||
break
|
break
|
||||||
|
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ButtonPressedBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ButtonPressedBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), raylib.GetColor(int32(style[ButtonPressedInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ButtonBorderWidth]), b.Y+int32(style[ButtonBorderWidth]), b.Width-(2*int32(style[ButtonBorderWidth])), b.Height-(2*int32(style[ButtonBorderWidth])), rl.GetColor(int32(style[ButtonPressedInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ButtonPressedTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ButtonPressedTextColor])))
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -439,12 +439,12 @@ func Button(bounds raylib.Rectangle, text string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToggleButton - Toggle Button element, returns true when active
|
// ToggleButton - Toggle Button element, returns true when active
|
||||||
func ToggleButton(bounds raylib.Rectangle, text string, active bool) bool {
|
func ToggleButton(bounds rl.Rectangle, text string, active bool) bool {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
|
|
||||||
textWidth := raylib.MeasureText(text, int32(style[GlobalTextFontsize]))
|
textWidth := rl.MeasureText(text, int32(style[GlobalTextFontsize]))
|
||||||
textHeight := int32(style[GlobalTextFontsize])
|
textHeight := int32(style[GlobalTextFontsize])
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
|
@ -455,10 +455,10 @@ func ToggleButton(bounds raylib.Rectangle, text string, active bool) bool {
|
||||||
b.Height = textHeight + int32(style[ToggleTextPadding])/2
|
b.Height = textHeight + int32(style[ToggleTextPadding])/2
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
state = Normal
|
state = Normal
|
||||||
active = !active
|
active = !active
|
||||||
} else {
|
} else {
|
||||||
|
@ -470,24 +470,24 @@ func ToggleButton(bounds raylib.Rectangle, text string, active bool) bool {
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
if active {
|
if active {
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ToggleActiveBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleActiveBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[ToggleActiveInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleActiveInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ToggleDefaultTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleDefaultTextColor])))
|
||||||
} else {
|
} else {
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ToggleDefaultBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleDefaultBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[ToggleDefaultInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleDefaultInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ToggleDefaultTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleDefaultTextColor])))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ToggleHoverBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleHoverBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[ToggleHoverInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[ToggleHoverInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ToggleHoverTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ToggleHoverTextColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[TogglePressedBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[TogglePressedBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[TogglePressedInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[TogglePressedInsideColor])))
|
||||||
raylib.DrawText(text, b.X+((b.Width/2)-(raylib.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[TogglePressedTextColor])))
|
rl.DrawText(text, b.X+((b.Width/2)-(rl.MeasureText(text, int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[TogglePressedTextColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -497,11 +497,11 @@ func ToggleButton(bounds raylib.Rectangle, text string, active bool) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToggleGroup - Toggle Group element, returns toggled button index
|
// ToggleGroup - Toggle Group element, returns toggled button index
|
||||||
func ToggleGroup(bounds raylib.Rectangle, toggleText []string, active int) int {
|
func ToggleGroup(bounds rl.Rectangle, toggleText []string, active int) int {
|
||||||
for i := 0; i < len(toggleText); i++ {
|
for i := 0; i < len(toggleText); i++ {
|
||||||
if i == active {
|
if i == active {
|
||||||
ToggleButton(raylib.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], true)
|
ToggleButton(rl.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], true)
|
||||||
} else if ToggleButton(raylib.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], false) {
|
} else if ToggleButton(rl.NewRectangle(bounds.X+float32(i)*(bounds.Width+float32(style[TogglegroupPadding])), bounds.Y, bounds.Width, bounds.Height), toggleText[i], false) {
|
||||||
active = i
|
active = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,15 +510,15 @@ func ToggleGroup(bounds raylib.Rectangle, toggleText []string, active int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ComboBox - Combo Box element, returns selected item index
|
// ComboBox - Combo Box element, returns selected item index
|
||||||
func ComboBox(bounds raylib.Rectangle, comboText []string, active int) int {
|
func ComboBox(bounds rl.Rectangle, comboText []string, active int) int {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
|
|
||||||
clicked := false
|
clicked := false
|
||||||
click := raylib.NewRectangle(bounds.X+bounds.Width+float32(style[ComboboxPadding]), bounds.Y, float32(style[boundsWidth]), float32(style[boundsHeight]))
|
click := rl.NewRectangle(bounds.X+bounds.Width+float32(style[ComboboxPadding]), bounds.Y, float32(style[boundsWidth]), float32(style[boundsHeight]))
|
||||||
c := click.ToInt32()
|
c := click.ToInt32()
|
||||||
|
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
|
|
||||||
textWidth := int32(0)
|
textWidth := int32(0)
|
||||||
textHeight := int32(style[GlobalTextFontsize])
|
textHeight := int32(style[GlobalTextFontsize])
|
||||||
|
@ -528,7 +528,7 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, active int) int {
|
||||||
for i := 0; i < comboCount; i++ {
|
for i := 0; i < comboCount; i++ {
|
||||||
if i == active {
|
if i == active {
|
||||||
// Update control
|
// Update control
|
||||||
textWidth = raylib.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))
|
textWidth = rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))
|
||||||
|
|
||||||
if b.Width < textWidth {
|
if b.Width < textWidth {
|
||||||
b.Width = textWidth + int32(style[ToggleTextPadding])
|
b.Width = textWidth + int32(style[ToggleTextPadding])
|
||||||
|
@ -537,10 +537,10 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, active int) int {
|
||||||
b.Height = textHeight + int32(style[ToggleTextPadding])/2
|
b.Height = textHeight + int32(style[ToggleTextPadding])/2
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) || raylib.CheckCollisionPointRec(mousePoint, click) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) || rl.CheckCollisionPointRec(mousePoint, click) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
clicked = true
|
clicked = true
|
||||||
} else {
|
} else {
|
||||||
state = Focused
|
state = Focused
|
||||||
|
@ -550,51 +550,51 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, active int) int {
|
||||||
// Draw control
|
// Draw control
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ComboboxDefaultBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxDefaultBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxDefaultInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxDefaultInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(c.X, c.Y, c.Width, c.Height, raylib.GetColor(int32(style[ComboboxDefaultBorderColor])))
|
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxDefaultBorderColor])))
|
||||||
raylib.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxDefaultInsideColor])))
|
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxDefaultInsideColor])))
|
||||||
raylib.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(raylib.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxDefaultListTextColor])))
|
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxDefaultListTextColor])))
|
||||||
raylib.DrawText(comboText[i], b.X+((b.Width/2)-(raylib.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxDefaultTextColor])))
|
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxDefaultTextColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ComboboxHoverBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxHoverBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxHoverInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxHoverInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(c.X, c.Y, c.Width, c.Height, raylib.GetColor(int32(style[ComboboxHoverBorderColor])))
|
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxHoverBorderColor])))
|
||||||
raylib.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxHoverInsideColor])))
|
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxHoverInsideColor])))
|
||||||
raylib.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(raylib.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxHoverListTextColor])))
|
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxHoverListTextColor])))
|
||||||
raylib.DrawText(comboText[i], b.X+((b.Width/2)-(raylib.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxHoverTextColor])))
|
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxHoverTextColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ComboboxPressedBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxPressedBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxPressedInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(c.X, c.Y, c.Width, c.Height, raylib.GetColor(int32(style[ComboboxPressedListBorderColor])))
|
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxPressedListBorderColor])))
|
||||||
raylib.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxPressedListInsideColor])))
|
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedListInsideColor])))
|
||||||
raylib.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(raylib.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxPressedListTextColor])))
|
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedListTextColor])))
|
||||||
raylib.DrawText(comboText[i], b.X+((b.Width/2)-(raylib.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxPressedTextColor])))
|
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedTextColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if clicked {
|
if clicked {
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ComboboxPressedBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ComboboxPressedBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxPressedInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ComboboxBorderWidth]), b.Y+int32(style[ComboboxBorderWidth]), b.Width-(2*int32(style[ComboboxBorderWidth])), b.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(c.X, c.Y, c.Width, c.Height, raylib.GetColor(int32(style[ComboboxPressedListBorderColor])))
|
rl.DrawRectangle(c.X, c.Y, c.Width, c.Height, rl.GetColor(int32(style[ComboboxPressedListBorderColor])))
|
||||||
raylib.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), raylib.GetColor(int32(style[ComboboxPressedListInsideColor])))
|
rl.DrawRectangle(c.X+int32(style[ComboboxBorderWidth]), c.Y+int32(style[ComboboxBorderWidth]), c.Width-(2*int32(style[ComboboxBorderWidth])), c.Height-(2*int32(style[ComboboxBorderWidth])), rl.GetColor(int32(style[ComboboxPressedListInsideColor])))
|
||||||
raylib.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(raylib.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxPressedListTextColor])))
|
rl.DrawText(fmt.Sprintf("%d/%d", active+1, comboCount), c.X+((c.Width/2)-(rl.MeasureText(fmt.Sprintf("%d/%d", active+1, comboCount), int32(style[GlobalTextFontsize]))/2)), c.Y+((c.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedListTextColor])))
|
||||||
raylib.DrawText(comboText[i], b.X+((b.Width/2)-(raylib.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[ComboboxPressedTextColor])))
|
rl.DrawText(comboText[i], b.X+((b.Width/2)-(rl.MeasureText(comboText[i], int32(style[GlobalTextFontsize]))/2)), b.Y+((b.Height/2)-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[ComboboxPressedTextColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) || raylib.CheckCollisionPointRec(mousePoint, click) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) || rl.CheckCollisionPointRec(mousePoint, click) {
|
||||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
active++
|
active++
|
||||||
if active >= comboCount {
|
if active >= comboCount {
|
||||||
active = 0
|
active = 0
|
||||||
|
@ -606,16 +606,16 @@ func ComboBox(bounds raylib.Rectangle, comboText []string, active int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckBox - Check Box element, returns true when active
|
// CheckBox - Check Box element, returns true when active
|
||||||
func CheckBox(bounds raylib.Rectangle, checked bool) bool {
|
func CheckBox(bounds rl.Rectangle, checked bool) bool {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
} else if raylib.IsMouseButtonReleased(raylib.MouseLeftButton) || raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
} else if rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
state = Normal
|
state = Normal
|
||||||
checked = !checked
|
checked = !checked
|
||||||
} else {
|
} else {
|
||||||
|
@ -626,36 +626,36 @@ func CheckBox(bounds raylib.Rectangle, checked bool) bool {
|
||||||
// Draw control
|
// Draw control
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[CheckboxDefaultBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxDefaultBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[CheckboxDefaultInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxDefaultInsideColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[CheckboxHoverBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxHoverBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[CheckboxHoverInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxHoverInsideColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[CheckboxClickBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[CheckboxClickBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), raylib.GetColor(int32(style[CheckboxClickInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[ToggleBorderWidth]), b.Y+int32(style[ToggleBorderWidth]), b.Width-(2*int32(style[ToggleBorderWidth])), b.Height-(2*int32(style[ToggleBorderWidth])), rl.GetColor(int32(style[CheckboxClickInsideColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if checked {
|
if checked {
|
||||||
raylib.DrawRectangle(b.X+int32(style[CheckboxInsideWidth]), b.Y+int32(style[CheckboxInsideWidth]), b.Width-(2*int32(style[CheckboxInsideWidth])), b.Height-(2*int32(style[CheckboxInsideWidth])), raylib.GetColor(int32(style[CheckboxDefaultActiveColor])))
|
rl.DrawRectangle(b.X+int32(style[CheckboxInsideWidth]), b.Y+int32(style[CheckboxInsideWidth]), b.Width-(2*int32(style[CheckboxInsideWidth])), b.Height-(2*int32(style[CheckboxInsideWidth])), rl.GetColor(int32(style[CheckboxDefaultActiveColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
return checked
|
return checked
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slider - Slider element, returns selected value
|
// Slider - Slider element, returns selected value
|
||||||
func Slider(bounds raylib.Rectangle, value, minValue, maxValue float32) float32 {
|
func Slider(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
sliderPos := float32(0)
|
sliderPos := float32(0)
|
||||||
state := Normal
|
state := Normal
|
||||||
|
|
||||||
buttonTravelDistance := float32(0)
|
buttonTravelDistance := float32(0)
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
if value < minValue {
|
if value < minValue {
|
||||||
|
@ -666,7 +666,7 @@ func Slider(bounds raylib.Rectangle, value, minValue, maxValue float32) float32
|
||||||
|
|
||||||
sliderPos = (value - minValue) / (maxValue - minValue)
|
sliderPos = (value - minValue) / (maxValue - minValue)
|
||||||
|
|
||||||
sliderButton := raylib.RectangleInt32{}
|
sliderButton := rl.RectangleInt32{}
|
||||||
sliderButton.Width = (b.Width-(2*int32(style[SliderButtonBorderWidth])))/10 - 8
|
sliderButton.Width = (b.Width-(2*int32(style[SliderButtonBorderWidth])))/10 - 8
|
||||||
sliderButton.Height = b.Height - (2 * int32(style[SliderBorderWidth]+2*style[SliderButtonBorderWidth]))
|
sliderButton.Height = b.Height - (2 * int32(style[SliderBorderWidth]+2*style[SliderButtonBorderWidth]))
|
||||||
|
|
||||||
|
@ -678,14 +678,14 @@ func Slider(bounds raylib.Rectangle, value, minValue, maxValue float32) float32
|
||||||
sliderButton.X = b.X + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth]) + int32(sliderPos*buttonTravelDistance)
|
sliderButton.X = b.X + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth]) + int32(sliderPos*buttonTravelDistance)
|
||||||
sliderButton.Y = b.Y + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth])
|
sliderButton.Y = b.Y + int32(style[SliderBorderWidth]) + int32(style[SliderButtonBorderWidth])
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
state = Focused
|
state = Focused
|
||||||
|
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
}
|
}
|
||||||
|
|
||||||
if state == Pressed && raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if state == Pressed && rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
sliderButton.X = int32(mousePoint.X) - sliderButton.Width/2
|
sliderButton.X = int32(mousePoint.X) - sliderButton.Width/2
|
||||||
|
|
||||||
if sliderButton.X <= sliderButtonMinPos {
|
if sliderButton.X <= sliderButtonMinPos {
|
||||||
|
@ -701,18 +701,18 @@ func Slider(bounds raylib.Rectangle, value, minValue, maxValue float32) float32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[SliderBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), raylib.GetColor(int32(style[SliderInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderInsideColor])))
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, raylib.GetColor(int32(style[SliderDefaultColor])))
|
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderDefaultColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, raylib.GetColor(int32(style[SliderHoverColor])))
|
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderHoverColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, raylib.GetColor(int32(style[SliderActiveColor])))
|
rl.DrawRectangle(sliderButton.X, sliderButton.Y, sliderButton.Width, sliderButton.Height, rl.GetColor(int32(style[SliderActiveColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -722,11 +722,11 @@ func Slider(bounds raylib.Rectangle, value, minValue, maxValue float32) float32
|
||||||
}
|
}
|
||||||
|
|
||||||
// SliderBar - Slider Bar element, returns selected value
|
// SliderBar - Slider Bar element, returns selected value
|
||||||
func SliderBar(bounds raylib.Rectangle, value, minValue, maxValue float32) float32 {
|
func SliderBar(bounds rl.Rectangle, value, minValue, maxValue float32) float32 {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
|
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
|
|
||||||
fixedValue := float32(0)
|
fixedValue := float32(0)
|
||||||
fixedMinValue := float32(0)
|
fixedMinValue := float32(0)
|
||||||
|
@ -742,17 +742,17 @@ func SliderBar(bounds raylib.Rectangle, value, minValue, maxValue float32) float
|
||||||
fixedValue = maxValue
|
fixedValue = maxValue
|
||||||
}
|
}
|
||||||
|
|
||||||
sliderBar := raylib.RectangleInt32{}
|
sliderBar := rl.RectangleInt32{}
|
||||||
|
|
||||||
sliderBar.X = b.X + int32(style[SliderBorderWidth])
|
sliderBar.X = b.X + int32(style[SliderBorderWidth])
|
||||||
sliderBar.Y = b.Y + int32(style[SliderBorderWidth])
|
sliderBar.Y = b.Y + int32(style[SliderBorderWidth])
|
||||||
sliderBar.Width = int32((fixedValue * (float32(b.Width) - 2*float32(style[SliderBorderWidth]))) / (maxValue - fixedMinValue))
|
sliderBar.Width = int32((fixedValue * (float32(b.Width) - 2*float32(style[SliderBorderWidth]))) / (maxValue - fixedMinValue))
|
||||||
sliderBar.Height = b.Height - 2*int32(style[SliderBorderWidth])
|
sliderBar.Height = b.Height - 2*int32(style[SliderBorderWidth])
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
state = Focused
|
state = Focused
|
||||||
|
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
|
|
||||||
sliderBar.Width = (int32(mousePoint.X) - b.X - int32(style[SliderBorderWidth]))
|
sliderBar.Width = (int32(mousePoint.X) - b.X - int32(style[SliderBorderWidth]))
|
||||||
|
@ -770,32 +770,32 @@ func SliderBar(bounds raylib.Rectangle, value, minValue, maxValue float32) float
|
||||||
fixedValue = (float32(sliderBar.Width) * (maxValue - fixedMinValue)) / (float32(b.Width) - 2*float32(style[SliderBorderWidth]))
|
fixedValue = (float32(sliderBar.Width) * (maxValue - fixedMinValue)) / (float32(b.Width) - 2*float32(style[SliderBorderWidth]))
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[SliderbarBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[SliderbarBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), raylib.GetColor(int32(style[SliderbarInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[SliderBorderWidth]), b.Y+int32(style[SliderBorderWidth]), b.Width-(2*int32(style[SliderBorderWidth])), b.Height-(2*int32(style[SliderBorderWidth])), rl.GetColor(int32(style[SliderbarInsideColor])))
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, raylib.GetColor(int32(style[SliderbarDefaultColor])))
|
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarDefaultColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, raylib.GetColor(int32(style[SliderbarHoverColor])))
|
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarHoverColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
raylib.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, raylib.GetColor(int32(style[SliderbarActiveColor])))
|
rl.DrawRectangle(sliderBar.X, sliderBar.Y, sliderBar.Width, sliderBar.Height, rl.GetColor(int32(style[SliderbarActiveColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if minValue < 0 && maxValue > 0 {
|
if minValue < 0 && maxValue > 0 {
|
||||||
raylib.DrawRectangle((b.X+int32(style[SliderBorderWidth]))-int32(minValue*(float32(b.Width-(int32(style[SliderBorderWidth])*2))/maxValue)), sliderBar.Y, 1, sliderBar.Height, raylib.GetColor(int32(style[SliderbarZeroLineColor])))
|
rl.DrawRectangle((b.X+int32(style[SliderBorderWidth]))-int32(minValue*(float32(b.Width-(int32(style[SliderBorderWidth])*2))/maxValue)), sliderBar.Y, 1, sliderBar.Height, rl.GetColor(int32(style[SliderbarZeroLineColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixedValue + minValue
|
return fixedValue + minValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProgressBar - Progress Bar element, shows current progress value
|
// ProgressBar - Progress Bar element, shows current progress value
|
||||||
func ProgressBar(bounds raylib.Rectangle, value float32) {
|
func ProgressBar(bounds rl.Rectangle, value float32) {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
if value > 1.0 {
|
if value > 1.0 {
|
||||||
value = 1.0
|
value = 1.0
|
||||||
|
@ -803,39 +803,39 @@ func ProgressBar(bounds raylib.Rectangle, value float32) {
|
||||||
value = 0.0
|
value = 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar := raylib.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), b.Width - (int32(style[ProgressbarBorderWidth]) * 2), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
|
progressBar := rl.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), b.Width - (int32(style[ProgressbarBorderWidth]) * 2), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
|
||||||
progressValue := raylib.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), int32(value * float32(b.Width-int32(style[ProgressbarBorderWidth])*2)), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
|
progressValue := rl.RectangleInt32{b.X + int32(style[ProgressbarBorderWidth]), b.Y + int32(style[ProgressbarBorderWidth]), int32(value * float32(b.Width-int32(style[ProgressbarBorderWidth])*2)), b.Height - (int32(style[ProgressbarBorderWidth]) * 2)}
|
||||||
|
|
||||||
// Draw control
|
// Draw control
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ProgressbarBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ProgressbarBorderColor])))
|
||||||
raylib.DrawRectangle(progressBar.X, progressBar.Y, progressBar.Width, progressBar.Height, raylib.GetColor(int32(style[ProgressbarInsideColor])))
|
rl.DrawRectangle(progressBar.X, progressBar.Y, progressBar.Width, progressBar.Height, rl.GetColor(int32(style[ProgressbarInsideColor])))
|
||||||
raylib.DrawRectangle(progressValue.X, progressValue.Y, progressValue.Width, progressValue.Height, raylib.GetColor(int32(style[ProgressbarProgressColor])))
|
rl.DrawRectangle(progressValue.X, progressValue.Y, progressValue.Width, progressValue.Height, rl.GetColor(int32(style[ProgressbarProgressColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spinner - Spinner element, returns selected value
|
// Spinner - Spinner element, returns selected value
|
||||||
func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
func Spinner(bounds rl.Rectangle, value, minValue, maxValue int) int {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
|
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
labelBoxBound := raylib.RectangleInt32{b.X + b.Width/4 + 1, b.Y, b.Width / 2, b.Height}
|
labelBoxBound := rl.RectangleInt32{b.X + b.Width/4 + 1, b.Y, b.Width / 2, b.Height}
|
||||||
leftButtonBound := raylib.RectangleInt32{b.X, b.Y, b.Width / 4, b.Height}
|
leftButtonBound := rl.RectangleInt32{b.X, b.Y, b.Width / 4, b.Height}
|
||||||
rightButtonBound := raylib.RectangleInt32{b.X + b.Width - b.Width/4 + 1, b.Y, b.Width / 4, b.Height}
|
rightButtonBound := rl.RectangleInt32{b.X + b.Width - b.Width/4 + 1, b.Y, b.Width / 4, b.Height}
|
||||||
|
|
||||||
textWidth := raylib.MeasureText(fmt.Sprintf("%d", value), int32(style[GlobalTextFontsize]))
|
textWidth := rl.MeasureText(fmt.Sprintf("%d", value), int32(style[GlobalTextFontsize]))
|
||||||
|
|
||||||
buttonSide := 0
|
buttonSide := 0
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) || raylib.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) || raylib.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
|
if rl.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) || rl.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) || rl.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
|
||||||
if raylib.IsKeyDown(raylib.KeyLeft) {
|
if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
buttonSide = 1
|
buttonSide = 1
|
||||||
|
|
||||||
if value > minValue {
|
if value > minValue {
|
||||||
value--
|
value--
|
||||||
}
|
}
|
||||||
} else if raylib.IsKeyDown(raylib.KeyRight) {
|
} else if rl.IsKeyDown(rl.KeyRight) {
|
||||||
state = Pressed
|
state = Pressed
|
||||||
buttonSide = 2
|
buttonSide = 2
|
||||||
|
|
||||||
|
@ -845,11 +845,11 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) {
|
if rl.CheckCollisionPointRec(mousePoint, leftButtonBound.ToFloat32()) {
|
||||||
buttonSide = 1
|
buttonSide = 1
|
||||||
state = Focused
|
state = Focused
|
||||||
|
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
if !valueSpeed {
|
if !valueSpeed {
|
||||||
if value > minValue {
|
if value > minValue {
|
||||||
value--
|
value--
|
||||||
|
@ -867,11 +867,11 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if raylib.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) {
|
} else if rl.CheckCollisionPointRec(mousePoint, rightButtonBound.ToFloat32()) {
|
||||||
buttonSide = 2
|
buttonSide = 2
|
||||||
state = Focused
|
state = Focused
|
||||||
|
|
||||||
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonDown(rl.MouseLeftButton) {
|
||||||
if !valueSpeed {
|
if !valueSpeed {
|
||||||
if value < maxValue {
|
if value < maxValue {
|
||||||
value++
|
value++
|
||||||
|
@ -889,11 +889,11 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !raylib.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
|
} else if !rl.CheckCollisionPointRec(mousePoint, labelBoxBound.ToFloat32()) {
|
||||||
buttonSide = 0
|
buttonSide = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsMouseButtonUp(raylib.MouseLeftButton) {
|
if rl.IsMouseButtonUp(rl.MouseLeftButton) {
|
||||||
valueSpeed = false
|
valueSpeed = false
|
||||||
framesCounter = 0
|
framesCounter = 0
|
||||||
}
|
}
|
||||||
|
@ -901,71 +901,71 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
||||||
// Draw control
|
// Draw control
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(raylib.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
raylib.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(raylib.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, raylib.GetColor(int32(style[SpinnerLabelBorderColor])))
|
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
|
||||||
raylib.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, raylib.GetColor(int32(style[SpinnerLabelInsideColor])))
|
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultTextColor])))
|
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultTextColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
if buttonSide == 1 {
|
if buttonSide == 1 {
|
||||||
raylib.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, raylib.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
|
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
|
||||||
raylib.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
|
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(raylib.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerHoverSymbolColor])))
|
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverSymbolColor])))
|
||||||
raylib.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(raylib.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
} else if buttonSide == 2 {
|
} else if buttonSide == 2 {
|
||||||
raylib.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, raylib.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
|
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerHoverButtonBorderColor])))
|
||||||
raylib.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
|
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerHoverButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(raylib.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
raylib.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(raylib.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerHoverSymbolColor])))
|
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverSymbolColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, raylib.GetColor(int32(style[SpinnerLabelBorderColor])))
|
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
|
||||||
raylib.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, raylib.GetColor(int32(style[SpinnerLabelInsideColor])))
|
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerHoverTextColor])))
|
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerHoverTextColor])))
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
if buttonSide == 1 {
|
if buttonSide == 1 {
|
||||||
raylib.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, raylib.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
|
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
|
||||||
raylib.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
|
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(raylib.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerPressedSymbolColor])))
|
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedSymbolColor])))
|
||||||
raylib.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(raylib.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
} else if buttonSide == 2 {
|
} else if buttonSide == 2 {
|
||||||
raylib.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, raylib.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
rl.DrawRectangle(leftButtonBound.X, leftButtonBound.Y, leftButtonBound.Width, leftButtonBound.Height, rl.GetColor(int32(style[SpinnerDefaultButtonBorderColor])))
|
||||||
raylib.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
rl.DrawRectangle(leftButtonBound.X+2, leftButtonBound.Y+2, leftButtonBound.Width-4, leftButtonBound.Height-4, rl.GetColor(int32(style[SpinnerDefaultButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, raylib.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
|
rl.DrawRectangle(rightButtonBound.X, rightButtonBound.Y, rightButtonBound.Width, rightButtonBound.Height, rl.GetColor(int32(style[SpinnerPressedButtonBorderColor])))
|
||||||
raylib.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, raylib.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
|
rl.DrawRectangle(rightButtonBound.X+2, rightButtonBound.Y+2, rightButtonBound.Width-4, rightButtonBound.Height-4, rl.GetColor(int32(style[SpinnerPressedButtonInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(raylib.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
rl.DrawText("-", leftButtonBound.X+(leftButtonBound.Width/2-(rl.MeasureText("+", int32(style[GlobalTextFontsize])))/2), leftButtonBound.Y+(leftButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerDefaultSymbolColor])))
|
||||||
raylib.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(raylib.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerPressedSymbolColor])))
|
rl.DrawText("+", rightButtonBound.X+(rightButtonBound.Width/2-(rl.MeasureText("-", int32(style[GlobalTextFontsize])))/2), rightButtonBound.Y+(rightButtonBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedSymbolColor])))
|
||||||
}
|
}
|
||||||
|
|
||||||
raylib.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, raylib.GetColor(int32(style[SpinnerLabelBorderColor])))
|
rl.DrawRectangle(labelBoxBound.X, labelBoxBound.Y, labelBoxBound.Width, labelBoxBound.Height, rl.GetColor(int32(style[SpinnerLabelBorderColor])))
|
||||||
raylib.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, raylib.GetColor(int32(style[SpinnerLabelInsideColor])))
|
rl.DrawRectangle(labelBoxBound.X+1, labelBoxBound.Y+1, labelBoxBound.Width-2, labelBoxBound.Height-2, rl.GetColor(int32(style[SpinnerLabelInsideColor])))
|
||||||
|
|
||||||
raylib.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), raylib.GetColor(int32(style[SpinnerPressedTextColor])))
|
rl.DrawText(fmt.Sprintf("%d", value), labelBoxBound.X+(labelBoxBound.Width/2-textWidth/2), labelBoxBound.Y+(labelBoxBound.Height/2-(int32(style[GlobalTextFontsize])/2)), int32(style[GlobalTextFontsize]), rl.GetColor(int32(style[SpinnerPressedTextColor])))
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -975,27 +975,27 @@ func Spinner(bounds raylib.Rectangle, value, minValue, maxValue int) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextBox - Text Box element, updates input text
|
// TextBox - Text Box element, updates input text
|
||||||
func TextBox(bounds raylib.Rectangle, text string) string {
|
func TextBox(bounds rl.Rectangle, text string) string {
|
||||||
b := bounds.ToInt32()
|
b := bounds.ToInt32()
|
||||||
state := Normal
|
state := Normal
|
||||||
|
|
||||||
mousePoint := raylib.GetMousePosition()
|
mousePoint := rl.GetMousePosition()
|
||||||
letter := int32(-1)
|
letter := int32(-1)
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
if raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
state = Focused // NOTE: PRESSED state is not used on this control
|
state = Focused // NOTE: PRESSED state is not used on this control
|
||||||
|
|
||||||
framesCounter2++
|
framesCounter2++
|
||||||
|
|
||||||
letter = raylib.GetKeyPressed()
|
letter = rl.GetKeyPressed()
|
||||||
if letter != -1 {
|
if letter != -1 {
|
||||||
if letter >= 32 && letter < 127 {
|
if letter >= 32 && letter < 127 {
|
||||||
text = fmt.Sprintf("%s%c", text, letter)
|
text = fmt.Sprintf("%s%c", text, letter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if raylib.IsKeyPressed(raylib.KeyBackspace) {
|
if rl.IsKeyPressed(rl.KeyBackspace) {
|
||||||
if len(text) > 0 {
|
if len(text) > 0 {
|
||||||
text = text[:len(text)-1]
|
text = text[:len(text)-1]
|
||||||
}
|
}
|
||||||
|
@ -1005,17 +1005,17 @@ func TextBox(bounds raylib.Rectangle, text string) string {
|
||||||
// Draw control
|
// Draw control
|
||||||
switch state {
|
switch state {
|
||||||
case Normal:
|
case Normal:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[TextboxBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[TextboxBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[TextboxBorderWidth]), b.Y+int32(style[TextboxBorderWidth]), b.Width-(int32(style[TextboxBorderWidth])*2), b.Height-(int32(style[TextboxBorderWidth])*2), raylib.GetColor(int32(style[TextboxInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[TextboxBorderWidth]), b.Y+int32(style[TextboxBorderWidth]), b.Width-(int32(style[TextboxBorderWidth])*2), b.Height-(int32(style[TextboxBorderWidth])*2), rl.GetColor(int32(style[TextboxInsideColor])))
|
||||||
raylib.DrawText(text, b.X+2, b.Y+int32(style[TextboxBorderWidth])+b.Height/2-int32(style[TextboxTextFontsize])/2, int32(style[TextboxTextFontsize]), raylib.GetColor(int32(style[TextboxTextColor])))
|
rl.DrawText(text, b.X+2, b.Y+int32(style[TextboxBorderWidth])+b.Height/2-int32(style[TextboxTextFontsize])/2, int32(style[TextboxTextFontsize]), rl.GetColor(int32(style[TextboxTextColor])))
|
||||||
break
|
break
|
||||||
case Focused:
|
case Focused:
|
||||||
raylib.DrawRectangle(b.X, b.Y, b.Width, b.Height, raylib.GetColor(int32(style[ToggleActiveBorderColor])))
|
rl.DrawRectangle(b.X, b.Y, b.Width, b.Height, rl.GetColor(int32(style[ToggleActiveBorderColor])))
|
||||||
raylib.DrawRectangle(b.X+int32(style[TextboxBorderWidth]), b.Y+int32(style[TextboxBorderWidth]), b.Width-(int32(style[TextboxBorderWidth])*2), b.Height-(int32(style[TextboxBorderWidth])*2), raylib.GetColor(int32(style[TextboxInsideColor])))
|
rl.DrawRectangle(b.X+int32(style[TextboxBorderWidth]), b.Y+int32(style[TextboxBorderWidth]), b.Width-(int32(style[TextboxBorderWidth])*2), b.Height-(int32(style[TextboxBorderWidth])*2), rl.GetColor(int32(style[TextboxInsideColor])))
|
||||||
raylib.DrawText(text, b.X+2, b.Y+int32(style[TextboxBorderWidth])+b.Height/2-int32(style[TextboxTextFontsize])/2, int32(style[TextboxTextFontsize]), raylib.GetColor(int32(style[TextboxTextColor])))
|
rl.DrawText(text, b.X+2, b.Y+int32(style[TextboxBorderWidth])+b.Height/2-int32(style[TextboxTextFontsize])/2, int32(style[TextboxTextFontsize]), rl.GetColor(int32(style[TextboxTextColor])))
|
||||||
|
|
||||||
if (framesCounter2/20)%2 == 0 && raylib.CheckCollisionPointRec(mousePoint, bounds) {
|
if (framesCounter2/20)%2 == 0 && rl.CheckCollisionPointRec(mousePoint, bounds) {
|
||||||
raylib.DrawRectangle(b.X+4+raylib.MeasureText(text, int32(style[GlobalTextFontsize])), b.Y+2, 1, b.Height-4, raylib.GetColor(int32(style[TextboxLineColor])))
|
rl.DrawRectangle(b.X+4+rl.MeasureText(text, int32(style[GlobalTextFontsize])), b.Y+2, 1, b.Height-4, rl.GetColor(int32(style[TextboxLineColor])))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case Pressed:
|
case Pressed:
|
||||||
|
@ -1039,9 +1039,9 @@ func SaveGuiStyle(fileName string) {
|
||||||
|
|
||||||
// LoadGuiStyle - Load GUI style file
|
// LoadGuiStyle - Load GUI style file
|
||||||
func LoadGuiStyle(fileName string) {
|
func LoadGuiStyle(fileName string) {
|
||||||
file, err := raylib.OpenAsset(fileName)
|
file, err := rl.OpenAsset(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
raylib.TraceLog(raylib.LogWarning, "[%s] GUI style file could not be opened", fileName)
|
rl.TraceLog(rl.LogWarning, "[%s] GUI style file could not be opened", fileName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
265
raylib/audio.c
265
raylib/audio.c
|
@ -19,7 +19,7 @@
|
||||||
* Required types and functions are defined in the same module.
|
* Required types and functions are defined in the same module.
|
||||||
*
|
*
|
||||||
* #define USE_OPENAL_BACKEND
|
* #define USE_OPENAL_BACKEND
|
||||||
* Use OpenAL Soft audio backend usage
|
* Use OpenAL Soft audio backend
|
||||||
*
|
*
|
||||||
* #define SUPPORT_FILEFORMAT_WAV
|
* #define SUPPORT_FILEFORMAT_WAV
|
||||||
* #define SUPPORT_FILEFORMAT_OGG
|
* #define SUPPORT_FILEFORMAT_OGG
|
||||||
|
@ -75,20 +75,19 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#if !defined(USE_OPENAL_BACKEND)
|
|
||||||
#define USE_MINI_AL 1 // Set to 1 to use mini_al; 0 to use OpenAL.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||||
#else
|
#else
|
||||||
#include "raylib.h"
|
#include "config.h" // Defines module configuration flags
|
||||||
|
#include "raylib.h" // Declares module functions
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(USE_OPENAL_BACKEND)
|
||||||
|
#define USE_MINI_AL 1 // Set to 1 to use mini_al; 0 to use OpenAL.
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "external/mini_al.h" // Implemented in mini_al.c. Cannot implement this here because it conflicts with Win32 APIs such as CloseWindow(), etc.
|
#include "external/mini_al.h" // Implemented in mini_al.c. Cannot implement this here because it conflicts with Win32 APIs such as CloseWindow(), etc.
|
||||||
|
|
||||||
#if !defined(USE_MINI_AL) || (USE_MINI_AL == 0)
|
#if !defined(USE_MINI_AL) || (USE_MINI_AL == 0)
|
||||||
|
@ -166,6 +165,7 @@
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MUSIC_AUDIO_OGG = 0,
|
MUSIC_AUDIO_OGG = 0,
|
||||||
MUSIC_AUDIO_FLAC,
|
MUSIC_AUDIO_FLAC,
|
||||||
|
MUSIC_AUDIO_MP3,
|
||||||
MUSIC_MODULE_XM,
|
MUSIC_MODULE_XM,
|
||||||
MUSIC_MODULE_MOD
|
MUSIC_MODULE_MOD
|
||||||
} MusicContextType;
|
} MusicContextType;
|
||||||
|
@ -179,6 +179,9 @@ typedef struct MusicData {
|
||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
drflac *ctxFlac; // FLAC audio context
|
drflac *ctxFlac; // FLAC audio context
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
drmp3 ctxMp3; // MP3 audio context
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
jar_xm_context_t *ctxXm; // XM chiptune context
|
jar_xm_context_t *ctxXm; // XM chiptune context
|
||||||
#endif
|
#endif
|
||||||
|
@ -220,6 +223,9 @@ static Wave LoadOGG(const char *fileName); // Load OGG file
|
||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
static Wave LoadFLAC(const char *fileName); // Load FLAC file
|
static Wave LoadFLAC(const char *fileName); // Load FLAC file
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
static Wave LoadMP3(const char *fileName); // Load MP3 file
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
bool IsFileExtension(const char *fileName, const char *ext); // Check file extension
|
bool IsFileExtension(const char *fileName, const char *ext); // Check file extension
|
||||||
|
@ -304,7 +310,7 @@ static mal_uint32 OnSendAudioDataToDevice(mal_device *pDevice, mal_uint32 frameC
|
||||||
(void)pDevice;
|
(void)pDevice;
|
||||||
|
|
||||||
// Mixing is basically just an accumulation. We need to initialize the output buffer to 0.
|
// Mixing is basically just an accumulation. We need to initialize the output buffer to 0.
|
||||||
memset(pFramesOut, 0, frameCount*pDevice->channels*mal_get_sample_size_in_bytes(pDevice->format));
|
memset(pFramesOut, 0, frameCount*pDevice->channels*mal_get_bytes_per_sample(pDevice->format));
|
||||||
|
|
||||||
// Using a mutex here for thread-safety which makes things not real-time. This is unlikely to be necessary for this project, but may
|
// Using a mutex here for thread-safety which makes things not real-time. This is unlikely to be necessary for this project, but may
|
||||||
// want to consider how you might want to avoid this.
|
// want to consider how you might want to avoid this.
|
||||||
|
@ -338,11 +344,7 @@ static mal_uint32 OnSendAudioDataToDevice(mal_device *pDevice, mal_uint32 frameC
|
||||||
framesToReadRightNow = sizeof(tempBuffer)/sizeof(tempBuffer[0])/DEVICE_CHANNELS;
|
framesToReadRightNow = sizeof(tempBuffer)/sizeof(tempBuffer[0])/DEVICE_CHANNELS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not looping, we need to make sure we flush the internal buffers of the DSP pipeline to ensure we get the
|
mal_uint32 framesJustRead = (mal_uint32)mal_dsp_read(&audioBuffer->dsp, framesToReadRightNow, tempBuffer, audioBuffer->dsp.pUserData);
|
||||||
// last few samples.
|
|
||||||
bool flushDSP = !audioBuffer->looping;
|
|
||||||
|
|
||||||
mal_uint32 framesJustRead = mal_dsp_read_frames_ex(&audioBuffer->dsp, framesToReadRightNow, tempBuffer, flushDSP);
|
|
||||||
if (framesJustRead > 0)
|
if (framesJustRead > 0)
|
||||||
{
|
{
|
||||||
float *framesOut = (float *)pFramesOut + (framesRead*device.channels);
|
float *framesOut = (float *)pFramesOut + (framesRead*device.channels);
|
||||||
|
@ -402,7 +404,7 @@ static mal_uint32 OnAudioBufferDSPRead(mal_dsp *pDSP, mal_uint32 frameCount, voi
|
||||||
isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0];
|
isSubBufferProcessed[0] = audioBuffer->isSubBufferProcessed[0];
|
||||||
isSubBufferProcessed[1] = audioBuffer->isSubBufferProcessed[1];
|
isSubBufferProcessed[1] = audioBuffer->isSubBufferProcessed[1];
|
||||||
|
|
||||||
mal_uint32 frameSizeInBytes = mal_get_sample_size_in_bytes(audioBuffer->dsp.config.formatIn)*audioBuffer->dsp.config.channelsIn;
|
mal_uint32 frameSizeInBytes = mal_get_bytes_per_sample(audioBuffer->dsp.formatConverterIn.config.formatIn)*audioBuffer->dsp.formatConverterIn.config.channels;
|
||||||
|
|
||||||
// Fill out every frame until we find a buffer that's marked as processed. Then fill the remainder with 0.
|
// Fill out every frame until we find a buffer that's marked as processed. Then fill the remainder with 0.
|
||||||
mal_uint32 framesRead = 0;
|
mal_uint32 framesRead = 0;
|
||||||
|
@ -648,7 +650,7 @@ void SetMasterVolume(float volume)
|
||||||
// Create a new audio buffer. Initially filled with silence
|
// Create a new audio buffer. Initially filled with silence
|
||||||
AudioBuffer *CreateAudioBuffer(mal_format format, mal_uint32 channels, mal_uint32 sampleRate, mal_uint32 bufferSizeInFrames, AudioBufferUsage usage)
|
AudioBuffer *CreateAudioBuffer(mal_format format, mal_uint32 channels, mal_uint32 sampleRate, mal_uint32 bufferSizeInFrames, AudioBufferUsage usage)
|
||||||
{
|
{
|
||||||
AudioBuffer *audioBuffer = (AudioBuffer *)calloc(sizeof(*audioBuffer) + (bufferSizeInFrames*channels*mal_get_sample_size_in_bytes(format)), 1);
|
AudioBuffer *audioBuffer = (AudioBuffer *)calloc(sizeof(*audioBuffer) + (bufferSizeInFrames*channels*mal_get_bytes_per_sample(format)), 1);
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "CreateAudioBuffer() : Failed to allocate memory for audio buffer");
|
TraceLog(LOG_ERROR, "CreateAudioBuffer() : Failed to allocate memory for audio buffer");
|
||||||
|
@ -664,10 +666,13 @@ AudioBuffer *CreateAudioBuffer(mal_format format, mal_uint32 channels, mal_uint3
|
||||||
dspConfig.channelsOut = DEVICE_CHANNELS;
|
dspConfig.channelsOut = DEVICE_CHANNELS;
|
||||||
dspConfig.sampleRateIn = sampleRate;
|
dspConfig.sampleRateIn = sampleRate;
|
||||||
dspConfig.sampleRateOut = DEVICE_SAMPLE_RATE;
|
dspConfig.sampleRateOut = DEVICE_SAMPLE_RATE;
|
||||||
mal_result resultMAL = mal_dsp_init(&dspConfig, OnAudioBufferDSPRead, audioBuffer, &audioBuffer->dsp);
|
dspConfig.onRead = OnAudioBufferDSPRead;
|
||||||
|
dspConfig.pUserData = audioBuffer;
|
||||||
|
dspConfig.allowDynamicSampleRate = MAL_TRUE; // <-- Required for pitch shifting.
|
||||||
|
mal_result resultMAL = mal_dsp_init(&dspConfig, &audioBuffer->dsp);
|
||||||
if (resultMAL != MAL_SUCCESS)
|
if (resultMAL != MAL_SUCCESS)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "LoadSoundFromWave() : Failed to create data conversion pipeline");
|
TraceLog(LOG_ERROR, "CreateAudioBuffer() : Failed to create data conversion pipeline");
|
||||||
free(audioBuffer);
|
free(audioBuffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -695,7 +700,7 @@ void DeleteAudioBuffer(AudioBuffer *audioBuffer)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "DeleteAudioBuffer() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,7 +713,7 @@ bool IsAudioBufferPlaying(AudioBuffer *audioBuffer)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "IsAudioBufferPlaying() : No audio buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +741,7 @@ void StopAudioBuffer(AudioBuffer *audioBuffer)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "StopAudioBuffer() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +760,7 @@ void PauseAudioBuffer(AudioBuffer *audioBuffer)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "PauseAudioBuffer() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,7 +772,7 @@ void ResumeAudioBuffer(AudioBuffer *audioBuffer)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "ResumeAudioBuffer() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,7 +784,7 @@ void SetAudioBufferVolume(AudioBuffer *audioBuffer, float volume)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "SetAudioBufferVolume() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -791,7 +796,7 @@ void SetAudioBufferPitch(AudioBuffer *audioBuffer, float pitch)
|
||||||
{
|
{
|
||||||
if (audioBuffer == NULL)
|
if (audioBuffer == NULL)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "PlayAudioBuffer() : No audio buffer");
|
TraceLog(LOG_ERROR, "SetAudioBufferPitch() : No audio buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,7 +804,7 @@ void SetAudioBufferPitch(AudioBuffer *audioBuffer, float pitch)
|
||||||
|
|
||||||
// Pitching is just an adjustment of the sample rate. Note that this changes the duration of the sound - higher pitches
|
// Pitching is just an adjustment of the sample rate. Note that this changes the duration of the sound - higher pitches
|
||||||
// will make the sound faster; lower pitches make it slower.
|
// will make the sound faster; lower pitches make it slower.
|
||||||
mal_uint32 newOutputSampleRate = (mal_uint32)((((float)audioBuffer->dsp.config.sampleRateOut / (float)audioBuffer->dsp.config.sampleRateIn) / pitch) * audioBuffer->dsp.config.sampleRateIn);
|
mal_uint32 newOutputSampleRate = (mal_uint32)((((float)audioBuffer->dsp.src.config.sampleRateOut / (float)audioBuffer->dsp.src.config.sampleRateIn) / pitch) * audioBuffer->dsp.src.config.sampleRateIn);
|
||||||
mal_dsp_set_output_sample_rate(&audioBuffer->dsp, newOutputSampleRate);
|
mal_dsp_set_output_sample_rate(&audioBuffer->dsp, newOutputSampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,6 +862,9 @@ Wave LoadWave(const char *fileName)
|
||||||
#endif
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (IsFileExtension(fileName, ".flac")) wave = LoadFLAC(fileName);
|
else if (IsFileExtension(fileName, ".flac")) wave = LoadFLAC(fileName);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (IsFileExtension(fileName, ".mp3")) wave = LoadMP3(fileName);
|
||||||
#endif
|
#endif
|
||||||
else TraceLog(LOG_WARNING, "[%s] Audio fileformat not supported, it can't be loaded", fileName);
|
else TraceLog(LOG_WARNING, "[%s] Audio fileformat not supported, it can't be loaded", fileName);
|
||||||
|
|
||||||
|
@ -915,13 +923,13 @@ Sound LoadSoundFromWave(Wave wave)
|
||||||
mal_format formatIn = ((wave.sampleSize == 8) ? mal_format_u8 : ((wave.sampleSize == 16) ? mal_format_s16 : mal_format_f32));
|
mal_format formatIn = ((wave.sampleSize == 8) ? mal_format_u8 : ((wave.sampleSize == 16) ? mal_format_s16 : mal_format_f32));
|
||||||
mal_uint32 frameCountIn = wave.sampleCount; // Is wave->sampleCount actually the frame count? That terminology needs to change, if so.
|
mal_uint32 frameCountIn = wave.sampleCount; // Is wave->sampleCount actually the frame count? That terminology needs to change, if so.
|
||||||
|
|
||||||
mal_uint32 frameCount = mal_convert_frames(NULL, DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, formatIn, wave.channels, wave.sampleRate, frameCountIn);
|
mal_uint32 frameCount = (mal_uint32)mal_convert_frames(NULL, DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, formatIn, wave.channels, wave.sampleRate, frameCountIn);
|
||||||
if (frameCount == 0) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Failed to get frame count for format conversion");
|
if (frameCount == 0) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Failed to get frame count for format conversion");
|
||||||
|
|
||||||
AudioBuffer* audioBuffer = CreateAudioBuffer(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, frameCount, AUDIO_BUFFER_USAGE_STATIC);
|
AudioBuffer* audioBuffer = CreateAudioBuffer(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, frameCount, AUDIO_BUFFER_USAGE_STATIC);
|
||||||
if (audioBuffer == NULL) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Failed to create audio buffer");
|
if (audioBuffer == NULL) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Failed to create audio buffer");
|
||||||
|
|
||||||
frameCount = mal_convert_frames(audioBuffer->buffer, audioBuffer->dsp.config.formatIn, audioBuffer->dsp.config.channelsIn, audioBuffer->dsp.config.sampleRateIn, wave.data, formatIn, wave.channels, wave.sampleRate, frameCountIn);
|
frameCount = (mal_uint32)mal_convert_frames(audioBuffer->buffer, audioBuffer->dsp.formatConverterIn.config.formatIn, audioBuffer->dsp.formatConverterIn.config.channels, audioBuffer->dsp.src.config.sampleRateIn, wave.data, formatIn, wave.channels, wave.sampleRate, frameCountIn);
|
||||||
if (frameCount == 0) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Format conversion failed");
|
if (frameCount == 0) TraceLog(LOG_WARNING, "LoadSoundFromWave() : Format conversion failed");
|
||||||
|
|
||||||
sound.audioBuffer = audioBuffer;
|
sound.audioBuffer = audioBuffer;
|
||||||
|
@ -1023,7 +1031,7 @@ void UpdateSound(Sound sound, const void *data, int samplesCount)
|
||||||
StopAudioBuffer(audioBuffer);
|
StopAudioBuffer(audioBuffer);
|
||||||
|
|
||||||
// TODO: May want to lock/unlock this since this data buffer is read at mixing time.
|
// TODO: May want to lock/unlock this since this data buffer is read at mixing time.
|
||||||
memcpy(audioBuffer->buffer, data, samplesCount*audioBuffer->dsp.config.channelsIn*mal_get_sample_size_in_bytes(audioBuffer->dsp.config.formatIn));
|
memcpy(audioBuffer->buffer, data, samplesCount*audioBuffer->dsp.formatConverterIn.config.channels*mal_get_bytes_per_sample(audioBuffer->dsp.formatConverterIn.config.formatIn));
|
||||||
#else
|
#else
|
||||||
ALint sampleRate, sampleSize, channels;
|
ALint sampleRate, sampleSize, channels;
|
||||||
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
|
alGetBufferi(sound.buffer, AL_FREQUENCY, &sampleRate);
|
||||||
|
@ -1049,6 +1057,89 @@ void UpdateSound(Sound sound, const void *data, int samplesCount)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export wave data to file
|
||||||
|
void ExportWave(Wave wave, const char *fileName)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
if (IsFileExtension(fileName, ".wav"))
|
||||||
|
{
|
||||||
|
// Basic WAV headers structs
|
||||||
|
typedef struct {
|
||||||
|
char chunkID[4];
|
||||||
|
int chunkSize;
|
||||||
|
char format[4];
|
||||||
|
} RiffHeader;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char subChunkID[4];
|
||||||
|
int subChunkSize;
|
||||||
|
short audioFormat;
|
||||||
|
short numChannels;
|
||||||
|
int sampleRate;
|
||||||
|
int byteRate;
|
||||||
|
short blockAlign;
|
||||||
|
short bitsPerSample;
|
||||||
|
} WaveFormat;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char subChunkID[4];
|
||||||
|
int subChunkSize;
|
||||||
|
} WaveData;
|
||||||
|
|
||||||
|
RiffHeader riffHeader;
|
||||||
|
WaveFormat waveFormat;
|
||||||
|
WaveData waveData;
|
||||||
|
|
||||||
|
// Fill structs with data
|
||||||
|
riffHeader.chunkID[0] = 'R';
|
||||||
|
riffHeader.chunkID[1] = 'I';
|
||||||
|
riffHeader.chunkID[2] = 'F';
|
||||||
|
riffHeader.chunkID[3] = 'F';
|
||||||
|
riffHeader.chunkSize = 44 - 4 + wave.sampleCount*wave.sampleSize/8;
|
||||||
|
riffHeader.format[0] = 'W';
|
||||||
|
riffHeader.format[1] = 'A';
|
||||||
|
riffHeader.format[2] = 'V';
|
||||||
|
riffHeader.format[3] = 'E';
|
||||||
|
|
||||||
|
waveFormat.subChunkID[0] = 'f';
|
||||||
|
waveFormat.subChunkID[1] = 'm';
|
||||||
|
waveFormat.subChunkID[2] = 't';
|
||||||
|
waveFormat.subChunkID[3] = ' ';
|
||||||
|
waveFormat.subChunkSize = 16;
|
||||||
|
waveFormat.audioFormat = 1;
|
||||||
|
waveFormat.numChannels = wave.channels;
|
||||||
|
waveFormat.sampleRate = wave.sampleRate;
|
||||||
|
waveFormat.byteRate = wave.sampleRate*wave.sampleSize/8;
|
||||||
|
waveFormat.blockAlign = wave.sampleSize/8;
|
||||||
|
waveFormat.bitsPerSample = wave.sampleSize;
|
||||||
|
|
||||||
|
waveData.subChunkID[0] = 'd';
|
||||||
|
waveData.subChunkID[1] = 'a';
|
||||||
|
waveData.subChunkID[2] = 't';
|
||||||
|
waveData.subChunkID[3] = 'a';
|
||||||
|
waveData.subChunkSize = wave.sampleCount*wave.channels*wave.sampleSize/8;
|
||||||
|
|
||||||
|
FILE *wavFile = fopen(fileName, "wb");
|
||||||
|
|
||||||
|
if (wavFile == NULL) return;
|
||||||
|
|
||||||
|
fwrite(&riffHeader, 1, sizeof(RiffHeader), wavFile);
|
||||||
|
fwrite(&waveFormat, 1, sizeof(WaveFormat), wavFile);
|
||||||
|
fwrite(&waveData, 1, sizeof(WaveData), wavFile);
|
||||||
|
|
||||||
|
fwrite(wave.data, 1, wave.sampleCount*wave.channels*wave.sampleSize/8, wavFile);
|
||||||
|
|
||||||
|
fclose(wavFile);
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
else if (IsFileExtension(fileName, ".raw")) { } // TODO: Support additional file formats to export wave sample data
|
||||||
|
|
||||||
|
if (success) TraceLog(LOG_INFO, "Wave exported successfully: %s", fileName);
|
||||||
|
else TraceLog(LOG_WARNING, "Wave could not be exported.");
|
||||||
|
}
|
||||||
|
|
||||||
// Play a sound
|
// Play a sound
|
||||||
void PlaySound(Sound sound)
|
void PlaySound(Sound sound)
|
||||||
{
|
{
|
||||||
|
@ -1153,7 +1244,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
|
||||||
|
|
||||||
mal_uint32 frameCountIn = wave->sampleCount; // Is wave->sampleCount actually the frame count? That terminology needs to change, if so.
|
mal_uint32 frameCountIn = wave->sampleCount; // Is wave->sampleCount actually the frame count? That terminology needs to change, if so.
|
||||||
|
|
||||||
mal_uint32 frameCount = mal_convert_frames(NULL, formatOut, channels, sampleRate, NULL, formatIn, wave->channels, wave->sampleRate, frameCountIn);
|
mal_uint32 frameCount = (mal_uint32)mal_convert_frames(NULL, formatOut, channels, sampleRate, NULL, formatIn, wave->channels, wave->sampleRate, frameCountIn);
|
||||||
if (frameCount == 0)
|
if (frameCount == 0)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "WaveFormat() : Failed to get frame count for format conversion.");
|
TraceLog(LOG_ERROR, "WaveFormat() : Failed to get frame count for format conversion.");
|
||||||
|
@ -1162,7 +1253,7 @@ void WaveFormat(Wave *wave, int sampleRate, int sampleSize, int channels)
|
||||||
|
|
||||||
void *data = malloc(frameCount*channels*(sampleSize/8));
|
void *data = malloc(frameCount*channels*(sampleSize/8));
|
||||||
|
|
||||||
frameCount = mal_convert_frames(data, formatOut, channels, sampleRate, wave->data, formatIn, wave->channels, wave->sampleRate, frameCountIn);
|
frameCount = (mal_uint32)mal_convert_frames(data, formatOut, channels, sampleRate, wave->data, formatIn, wave->channels, wave->sampleRate, frameCountIn);
|
||||||
if (frameCount == 0)
|
if (frameCount == 0)
|
||||||
{
|
{
|
||||||
TraceLog(LOG_ERROR, "WaveFormat() : Format conversion failed.");
|
TraceLog(LOG_ERROR, "WaveFormat() : Format conversion failed.");
|
||||||
|
@ -1284,7 +1375,7 @@ Wave WaveCopy(Wave wave)
|
||||||
void WaveCrop(Wave *wave, int initSample, int finalSample)
|
void WaveCrop(Wave *wave, int initSample, int finalSample)
|
||||||
{
|
{
|
||||||
if ((initSample >= 0) && (initSample < finalSample) &&
|
if ((initSample >= 0) && (initSample < finalSample) &&
|
||||||
(finalSample > 0) && (finalSample < wave->sampleCount))
|
(finalSample > 0) && ((unsigned int)finalSample < wave->sampleCount))
|
||||||
{
|
{
|
||||||
int sampleCount = finalSample - initSample;
|
int sampleCount = finalSample - initSample;
|
||||||
|
|
||||||
|
@ -1304,9 +1395,9 @@ float *GetWaveData(Wave wave)
|
||||||
{
|
{
|
||||||
float *samples = (float *)malloc(wave.sampleCount*wave.channels*sizeof(float));
|
float *samples = (float *)malloc(wave.sampleCount*wave.channels*sizeof(float));
|
||||||
|
|
||||||
for (int i = 0; i < wave.sampleCount; i++)
|
for (unsigned int i = 0; i < wave.sampleCount; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < wave.channels; j++)
|
for (unsigned int j = 0; j < wave.channels; j++)
|
||||||
{
|
{
|
||||||
if (wave.sampleSize == 8) samples[wave.channels*i + j] = (float)(((unsigned char *)wave.data)[wave.channels*i + j] - 127)/256.0f;
|
if (wave.sampleSize == 8) samples[wave.channels*i + j] = (float)(((unsigned char *)wave.data)[wave.channels*i + j] - 127)/256.0f;
|
||||||
else if (wave.sampleSize == 16) samples[wave.channels*i + j] = (float)((short *)wave.data)[wave.channels*i + j]/32767.0f;
|
else if (wave.sampleSize == 16) samples[wave.channels*i + j] = (float)((short *)wave.data)[wave.channels*i + j]/32767.0f;
|
||||||
|
@ -1325,13 +1416,14 @@ float *GetWaveData(Wave wave)
|
||||||
Music LoadMusicStream(const char *fileName)
|
Music LoadMusicStream(const char *fileName)
|
||||||
{
|
{
|
||||||
Music music = (MusicData *)malloc(sizeof(MusicData));
|
Music music = (MusicData *)malloc(sizeof(MusicData));
|
||||||
|
bool musicLoaded = true;
|
||||||
|
|
||||||
if (IsFileExtension(fileName, ".ogg"))
|
if (IsFileExtension(fileName, ".ogg"))
|
||||||
{
|
{
|
||||||
// Open ogg audio stream
|
// Open ogg audio stream
|
||||||
music->ctxOgg = stb_vorbis_open_filename(fileName, NULL, NULL);
|
music->ctxOgg = stb_vorbis_open_filename(fileName, NULL, NULL);
|
||||||
|
|
||||||
if (music->ctxOgg == NULL) TraceLog(LOG_WARNING, "[%s] OGG audio file could not be opened", fileName);
|
if (music->ctxOgg == NULL) musicLoaded = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stb_vorbis_info info = stb_vorbis_get_info(music->ctxOgg); // Get Ogg file info
|
stb_vorbis_info info = stb_vorbis_get_info(music->ctxOgg); // Get Ogg file info
|
||||||
|
@ -1343,7 +1435,7 @@ Music LoadMusicStream(const char *fileName)
|
||||||
music->ctxType = MUSIC_AUDIO_OGG;
|
music->ctxType = MUSIC_AUDIO_OGG;
|
||||||
music->loopCount = -1; // Infinite loop by default
|
music->loopCount = -1; // Infinite loop by default
|
||||||
|
|
||||||
TraceLog(LOG_DEBUG, "[%s] FLAC total samples: %i", fileName, music->totalSamples);
|
TraceLog(LOG_DEBUG, "[%s] OGG total samples: %i", fileName, music->totalSamples);
|
||||||
TraceLog(LOG_DEBUG, "[%s] OGG sample rate: %i", fileName, info.sample_rate);
|
TraceLog(LOG_DEBUG, "[%s] OGG sample rate: %i", fileName, info.sample_rate);
|
||||||
TraceLog(LOG_DEBUG, "[%s] OGG channels: %i", fileName, info.channels);
|
TraceLog(LOG_DEBUG, "[%s] OGG channels: %i", fileName, info.channels);
|
||||||
TraceLog(LOG_DEBUG, "[%s] OGG memory required: %i", fileName, info.temp_memory_required);
|
TraceLog(LOG_DEBUG, "[%s] OGG memory required: %i", fileName, info.temp_memory_required);
|
||||||
|
@ -1354,7 +1446,7 @@ Music LoadMusicStream(const char *fileName)
|
||||||
{
|
{
|
||||||
music->ctxFlac = drflac_open_file(fileName);
|
music->ctxFlac = drflac_open_file(fileName);
|
||||||
|
|
||||||
if (music->ctxFlac == NULL) TraceLog(LOG_WARNING, "[%s] FLAC audio file could not be opened", fileName);
|
if (music->ctxFlac == NULL) musicLoaded = false;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
music->stream = InitAudioStream(music->ctxFlac->sampleRate, music->ctxFlac->bitsPerSample, music->ctxFlac->channels);
|
music->stream = InitAudioStream(music->ctxFlac->sampleRate, music->ctxFlac->bitsPerSample, music->ctxFlac->channels);
|
||||||
|
@ -1370,6 +1462,27 @@ Music LoadMusicStream(const char *fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (IsFileExtension(fileName, ".mp3"))
|
||||||
|
{
|
||||||
|
drmp3_init_file(&music->ctxMp3, fileName, NULL);
|
||||||
|
|
||||||
|
if (music->ctxMp3.framesRemaining <= 0) musicLoaded = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
music->stream = InitAudioStream(music->ctxMp3.sampleRate, 16, music->ctxMp3.channels);
|
||||||
|
music->totalSamples = (unsigned int)music->ctxMp3.framesRemaining*music->ctxMp3.channels;
|
||||||
|
music->samplesLeft = music->totalSamples;
|
||||||
|
music->ctxType = MUSIC_AUDIO_MP3;
|
||||||
|
music->loopCount = -1; // Infinite loop by default
|
||||||
|
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 total samples: %i", fileName, music->totalSamples);
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 sample rate: %i", fileName, music->ctxMp3.sampleRate);
|
||||||
|
//TraceLog(LOG_DEBUG, "[%s] MP3 bits per sample: %i", fileName, music->ctxMp3.bitsPerSample);
|
||||||
|
TraceLog(LOG_DEBUG, "[%s] MP3 channels: %i", fileName, music->ctxMp3.channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (IsFileExtension(fileName, ".xm"))
|
else if (IsFileExtension(fileName, ".xm"))
|
||||||
{
|
{
|
||||||
|
@ -1389,7 +1502,7 @@ Music LoadMusicStream(const char *fileName)
|
||||||
TraceLog(LOG_DEBUG, "[%s] XM number of samples: %i", fileName, music->totalSamples);
|
TraceLog(LOG_DEBUG, "[%s] XM number of samples: %i", fileName, music->totalSamples);
|
||||||
TraceLog(LOG_DEBUG, "[%s] XM track length: %11.6f sec", fileName, (float)music->totalSamples/48000.0f);
|
TraceLog(LOG_DEBUG, "[%s] XM track length: %11.6f sec", fileName, (float)music->totalSamples/48000.0f);
|
||||||
}
|
}
|
||||||
else TraceLog(LOG_WARNING, "[%s] XM file could not be opened", fileName);
|
else musicLoaded = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_MOD)
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
|
@ -1408,10 +1521,32 @@ Music LoadMusicStream(const char *fileName)
|
||||||
TraceLog(LOG_DEBUG, "[%s] MOD number of samples: %i", fileName, music->samplesLeft);
|
TraceLog(LOG_DEBUG, "[%s] MOD number of samples: %i", fileName, music->samplesLeft);
|
||||||
TraceLog(LOG_DEBUG, "[%s] MOD track length: %11.6f sec", fileName, (float)music->totalSamples/48000.0f);
|
TraceLog(LOG_DEBUG, "[%s] MOD track length: %11.6f sec", fileName, (float)music->totalSamples/48000.0f);
|
||||||
}
|
}
|
||||||
else TraceLog(LOG_WARNING, "[%s] MOD file could not be opened", fileName);
|
else musicLoaded = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else TraceLog(LOG_WARNING, "[%s] Audio fileformat not supported, it can't be loaded", fileName);
|
else musicLoaded = false;
|
||||||
|
|
||||||
|
if (!musicLoaded)
|
||||||
|
{
|
||||||
|
if (music->ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close(music->ctxOgg);
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
|
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (music->ctxType == MUSIC_AUDIO_MP3) drmp3_uninit(&music->ctxMp3);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
|
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
|
else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free(music);
|
||||||
|
music = NULL;
|
||||||
|
|
||||||
|
TraceLog(LOG_WARNING, "[%s] Music file could not be opened", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
|
@ -1425,6 +1560,9 @@ void UnloadMusicStream(Music music)
|
||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
else if (music->ctxType == MUSIC_AUDIO_MP3) drmp3_uninit(&music->ctxMp3);
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1516,7 +1654,10 @@ void StopMusicStream(Music music)
|
||||||
{
|
{
|
||||||
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
|
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
|
||||||
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
case MUSIC_MODULE_FLAC: /* TODO: Restart FLAC context */ break;
|
case MUSIC_AUDIO_FLAC: /* TODO: Restart FLAC context */ break;
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
case MUSIC_AUDIO_MP3: /* TODO: Restart MP3 context */ break;
|
||||||
#endif
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: /* TODO: Restart XM context */ break;
|
case MUSIC_MODULE_XM: /* TODO: Restart XM context */ break;
|
||||||
|
@ -1566,6 +1707,14 @@ void UpdateMusicStream(Music music)
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
case MUSIC_AUDIO_MP3:
|
||||||
|
{
|
||||||
|
// NOTE: Returns the number of samples to process
|
||||||
|
unsigned int numSamplesMp3 = (unsigned int)drmp3_read_f32(&music->ctxMp3, samplesCount*music->stream.channels, (float *)pcm);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1650,6 +1799,13 @@ void UpdateMusicStream(Music music)
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
case MUSIC_AUDIO_MP3:
|
||||||
|
{
|
||||||
|
// NOTE: Returns the number of samples to process
|
||||||
|
unsigned int numSamplesMp3 = (unsigned int)drmp3_read_f32(&music->ctxMp3, samplesCount*music->stream.channels, (float *)pcm);
|
||||||
|
} break;
|
||||||
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_XM)
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2239,6 +2395,33 @@ static Wave LoadFLAC(const char *fileName)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MP3)
|
||||||
|
// Load MP3 file into Wave structure
|
||||||
|
// NOTE: Using dr_mp3 library
|
||||||
|
static Wave LoadMP3(const char *fileName)
|
||||||
|
{
|
||||||
|
Wave wave;
|
||||||
|
|
||||||
|
// Decode an entire MP3 file in one go
|
||||||
|
uint64_t totalSampleCount;
|
||||||
|
drmp3_config *config;
|
||||||
|
wave.data = drmp3_open_and_decode_file_f32(fileName, config, &totalSampleCount);
|
||||||
|
|
||||||
|
wave.channels = config->outputChannels;
|
||||||
|
wave.sampleRate = config->outputSampleRate;
|
||||||
|
wave.sampleCount = (int)totalSampleCount/wave.channels;
|
||||||
|
wave.sampleSize = 16;
|
||||||
|
|
||||||
|
// NOTE: Only support up to 2 channels (mono, stereo)
|
||||||
|
if (wave.channels > 2) TraceLog(LOG_WARNING, "[%s] MP3 channels number (%i) not supported", fileName, wave.channels);
|
||||||
|
|
||||||
|
if (wave.data == NULL) TraceLog(LOG_WARNING, "[%s] MP3 data could not be loaded", fileName);
|
||||||
|
else TraceLog(LOG_INFO, "[%s] MP3 file loaded successfully (%i Hz, %i bit, %s)", fileName, wave.sampleRate, wave.sampleSize, (wave.channels == 1) ? "Mono" : "Stereo");
|
||||||
|
|
||||||
|
return wave;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Some required functions for audio standalone module version
|
// Some required functions for audio standalone module version
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
// Check file extension
|
// Check file extension
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !noaudio
|
// +build !noaudio
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "external/stb_vorbis.c"
|
#include "external/stb_vorbis.c"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build !android
|
// +build !android
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
|
@ -244,8 +244,8 @@ void SetCameraMode(Camera camera, int mode)
|
||||||
distance.y = sqrtf(dx*dx + dy*dy);
|
distance.y = sqrtf(dx*dx + dy*dy);
|
||||||
|
|
||||||
// Camera angle calculation
|
// Camera angle calculation
|
||||||
cameraAngle.x = asinf(fabsf(dx)/distance.x); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
cameraAngle.x = asinf( (float)fabs(dx)/distance.x); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||||
cameraAngle.y = -asinf(fabsf(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
cameraAngle.y = -asinf( (float)fabs(dy)/distance.y); // Camera angle in plane XY (0 aligned with X, move positive CW)
|
||||||
|
|
||||||
// NOTE: Just testing what cameraAngle means
|
// NOTE: Just testing what cameraAngle means
|
||||||
//cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
//cameraAngle.x = 0.0f*DEG2RAD; // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result
|
#cgo CFLAGS: -std=gnu99 -Wno-missing-braces -Wno-unused-result -Wno-stringop-overflow
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build android
|
// +build android
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "external/android/native_app_glue/android_native_app_glue.c"
|
#include "external/android/native_app_glue/android_native_app_glue.c"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build darwin
|
// +build darwin
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "external/glfw/src/context.c"
|
#include "external/glfw/src/context.c"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux,!arm,!arm64
|
// +build linux,!arm,!arm64
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "external/glfw/src/context.c"
|
#include "external/glfw/src/context.c"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build linux,arm,!android
|
// +build linux,arm,!android
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo linux,arm LDFLAGS: -L/opt/vc/lib -L/opt/vc/lib64 -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -lvcos -lvchiq_arm -ldl
|
#cgo linux,arm LDFLAGS: -L/opt/vc/lib -L/opt/vc/lib64 -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -lvcos -lvchiq_arm -ldl
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "external/glfw/src/context.c"
|
#include "external/glfw/src/context.c"
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
#define RAYLIB_VERSION "2.0-dev"
|
#define RAYLIB_VERSION "2.1-dev"
|
||||||
|
|
||||||
// Edit to control what features Makefile'd raylib is compiled with
|
// Edit to control what features Makefile'd raylib is compiled with
|
||||||
#if defined(RAYLIB_CMAKE)
|
#if defined(RAYLIB_CMAKE)
|
||||||
|
@ -86,10 +86,12 @@
|
||||||
//#define SUPPORT_FILEFORMAT_PKM 1
|
//#define SUPPORT_FILEFORMAT_PKM 1
|
||||||
//#define SUPPORT_FILEFORMAT_PVR 1
|
//#define SUPPORT_FILEFORMAT_PVR 1
|
||||||
|
|
||||||
|
// Support image export functionality (.png, .bmp, .tga, .jpg)
|
||||||
|
#define SUPPORT_IMAGE_EXPORT 1
|
||||||
// Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop...
|
// Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop...
|
||||||
// If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT()
|
// If not defined only three image editing functions supported: ImageFormat(), ImageAlphaMask(), ImageToPOT()
|
||||||
#define SUPPORT_IMAGE_MANIPULATION 1
|
#define SUPPORT_IMAGE_MANIPULATION 1
|
||||||
// Support proedural image generation functionality (gradient, spot, perlin-noise, cellular)
|
// Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)
|
||||||
#define SUPPORT_IMAGE_GENERATION 1
|
#define SUPPORT_IMAGE_GENERATION 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@
|
||||||
#define SUPPORT_FILEFORMAT_XM 1
|
#define SUPPORT_FILEFORMAT_XM 1
|
||||||
#define SUPPORT_FILEFORMAT_MOD 1
|
#define SUPPORT_FILEFORMAT_MOD 1
|
||||||
//#define SUPPORT_FILEFORMAT_FLAC 1
|
//#define SUPPORT_FILEFORMAT_FLAC 1
|
||||||
//#define SUPPORT_FILEFORMAT_MP3 1
|
#define SUPPORT_FILEFORMAT_MP3 1
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
@ -133,10 +135,6 @@
|
||||||
// Show TraceLog() output messages
|
// Show TraceLog() output messages
|
||||||
// NOTE: By default LOG_DEBUG traces not shown
|
// NOTE: By default LOG_DEBUG traces not shown
|
||||||
#define SUPPORT_TRACELOG 1
|
#define SUPPORT_TRACELOG 1
|
||||||
// Support saving image data fileformats
|
|
||||||
// NOTE: Requires stb_image_write library
|
|
||||||
#define SUPPORT_SAVE_PNG 1
|
|
||||||
//#define SUPPORT_SAVE_BMP 1
|
|
||||||
|
|
||||||
|
|
||||||
#endif //defined(RAYLIB_CMAKE)
|
#endif //defined(RAYLIB_CMAKE)
|
||||||
|
|
534
raylib/core.c
534
raylib/core.c
|
@ -5,7 +5,7 @@
|
||||||
* PLATFORMS SUPPORTED:
|
* PLATFORMS SUPPORTED:
|
||||||
* - PLATFORM_DESKTOP: Windows (Win32, Win64)
|
* - PLATFORM_DESKTOP: Windows (Win32, Win64)
|
||||||
* - PLATFORM_DESKTOP: Linux (X11 desktop mode)
|
* - PLATFORM_DESKTOP: Linux (X11 desktop mode)
|
||||||
* - PLATFORM_DESKTOP: FreeBSD (X11 desktop)
|
* - PLATFORM_DESKTOP: FreeBSD, OpenBSD, NetBSD, DragonFly (X11 desktop)
|
||||||
* - PLATFORM_DESKTOP: OSX/macOS
|
* - PLATFORM_DESKTOP: OSX/macOS
|
||||||
* - PLATFORM_ANDROID: Android 4.0 (ARM, ARM64)
|
* - PLATFORM_ANDROID: Android 4.0 (ARM, ARM64)
|
||||||
* - PLATFORM_RPI: Raspberry Pi 0,1,2,3 (Raspbian)
|
* - PLATFORM_RPI: Raspberry Pi 0,1,2,3 (Raspbian)
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
* CONFIGURATION:
|
* CONFIGURATION:
|
||||||
*
|
*
|
||||||
* #define PLATFORM_DESKTOP
|
* #define PLATFORM_DESKTOP
|
||||||
* Windowing and input system configured for desktop platforms: Windows, Linux, OSX, FreeBSD
|
* Windowing and input system configured for desktop platforms: Windows, Linux, OSX, FreeBSD, OpenBSD, NetBSD, DragonFly
|
||||||
* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for mirror rendering - View [rlgl] module to enable it
|
* NOTE: Oculus Rift CV1 requires PLATFORM_DESKTOP for mirror rendering - View [rlgl] module to enable it
|
||||||
*
|
*
|
||||||
* #define PLATFORM_ANDROID
|
* #define PLATFORM_ANDROID
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
|
* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD)
|
* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD, OpenBSD, NetBSD, DragonFly)
|
||||||
* raymath - 3D math functionality (Vector2, Vector3, Matrix, Quaternion)
|
* raymath - 3D math functionality (Vector2, Vector3, Matrix, Quaternion)
|
||||||
* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person)
|
* camera - Multiple 3D camera modes (free, orbital, 1st person, 3rd person)
|
||||||
* gestures - Gestures system for touch-ready devices (or simulated from mouse inputs)
|
* gestures - Gestures system for touch-ready devices (or simulated from mouse inputs)
|
||||||
|
@ -95,7 +95,9 @@
|
||||||
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation of raymath here
|
#define RAYMATH_IMPLEMENTATION // Define external out-of-line implementation of raymath here
|
||||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||||
|
|
||||||
|
#define RLGL_IMPLEMENTATION
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 3.3+ or ES2
|
||||||
|
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
|
|
||||||
#if defined(SUPPORT_GESTURES_SYSTEM)
|
#if defined(SUPPORT_GESTURES_SYSTEM)
|
||||||
|
@ -121,6 +123,7 @@
|
||||||
#include <string.h> // Required for: strrchr(), strcmp()
|
#include <string.h> // Required for: strrchr(), strcmp()
|
||||||
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
||||||
#include <ctype.h> // Required for: tolower() [Used in IsFileExtension()]
|
#include <ctype.h> // Required for: tolower() [Used in IsFileExtension()]
|
||||||
|
#include <dirent.h> // Required for: DIR, opendir(), closedir() [Used in GetDirectoryFiles()]
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <direct.h> // Required for: _getch(), _chdir()
|
#include <direct.h> // Required for: _getch(), _chdir()
|
||||||
|
@ -132,17 +135,25 @@
|
||||||
#define CHDIR chdir
|
#define CHDIR chdir
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__) || defined(PLATFORM_WEB)
|
|
||||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
#include <unistd.h> // Required for: usleep()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
#define GLFW_INCLUDE_ES2
|
||||||
|
#endif
|
||||||
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
||||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||||
// NOTE: GLFW3 already includes gl.h (OpenGL) headers
|
// NOTE: GLFW3 already includes gl.h (OpenGL) headers
|
||||||
|
|
||||||
|
// Support retrieving native window handlers
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
|
#include <GLFW/glfw3native.h> // WARNING: It requires customization to avoid windows.h inclusion!
|
||||||
|
#elif defined(__linux__)
|
||||||
|
//#define GLFW_EXPOSE_NATIVE_X11 // WARNING: Exposing Xlib.h > X.h results in dup symbols for Font type
|
||||||
|
//GLFW_EXPOSE_NATIVE_WAYLAND
|
||||||
|
//GLFW_EXPOSE_NATIVE_MIR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
||||||
// NOTE: Those functions require linking with winmm library
|
// NOTE: Those functions require linking with winmm library
|
||||||
unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
|
unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
|
||||||
|
@ -150,6 +161,16 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(__linux__) || defined(PLATFORM_WEB)
|
||||||
|
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include <unistd.h> // Required for: usleep()
|
||||||
|
#include <objc/message.h> // Required for: objc_msgsend(), sel_registerName()
|
||||||
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||||
|
#define GLFW_EXPOSE_NATIVE_NSGL
|
||||||
|
#include <GLFW/glfw3native.h> // Required for: glfwGetCocoaWindow(), glfwGetNSGLContext()
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
|
//#include <android/sensor.h> // Android sensors functions (accelerometer, gyroscope, light...)
|
||||||
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
||||||
|
@ -220,14 +241,46 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Global Variables Definition
|
// Global Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Window/Graphics related variables
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
static GLFWwindow *window; // Native window (graphic device)
|
static GLFWwindow *window; // Native window (graphic device)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool windowReady = false; // Check if window has been initialized successfully
|
static bool windowReady = false; // Check if window has been initialized successfully
|
||||||
static bool windowMinimized = false; // Check if window has been minimized
|
static bool windowMinimized = false; // Check if window has been minimized
|
||||||
static const char *windowTitle = NULL; // Window text title...
|
static const char *windowTitle = NULL; // Window text title...
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
static int windowNeedsUpdating = 2; // Times the Cocoa window needs to be updated initially
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static unsigned int displayWidth, displayHeight;// Display width and height (monitor, device-screen, LCD, ...)
|
||||||
|
static int screenWidth, screenHeight; // Screen width and height (used render area)
|
||||||
|
static int renderWidth, renderHeight; // Framebuffer width and height (render area, including black bars if required)
|
||||||
|
static int renderOffsetX = 0; // Offset X from render area (must be divided by 2)
|
||||||
|
static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2)
|
||||||
|
static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
|
||||||
|
static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size)
|
||||||
|
|
||||||
|
#if defined(PLATFORM_RPI)
|
||||||
|
static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
|
||||||
|
static EGLDisplay display; // Native display device (physical screen connection)
|
||||||
|
static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
|
||||||
|
static EGLContext context; // Graphic context, mode in which drawing can be done
|
||||||
|
static EGLConfig config; // Graphic config
|
||||||
|
static uint64_t baseTime; // Base time measure for hi-res timer
|
||||||
|
static bool windowShouldClose = false; // Flag to set window for closing
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_UWP)
|
||||||
|
extern EGLNativeWindowType uwpWindow; // Native EGL window handler for UWP (external, defined in UWP App)
|
||||||
|
#endif
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
static struct android_app *androidApp; // Android activity
|
static struct android_app *androidApp; // Android activity
|
||||||
static struct android_poll_source *source; // Android events polling source
|
static struct android_poll_source *source; // Android events polling source
|
||||||
|
@ -238,104 +291,86 @@ static bool appEnabled = true; // Used to detec if app is activ
|
||||||
static bool contextRebindRequired = false; // Used to know context rebind required
|
static bool contextRebindRequired = false; // Used to know context rebind required
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_RPI)
|
// Inputs related variables
|
||||||
static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
|
//-----------------------------------------------------------------------------------
|
||||||
|
// Keyboard states
|
||||||
|
static char previousKeyState[512] = { 0 }; // Registers previous frame key state
|
||||||
|
static char currentKeyState[512] = { 0 }; // Registers current frame key state
|
||||||
|
static int lastKeyPressed = -1; // Register last key pressed
|
||||||
|
static int exitKey = KEY_ESCAPE; // Default exit key (ESC)
|
||||||
|
|
||||||
// Keyboard input variables
|
#if defined(PLATFORM_RPI)
|
||||||
// NOTE: For keyboard we will use the standard input (but reconfigured...)
|
// NOTE: For keyboard we will use the standard input (but reconfigured...)
|
||||||
static struct termios defaultKeyboardSettings; // Used to store default keyboard settings
|
static struct termios defaultKeyboardSettings; // Used to store default keyboard settings
|
||||||
static int defaultKeyboardMode; // Used to store default keyboard mode
|
static int defaultKeyboardMode; // Used to store default keyboard mode
|
||||||
|
#endif
|
||||||
|
|
||||||
// Mouse input variables
|
// Mouse states
|
||||||
|
static Vector2 mousePosition; // Mouse position on screen
|
||||||
|
static float mouseScale = 1.0f; // Mouse default scale
|
||||||
|
static bool cursorHidden = false; // Track if cursor is hidden
|
||||||
|
static bool cursorOnScreen = false; // Tracks if cursor is inside client area
|
||||||
|
static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP)
|
||||||
|
static char previousMouseState[3] = { 0 }; // Registers previous mouse button state
|
||||||
|
static char currentMouseState[3] = { 0 }; // Registers current mouse button state
|
||||||
|
static int previousMouseWheelY = 0; // Registers previous mouse wheel variation
|
||||||
|
static int currentMouseWheelY = 0; // Registers current mouse wheel variation
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_RPI)
|
||||||
static int mouseStream = -1; // Mouse device file descriptor
|
static int mouseStream = -1; // Mouse device file descriptor
|
||||||
static bool mouseReady = false; // Flag to know if mouse is ready
|
static bool mouseReady = false; // Flag to know if mouse is ready
|
||||||
static pthread_t mouseThreadId; // Mouse reading thread id
|
static pthread_t mouseThreadId; // Mouse reading thread id
|
||||||
|
|
||||||
// Touch input variables
|
|
||||||
static int touchStream = -1; // Touch device file descriptor
|
static int touchStream = -1; // Touch device file descriptor
|
||||||
static bool touchReady = false; // Flag to know if touch interface is ready
|
static bool touchReady = false; // Flag to know if touch interface is ready
|
||||||
static pthread_t touchThreadId; // Touch reading thread id
|
static pthread_t touchThreadId; // Touch reading thread id
|
||||||
|
#endif
|
||||||
// Gamepad input variables
|
#if defined(PLATFORM_WEB)
|
||||||
static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor
|
static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click
|
||||||
static pthread_t gamepadThreadId; // Gamepad reading thread id
|
|
||||||
static char gamepadName[64]; // Gamepad name holder
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
|
// Gamepads states
|
||||||
static EGLDisplay display; // Native display device (physical screen connection)
|
static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed
|
||||||
static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
|
static int gamepadAxisCount = 0; // Register number of available gamepad axis
|
||||||
static EGLContext context; // Graphic context, mode in which drawing can be done
|
|
||||||
static EGLConfig config; // Graphic config
|
|
||||||
static uint64_t baseTime; // Base time measure for hi-res timer
|
|
||||||
static bool windowShouldClose = false; // Flag to set window for closing
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PLATFORM_UWP)
|
|
||||||
extern EGLNativeWindowType uwpWindow; // Native EGL window handler for UWP (external, defined in UWP App)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Screen related variables
|
|
||||||
static unsigned int displayWidth, displayHeight; // Display width and height (monitor, device-screen, LCD, ...)
|
|
||||||
static int screenWidth, screenHeight; // Screen width and height (used render area)
|
|
||||||
static int renderWidth, renderHeight; // Framebuffer width and height (render area, including black bars if required)
|
|
||||||
static int renderOffsetX = 0; // Offset X from render area (must be divided by 2)
|
|
||||||
static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2)
|
|
||||||
static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP)
|
|
||||||
static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size)
|
|
||||||
|
|
||||||
static bool cursorHidden = false; // Track if cursor is hidden
|
|
||||||
static bool cursorOnScreen = false; // Tracks if cursor is inside client area
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP)
|
||||||
// Register mouse states
|
|
||||||
static char previousMouseState[3] = { 0 }; // Registers previous mouse button state
|
|
||||||
static char currentMouseState[3] = { 0 }; // Registers current mouse button state
|
|
||||||
static int previousMouseWheelY = 0; // Registers previous mouse wheel variation
|
|
||||||
static int currentMouseWheelY = 0; // Registers current mouse wheel variation
|
|
||||||
|
|
||||||
// Register gamepads states
|
|
||||||
static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready
|
static bool gamepadReady[MAX_GAMEPADS] = { false }; // Flag to know if gamepad is ready
|
||||||
static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
|
static float gamepadAxisState[MAX_GAMEPADS][MAX_GAMEPAD_AXIS]; // Gamepad axis state
|
||||||
static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
static char previousGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Previous gamepad buttons state
|
||||||
static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
|
static char currentGamepadState[MAX_GAMEPADS][MAX_GAMEPAD_BUTTONS]; // Current gamepad buttons state
|
||||||
|
|
||||||
// Keyboard configuration
|
|
||||||
static int exitKey = KEY_ESCAPE; // Default exit key (ESC)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Register keyboard states
|
#if defined(PLATFORM_RPI)
|
||||||
static char previousKeyState[512] = { 0 }; // Registers previous frame key state
|
static int gamepadStream[MAX_GAMEPADS] = { -1 };// Gamepad device file descriptor
|
||||||
static char currentKeyState[512] = { 0 }; // Registers current frame key state
|
static pthread_t gamepadThreadId; // Gamepad reading thread id
|
||||||
|
static char gamepadName[64]; // Gamepad name holder
|
||||||
static int lastKeyPressed = -1; // Register last key pressed
|
|
||||||
static int lastGamepadButtonPressed = -1; // Register last gamepad button pressed
|
|
||||||
static int gamepadAxisCount = 0; // Register number of available gamepad axis
|
|
||||||
|
|
||||||
static Vector2 mousePosition; // Mouse position on screen
|
|
||||||
static float mouseScale = 1.0f; // Mouse default scale
|
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
|
||||||
static bool toggleCursorLock = false; // Ask for cursor pointer lock on next click
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Vector2 touchPosition[MAX_TOUCH_POINTS]; // Touch position on screen
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
|
||||||
static char **dropFilesPath; // Store dropped files paths as strings
|
|
||||||
static int dropFilesCount = 0; // Count stored strings
|
|
||||||
#endif
|
#endif
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Timming system variables
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
static double currentTime = 0.0; // Current time measure
|
static double currentTime = 0.0; // Current time measure
|
||||||
static double previousTime = 0.0; // Previous time measure
|
static double previousTime = 0.0; // Previous time measure
|
||||||
static double updateTime = 0.0; // Time measure for frame update
|
static double updateTime = 0.0; // Time measure for frame update
|
||||||
static double drawTime = 0.0; // Time measure for frame draw
|
static double drawTime = 0.0; // Time measure for frame draw
|
||||||
static double frameTime = 0.0; // Time measure for one frame
|
static double frameTime = 0.0; // Time measure for one frame
|
||||||
static double targetTime = 0.0; // Desired time for one frame, if 0 not applied
|
static double targetTime = 0.0; // Desired time for one frame, if 0 not applied
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Config internal variables
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
static unsigned char configFlags = 0; // Configuration flags (bit based)
|
static unsigned char configFlags = 0; // Configuration flags (bit based)
|
||||||
static bool showLogo = false; // Track if showing logo at init is enabled
|
static bool showLogo = false; // Track if showing logo at init is enabled
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
static char **dropFilesPath; // Store dropped files paths as strings
|
||||||
|
static int dropFilesCount = 0; // Count dropped files strings
|
||||||
|
#endif
|
||||||
|
static char **dirFilesPath; // Store directory files paths as strings
|
||||||
|
static int dirFilesCount = 0; // Count directory files strings
|
||||||
|
|
||||||
#if defined(SUPPORT_SCREEN_CAPTURE)
|
#if defined(SUPPORT_SCREEN_CAPTURE)
|
||||||
static int screenshotCounter = 0; // Screenshots counter
|
static int screenshotCounter = 0; // Screenshots counter
|
||||||
#endif
|
#endif
|
||||||
|
@ -344,6 +379,7 @@ static int screenshotCounter = 0; // Screenshots counter
|
||||||
static int gifFramesCounter = 0; // GIF frames counter
|
static int gifFramesCounter = 0; // GIF frames counter
|
||||||
static bool gifRecording = false; // GIF recording state
|
static bool gifRecording = false; // GIF recording state
|
||||||
#endif
|
#endif
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Other Modules Functions Declaration (required by core)
|
// Other Modules Functions Declaration (required by core)
|
||||||
|
@ -357,15 +393,18 @@ extern void UnloadDefaultFont(void); // [Module: text] Unloads default fo
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
static bool InitGraphicsDevice(int width, int height); // Initialize graphics device
|
static bool InitGraphicsDevice(int width, int height); // Initialize graphics device
|
||||||
static void SetupFramebufferSize(int displayWidth, int displayHeight);
|
static void SetupFramebuffer(int width, int height); // Setup main framebuffer
|
||||||
|
static void SetupViewport(void); // Set viewport parameters
|
||||||
|
static void SwapBuffers(void); // Copy back buffer to front buffers
|
||||||
|
|
||||||
static void InitTimer(void); // Initialize timer
|
static void InitTimer(void); // Initialize timer
|
||||||
static void Wait(float ms); // Wait for some milliseconds (stop program execution)
|
static void Wait(float ms); // Wait for some milliseconds (stop program execution)
|
||||||
|
|
||||||
static bool GetKeyStatus(int key); // Returns if a key has been pressed
|
static bool GetKeyStatus(int key); // Returns if a key has been pressed
|
||||||
static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed
|
static bool GetMouseButtonStatus(int button); // Returns if a mouse button has been pressed
|
||||||
static void PollInputEvents(void); // Register user events
|
static void PollInputEvents(void); // Register user events
|
||||||
static void SwapBuffers(void); // Copy back buffer to front buffers
|
|
||||||
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
static void LogoAnimation(void); // Plays raylib logo appearing animation
|
||||||
static void SetupViewport(void); // Set viewport parameters
|
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
static void ErrorCallback(int error, const char *description); // GLFW3 Error Callback, runs on GLFW3 error
|
||||||
|
@ -378,7 +417,6 @@ static void CursorEnterCallback(GLFWwindow *window, int enter);
|
||||||
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
|
static void WindowSizeCallback(GLFWwindow *window, int width, int height); // GLFW3 WindowSize Callback, runs when window is resized
|
||||||
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
static void WindowIconifyCallback(GLFWwindow *window, int iconified); // GLFW3 WindowIconify Callback, runs when window is minimized/restored
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
|
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths); // GLFW3 Window Drop Callback, runs when drop files into window
|
||||||
#endif
|
#endif
|
||||||
|
@ -634,7 +672,17 @@ bool IsWindowReady(void)
|
||||||
// Check if KEY_ESCAPE pressed or Close icon pressed
|
// Check if KEY_ESCAPE pressed or Close icon pressed
|
||||||
bool WindowShouldClose(void)
|
bool WindowShouldClose(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
|
// Emterpreter-Async required to run sync code
|
||||||
|
// https://github.com/kripken/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code
|
||||||
|
// By default, this function is never called on a web-ready raylib example because we encapsulate
|
||||||
|
// frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously
|
||||||
|
// but now emscripten allows sync code to be executed in an interpreted way, using emterpreter!
|
||||||
|
emscripten_sleep(16);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
if (windowReady)
|
if (windowReady)
|
||||||
{
|
{
|
||||||
// While window minimized, stop loop execution
|
// While window minimized, stop loop execution
|
||||||
|
@ -757,6 +805,124 @@ int GetScreenHeight(void)
|
||||||
return screenHeight;
|
return screenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get native window handle
|
||||||
|
void *GetWindowHandle(void)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
// NOTE: Returned handle is: void *HWND (windows.h)
|
||||||
|
return glfwGetWin32Window(window);
|
||||||
|
#elif defined(__linux__)
|
||||||
|
// NOTE: Returned handle is: unsigned long Window (X.h)
|
||||||
|
// typedef unsigned long XID;
|
||||||
|
// typedef XID Window;
|
||||||
|
//unsigned long id = (unsigned long)glfwGetX11Window(window);
|
||||||
|
return NULL; // TODO: Find a way to return value... cast to void *?
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// NOTE: Returned handle is: void *id
|
||||||
|
return glfwGetCocoaWindow(window);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get number of monitors
|
||||||
|
int GetMonitorCount(void)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
glfwGetMonitors(&monitorCount);
|
||||||
|
return monitorCount;
|
||||||
|
#else
|
||||||
|
return 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get primary monitor width
|
||||||
|
int GetMonitorWidth(int monitor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]);
|
||||||
|
return mode->width;
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Selected monitor not found");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get primary monitor width
|
||||||
|
int GetMonitorHeight(int monitor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]);
|
||||||
|
return mode->height;
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Selected monitor not found");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get primary montior physical width in millimetres
|
||||||
|
int GetMonitorPhysicalWidth(int monitor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
int physicalWidth;
|
||||||
|
glfwGetMonitorPhysicalSize(monitors[monitor], &physicalWidth, NULL);
|
||||||
|
return physicalWidth;
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Selected monitor not found");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get primary monitor physical height in millimetres
|
||||||
|
int GetMonitorPhysicalHeight(int monitor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
int physicalHeight;
|
||||||
|
glfwGetMonitorPhysicalSize(monitors[monitor], NULL, &physicalHeight);
|
||||||
|
return physicalHeight;
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Selected monitor not found");
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the human-readable, UTF-8 encoded name of the primary monitor
|
||||||
|
const char *GetMonitorName(int monitor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int monitorCount;
|
||||||
|
GLFWmonitor** monitors = glfwGetMonitors(&monitorCount);
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
return glfwGetMonitorName(monitors[monitor]);
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Selected monitor not found");
|
||||||
|
#endif
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// Show mouse cursor
|
// Show mouse cursor
|
||||||
void ShowCursor()
|
void ShowCursor()
|
||||||
{
|
{
|
||||||
|
@ -873,7 +1039,7 @@ void EndDrawing(void)
|
||||||
// Wait for some milliseconds...
|
// Wait for some milliseconds...
|
||||||
if (frameTime < targetTime)
|
if (frameTime < targetTime)
|
||||||
{
|
{
|
||||||
Wait((targetTime - frameTime)*1000.0f);
|
Wait((float)(targetTime - frameTime)*1000.0f);
|
||||||
|
|
||||||
currentTime = GetTime();
|
currentTime = GetTime();
|
||||||
double extraTime = currentTime - previousTime;
|
double extraTime = currentTime - previousTime;
|
||||||
|
@ -1028,7 +1194,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
||||||
// Calculate view matrix from camera look at
|
// Calculate view matrix from camera look at
|
||||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
|
|
||||||
Matrix matProj;
|
Matrix matProj = MatrixIdentity();
|
||||||
|
|
||||||
if (camera.type == CAMERA_PERSPECTIVE)
|
if (camera.type == CAMERA_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
|
@ -1040,6 +1206,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
||||||
float aspect = (float)screenWidth/(float)screenHeight;
|
float aspect = (float)screenWidth/(float)screenHeight;
|
||||||
double top = camera.fovy/2.0;
|
double top = camera.fovy/2.0;
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
// Calculate projection matrix from orthographic
|
// Calculate projection matrix from orthographic
|
||||||
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
||||||
}
|
}
|
||||||
|
@ -1069,18 +1236,19 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
||||||
Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
Vector2 GetWorldToScreen(Vector3 position, Camera camera)
|
||||||
{
|
{
|
||||||
// Calculate projection matrix (from perspective instead of frustum
|
// Calculate projection matrix (from perspective instead of frustum
|
||||||
Matrix matProj;
|
Matrix matProj = MatrixIdentity();
|
||||||
|
|
||||||
if(camera.type == CAMERA_PERSPECTIVE)
|
if (camera.type == CAMERA_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
// Calculate projection matrix from perspective
|
// Calculate projection matrix from perspective
|
||||||
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0);
|
matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0);
|
||||||
}
|
}
|
||||||
else if(camera.type == CAMERA_ORTHOGRAPHIC)
|
else if (camera.type == CAMERA_ORTHOGRAPHIC)
|
||||||
{
|
{
|
||||||
float aspect = (float)screenWidth/(float)screenHeight;
|
float aspect = (float)screenWidth/(float)screenHeight;
|
||||||
double top = camera.fovy/2.0;
|
double top = camera.fovy/2.0;
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
// Calculate projection matrix from orthographic
|
// Calculate projection matrix from orthographic
|
||||||
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
matProj = MatrixOrtho(-right, right, -top, top, 0.01, 1000.0);
|
||||||
}
|
}
|
||||||
|
@ -1282,7 +1450,9 @@ void TakeScreenshot(const char *fileName)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
unsigned char *imgData = rlReadScreenPixels(renderWidth, renderHeight);
|
unsigned char *imgData = rlReadScreenPixels(renderWidth, renderHeight);
|
||||||
SavePNG(fileName, imgData, renderWidth, renderHeight, 4); // Save image as PNG
|
|
||||||
|
Image image = { imgData, renderWidth, renderHeight, 1, UNCOMPRESSED_R8G8B8A8 };
|
||||||
|
ExportImage(image, fileName);
|
||||||
free(imgData);
|
free(imgData);
|
||||||
|
|
||||||
TraceLog(LOG_INFO, "Screenshot taken: %s", fileName);
|
TraceLog(LOG_INFO, "Screenshot taken: %s", fileName);
|
||||||
|
@ -1312,6 +1482,7 @@ bool IsFileExtension(const char *fileName, const char *ext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else result = false;
|
||||||
#else
|
#else
|
||||||
if (strcmp(fileExt, ext) == 0) result = true;
|
if (strcmp(fileExt, ext) == 0) result = true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1330,10 +1501,18 @@ const char *GetExtension(const char *fileName)
|
||||||
return (dot + 1);
|
return (dot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String pointer reverse break: returns right-most occurrence of charset in s
|
||||||
|
static const char *strprbrk(const char *s, const char *charset)
|
||||||
|
{
|
||||||
|
const char *latestMatch = NULL;
|
||||||
|
for (; s = strpbrk(s, charset), s != NULL; latestMatch = s++) { }
|
||||||
|
return latestMatch;
|
||||||
|
}
|
||||||
|
|
||||||
// Get pointer to filename for a path string
|
// Get pointer to filename for a path string
|
||||||
const char *GetFileName(const char *filePath)
|
const char *GetFileName(const char *filePath)
|
||||||
{
|
{
|
||||||
const char *fileName = strrchr(filePath, '\\');
|
const char *fileName = strprbrk(filePath, "\\/");
|
||||||
|
|
||||||
if (!fileName || fileName == filePath) return filePath;
|
if (!fileName || fileName == filePath) return filePath;
|
||||||
|
|
||||||
|
@ -1344,11 +1523,13 @@ const char *GetFileName(const char *filePath)
|
||||||
// Get directory for a given fileName (with path)
|
// Get directory for a given fileName (with path)
|
||||||
const char *GetDirectoryPath(const char *fileName)
|
const char *GetDirectoryPath(const char *fileName)
|
||||||
{
|
{
|
||||||
char *lastSlash = NULL;
|
const char *lastSlash = NULL;
|
||||||
static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256
|
static char filePath[256]; // MAX_DIRECTORY_PATH_SIZE = 256
|
||||||
memset(filePath, 0, 256);
|
memset(filePath, 0, 256);
|
||||||
|
|
||||||
lastSlash = strrchr(fileName, '\\');
|
lastSlash = strprbrk(fileName, "\\/");
|
||||||
|
if (!lastSlash) return NULL;
|
||||||
|
|
||||||
strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
|
strncpy(filePath, fileName, strlen(fileName) - (strlen(lastSlash) - 1));
|
||||||
filePath[strlen(fileName) - strlen(lastSlash)] = '\0';
|
filePath[strlen(fileName) - strlen(lastSlash)] = '\0';
|
||||||
|
|
||||||
|
@ -1366,6 +1547,57 @@ const char *GetWorkingDirectory(void)
|
||||||
return currentDir;
|
return currentDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get filenames in a directory path (max 256 files)
|
||||||
|
// NOTE: Files count is returned by parameters pointer
|
||||||
|
char **GetDirectoryFiles(const char *dirPath, int *fileCount)
|
||||||
|
{
|
||||||
|
#define MAX_FILEPATH_LENGTH 256
|
||||||
|
#define MAX_DIRECTORY_FILES 512
|
||||||
|
|
||||||
|
ClearDirectoryFiles();
|
||||||
|
|
||||||
|
// Memory allocation for MAX_DIRECTORY_FILES
|
||||||
|
dirFilesPath = (char **)malloc(sizeof(char *)*MAX_DIRECTORY_FILES);
|
||||||
|
for (int i = 0; i < MAX_DIRECTORY_FILES; i++) dirFilesPath[i] = (char *)malloc(sizeof(char)*MAX_FILEPATH_LENGTH);
|
||||||
|
|
||||||
|
int counter = 0;
|
||||||
|
struct dirent *ent;
|
||||||
|
DIR *dir = opendir(dirPath);
|
||||||
|
|
||||||
|
if (dir != NULL) // It's a directory
|
||||||
|
{
|
||||||
|
// TODO: Reading could be done in two passes,
|
||||||
|
// first one to count files and second one to read names
|
||||||
|
// That way we can allocate required memory, instead of a limited pool
|
||||||
|
|
||||||
|
while ((ent = readdir(dir)) != NULL)
|
||||||
|
{
|
||||||
|
strcpy(dirFilesPath[counter], ent->d_name);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
|
else TraceLog(LOG_WARNING, "Can not open directory...\n"); // Maybe it's a file...
|
||||||
|
|
||||||
|
dirFilesCount = counter;
|
||||||
|
*fileCount = dirFilesCount;
|
||||||
|
|
||||||
|
return dirFilesPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear directory files paths buffers
|
||||||
|
void ClearDirectoryFiles(void)
|
||||||
|
{
|
||||||
|
if (dirFilesCount > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < dirFilesCount; i++) free(dirFilesPath[i]);
|
||||||
|
|
||||||
|
free(dirFilesPath);
|
||||||
|
dirFilesCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Change working directory, returns true if success
|
// Change working directory, returns true if success
|
||||||
bool ChangeDirectory(const char *dir)
|
bool ChangeDirectory(const char *dir)
|
||||||
{
|
{
|
||||||
|
@ -1853,6 +2085,10 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
glfwSetErrorCallback(ErrorCallback);
|
glfwSetErrorCallback(ErrorCallback);
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
glfwInitHint(GLFW_COCOA_CHDIR_RESOURCES, GLFW_FALSE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
{
|
{
|
||||||
TraceLog(LOG_WARNING, "Failed to initialize GLFW");
|
TraceLog(LOG_WARNING, "Failed to initialize GLFW");
|
||||||
|
@ -1883,30 +2119,29 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
displayHeight = screenHeight;
|
displayHeight = screenHeight;
|
||||||
#endif // defined(PLATFORM_WEB)
|
#endif // defined(PLATFORM_WEB)
|
||||||
|
|
||||||
glfwDefaultWindowHints(); // Set default windows hints
|
glfwDefaultWindowHints(); // Set default windows hints:
|
||||||
|
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
||||||
|
//glfwWindowHint(GLFW_GREEN_BITS, 8); // Framebuffer green color component bits
|
||||||
|
//glfwWindowHint(GLFW_BLUE_BITS, 8); // Framebuffer blue color component bits
|
||||||
|
//glfwWindowHint(GLFW_ALPHA_BITS, 8); // Framebuffer alpha color component bits
|
||||||
|
//glfwWindowHint(GLFW_DEPTH_BITS, 24); // Depthbuffer bits
|
||||||
|
//glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window
|
||||||
|
//glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // OpenGL API to use. Alternative: GLFW_OPENGL_ES_API
|
||||||
|
//glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
|
||||||
|
|
||||||
// Check some Window creation flags
|
// Check some Window creation flags
|
||||||
if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window
|
if (configFlags & FLAG_WINDOW_RESIZABLE) glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Resizable window
|
||||||
else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable
|
else glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Avoid window being resizable
|
||||||
|
|
||||||
if (configFlags & FLAG_WINDOW_DECORATED) glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Border and buttons on Window
|
if (configFlags & FLAG_WINDOW_UNDECORATED) glfwWindowHint(GLFW_DECORATED, GL_FALSE); // Border and buttons on Window
|
||||||
|
else glfwWindowHint(GLFW_DECORATED, GL_TRUE); // Decorated window
|
||||||
|
// FLAG_WINDOW_TRANSPARENT not supported on HTML5 and not included in any released GLFW version yet
|
||||||
|
#if defined(GLFW_TRANSPARENT_FRAMEBUFFER)
|
||||||
|
if (configFlags & FLAG_WINDOW_TRANSPARENT) glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); // Transparent framebuffer
|
||||||
|
else glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); // Opaque framebuffer
|
||||||
|
#endif
|
||||||
|
|
||||||
if (configFlags & FLAG_WINDOW_TRANSPARENT)
|
if (configFlags & FLAG_MSAA_4X_HINT) glfwWindowHint(GLFW_SAMPLES, 4); // Tries to enable multisampling x4 (MSAA), default is 0
|
||||||
{
|
|
||||||
// TODO: Enable transparent window (not ready yet on GLFW 3.2)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configFlags & FLAG_MSAA_4X_HINT)
|
|
||||||
{
|
|
||||||
glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0
|
|
||||||
TraceLog(LOG_INFO, "Trying to enable MSAA x4");
|
|
||||||
}
|
|
||||||
|
|
||||||
//glfwWindowHint(GLFW_RED_BITS, 8); // Framebuffer red color component bits
|
|
||||||
//glfwWindowHint(GLFW_DEPTH_BITS, 16); // Depthbuffer bits (24 by default)
|
|
||||||
//glfwWindowHint(GLFW_REFRESH_RATE, 0); // Refresh rate for fullscreen window
|
|
||||||
//glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); // Default OpenGL API to use. Alternative: GLFW_OPENGL_ES_API
|
|
||||||
//glfwWindowHint(GLFW_AUX_BUFFERS, 0); // Number of auxiliar buffers
|
|
||||||
|
|
||||||
// NOTE: When asking for an OpenGL context version, most drivers provide highest supported version
|
// NOTE: When asking for an OpenGL context version, most drivers provide highest supported version
|
||||||
// with forward compatibility to older OpenGL versions.
|
// with forward compatibility to older OpenGL versions.
|
||||||
|
@ -1925,11 +2160,11 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above!
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Profiles Hint: Only 3.3 and above!
|
||||||
// Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE
|
// Other values: GLFW_OPENGL_ANY_PROFILE, GLFW_OPENGL_COMPAT_PROFILE
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // OSX Requires fordward compatibility
|
||||||
#else
|
#else
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above!
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE); // Fordward Compatibility Hint: Only 3.3 and above!
|
||||||
#endif
|
#endif
|
||||||
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
//glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); // Request OpenGL DEBUG context
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
|
@ -1962,7 +2197,7 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
// At this point we need to manage render size vs screen size
|
// At this point we need to manage render size vs screen size
|
||||||
// NOTE: This function uses and modifies global module variables:
|
// NOTE: This function uses and modifies global module variables:
|
||||||
// screenWidth/screenHeight - renderWidth/renderHeight - downscaleView
|
// screenWidth/screenHeight - renderWidth/renderHeight - downscaleView
|
||||||
SetupFramebufferSize(displayWidth, displayHeight);
|
SetupFramebuffer(displayWidth, displayHeight);
|
||||||
|
|
||||||
window = glfwCreateWindow(displayWidth, displayHeight, windowTitle, glfwGetPrimaryMonitor(), NULL);
|
window = glfwCreateWindow(displayWidth, displayHeight, windowTitle, glfwGetPrimaryMonitor(), NULL);
|
||||||
|
|
||||||
|
@ -2196,7 +2431,7 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetupFramebufferSize(displayWidth, displayHeight);
|
//SetupFramebuffer(displayWidth, displayHeight);
|
||||||
|
|
||||||
EGLint numConfigs = 0;
|
EGLint numConfigs = 0;
|
||||||
if ((eglChooseConfig(display, framebufferAttribs, &config, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0))
|
if ((eglChooseConfig(display, framebufferAttribs, &config, 1, &numConfigs) == EGL_FALSE) || (numConfigs == 0))
|
||||||
|
@ -2302,7 +2537,7 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
|
|
||||||
// At this point we need to manage render size vs screen size
|
// At this point we need to manage render size vs screen size
|
||||||
// NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
// NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
||||||
SetupFramebufferSize(displayWidth, displayHeight);
|
SetupFramebuffer(displayWidth, displayHeight);
|
||||||
|
|
||||||
ANativeWindow_setBuffersGeometry(androidApp->window, renderWidth, renderHeight, displayFormat);
|
ANativeWindow_setBuffersGeometry(androidApp->window, renderWidth, renderHeight, displayFormat);
|
||||||
//ANativeWindow_setBuffersGeometry(androidApp->window, 0, 0, displayFormat); // Force use of native display size
|
//ANativeWindow_setBuffersGeometry(androidApp->window, 0, 0, displayFormat); // Force use of native display size
|
||||||
|
@ -2315,7 +2550,7 @@ static bool InitGraphicsDevice(int width, int height)
|
||||||
|
|
||||||
// At this point we need to manage render size vs screen size
|
// At this point we need to manage render size vs screen size
|
||||||
// NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
// NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
||||||
SetupFramebufferSize(displayWidth, displayHeight);
|
SetupFramebuffer(displayWidth, displayHeight);
|
||||||
|
|
||||||
dstRect.x = 0;
|
dstRect.x = 0;
|
||||||
dstRect.y = 0;
|
dstRect.y = 0;
|
||||||
|
@ -2417,7 +2652,7 @@ static void SetupViewport(void)
|
||||||
|
|
||||||
// Compute framebuffer size relative to screen size and display size
|
// Compute framebuffer size relative to screen size and display size
|
||||||
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
// NOTE: Global variables renderWidth/renderHeight and renderOffsetX/renderOffsetY can be modified
|
||||||
static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
static void SetupFramebuffer(int width, int height)
|
||||||
{
|
{
|
||||||
// Calculate renderWidth and renderHeight, we have the display size (input params) and the desired screen size (global var)
|
// Calculate renderWidth and renderHeight, we have the display size (input params) and the desired screen size (global var)
|
||||||
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
|
if ((screenWidth > displayWidth) || (screenHeight > displayHeight))
|
||||||
|
@ -2491,7 +2726,7 @@ static void SetupFramebufferSize(int displayWidth, int displayHeight)
|
||||||
// Initialize hi-resolution timer
|
// Initialize hi-resolution timer
|
||||||
static void InitTimer(void)
|
static void InitTimer(void)
|
||||||
{
|
{
|
||||||
srand(time(NULL)); // Initialize random seed
|
srand((unsigned int)time(NULL)); // Initialize random seed
|
||||||
|
|
||||||
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
#if !defined(SUPPORT_BUSY_WAIT_LOOP) && defined(_WIN32)
|
||||||
timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms)
|
timeBeginPeriod(1); // Setup high-resolution timer to 1ms (granularity of 1-2 ms)
|
||||||
|
@ -2741,6 +2976,15 @@ static void SwapBuffers(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
#if __APPLE__
|
||||||
|
// workaround for missing/erroneous initial rendering on macOS
|
||||||
|
if (windowNeedsUpdating) {
|
||||||
|
// Desugared version of Objective C: [glfwGetNSGLContext(window) update]
|
||||||
|
((id (*)(id, SEL))objc_msgSend)(glfwGetNSGLContext(window),
|
||||||
|
sel_registerName("update"));
|
||||||
|
windowNeedsUpdating--;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(PLATFORM_UWP)
|
||||||
|
@ -3079,7 +3323,8 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
// Android: Get input events
|
// Android: Get input events
|
||||||
static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
{
|
{
|
||||||
//http://developer.android.com/ndk/reference/index.html
|
// If additional inputs are required check:
|
||||||
|
// https://developer.android.com/ndk/reference/group/input
|
||||||
|
|
||||||
int type = AInputEvent_getType(event);
|
int type = AInputEvent_getType(event);
|
||||||
|
|
||||||
|
@ -3092,6 +3337,23 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
// Get second touch position
|
// Get second touch position
|
||||||
touchPosition[1].x = AMotionEvent_getX(event, 1);
|
touchPosition[1].x = AMotionEvent_getX(event, 1);
|
||||||
touchPosition[1].y = AMotionEvent_getY(event, 1);
|
touchPosition[1].y = AMotionEvent_getY(event, 1);
|
||||||
|
|
||||||
|
// Useful functions for gamepad inputs:
|
||||||
|
//AMotionEvent_getAction()
|
||||||
|
//AMotionEvent_getAxisValue()
|
||||||
|
//AMotionEvent_getButtonState()
|
||||||
|
|
||||||
|
// Gamepad dpad button presses capturing
|
||||||
|
// TODO: That's weird, key input (or button)
|
||||||
|
// shouldn't come as a TYPE_MOTION event...
|
||||||
|
int32_t keycode = AKeyEvent_getKeyCode(event);
|
||||||
|
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN)
|
||||||
|
{
|
||||||
|
currentKeyState[keycode] = 1; // Key down
|
||||||
|
lastKeyPressed = keycode;
|
||||||
|
}
|
||||||
|
else currentKeyState[keycode] = 0; // Key up
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (type == AINPUT_EVENT_TYPE_KEY)
|
else if (type == AINPUT_EVENT_TYPE_KEY)
|
||||||
{
|
{
|
||||||
|
@ -3100,9 +3362,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
|
|
||||||
// Save current button and its state
|
// Save current button and its state
|
||||||
// NOTE: Android key action is 0 for down and 1 for up
|
// NOTE: Android key action is 0 for down and 1 for up
|
||||||
if (AKeyEvent_getAction(event) == 0)
|
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN)
|
||||||
{
|
{
|
||||||
currentKeyState[keycode] = 1; // Key down
|
currentKeyState[keycode] = 1; // Key down
|
||||||
lastKeyPressed = keycode;
|
lastKeyPressed = keycode;
|
||||||
}
|
}
|
||||||
else currentKeyState[keycode] = 0; // Key up
|
else currentKeyState[keycode] = 0; // Key up
|
||||||
|
@ -3140,26 +3402,32 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
||||||
|
|
||||||
// Register touch points count
|
// Register touch points count
|
||||||
|
// NOTE: Documentation says pointerCount is Always >= 1,
|
||||||
|
// but in practice it can be 0 or over a million
|
||||||
gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
|
gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
|
||||||
|
|
||||||
// Register touch points id
|
// Only enable gestures for 1-3 touch points
|
||||||
gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
|
if ((gestureEvent.pointCount > 0) && (gestureEvent.pointCount < 4))
|
||||||
gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
|
{
|
||||||
|
// Register touch points id
|
||||||
|
// NOTE: Only two points registered
|
||||||
|
gestureEvent.pointerId[0] = AMotionEvent_getPointerId(event, 0);
|
||||||
|
gestureEvent.pointerId[1] = AMotionEvent_getPointerId(event, 1);
|
||||||
|
|
||||||
// Register touch points position
|
// Register touch points position
|
||||||
// NOTE: Only two points registered
|
gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
|
||||||
gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
|
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
|
||||||
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
|
|
||||||
|
|
||||||
// Normalize gestureEvent.position[x] for screenWidth and screenHeight
|
// Normalize gestureEvent.position[x] for screenWidth and screenHeight
|
||||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||||
|
|
||||||
gestureEvent.position[1].x /= (float)GetScreenWidth();
|
gestureEvent.position[1].x /= (float)GetScreenWidth();
|
||||||
gestureEvent.position[1].y /= (float)GetScreenHeight();
|
gestureEvent.position[1].y /= (float)GetScreenHeight();
|
||||||
|
|
||||||
// Gesture data is sent to gestures system for processing
|
// Gesture data is sent to gestures system for processing
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Support only simple touch position
|
// Support only simple touch position
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package raylib
|
package rl
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
@ -95,43 +95,90 @@ func SetWindowTitle(title string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP)
|
// SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP)
|
||||||
func SetWindowPosition(x, y int32) {
|
func SetWindowPosition(x, y int) {
|
||||||
cx := (C.int)(x)
|
cx := (C.int)(x)
|
||||||
cy := (C.int)(y)
|
cy := (C.int)(y)
|
||||||
C.SetWindowPosition(cx, cy)
|
C.SetWindowPosition(cx, cy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWindowMonitor - Set monitor for the current window (fullscreen mode)
|
// SetWindowMonitor - Set monitor for the current window (fullscreen mode)
|
||||||
func SetWindowMonitor(monitor int32) {
|
func SetWindowMonitor(monitor int) {
|
||||||
cmonitor := (C.int)(monitor)
|
cmonitor := (C.int)(monitor)
|
||||||
C.SetWindowMonitor(cmonitor)
|
C.SetWindowMonitor(cmonitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
|
// SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
|
||||||
func SetWindowMinSize(w, h int32) {
|
func SetWindowMinSize(w, h int) {
|
||||||
cw := (C.int)(w)
|
cw := (C.int)(w)
|
||||||
ch := (C.int)(h)
|
ch := (C.int)(h)
|
||||||
C.SetWindowMinSize(cw, ch)
|
C.SetWindowMinSize(cw, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWindowSize - Set window dimensions
|
// SetWindowSize - Set window dimensions
|
||||||
func SetWindowSize(w, h int32) {
|
func SetWindowSize(w, h int) {
|
||||||
cw := (C.int)(w)
|
cw := (C.int)(w)
|
||||||
ch := (C.int)(h)
|
ch := (C.int)(h)
|
||||||
C.SetWindowSize(cw, ch)
|
C.SetWindowSize(cw, ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScreenWidth - Get current screen width
|
// GetScreenWidth - Get current screen width
|
||||||
func GetScreenWidth() int32 {
|
func GetScreenWidth() int {
|
||||||
ret := C.GetScreenWidth()
|
ret := C.GetScreenWidth()
|
||||||
v := (int32)(ret)
|
v := (int)(ret)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetScreenHeight - Get current screen height
|
// GetScreenHeight - Get current screen height
|
||||||
func GetScreenHeight() int32 {
|
func GetScreenHeight() int {
|
||||||
ret := C.GetScreenHeight()
|
ret := C.GetScreenHeight()
|
||||||
v := (int32)(ret)
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorCount - Get number of connected monitors
|
||||||
|
func GetMonitorCount() int {
|
||||||
|
ret := C.GetMonitorCount()
|
||||||
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorWidth - Get primary monitor width
|
||||||
|
func GetMonitorWidth(monitor int) int {
|
||||||
|
cmonitor := (C.int)(monitor)
|
||||||
|
ret := C.GetMonitorWidth(cmonitor)
|
||||||
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorHeight - Get primary monitor height
|
||||||
|
func GetMonitorHeight(monitor int) int {
|
||||||
|
cmonitor := (C.int)(monitor)
|
||||||
|
ret := C.GetMonitorHeight(cmonitor)
|
||||||
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorPhysicalWidth - Get primary monitor physical width in millimetres
|
||||||
|
func GetMonitorPhysicalWidth(monitor int) int {
|
||||||
|
cmonitor := (C.int)(monitor)
|
||||||
|
ret := C.GetMonitorPhysicalWidth(cmonitor)
|
||||||
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorPhysicalHeight - Get primary monitor physical height in millimetres
|
||||||
|
func GetMonitorPhysicalHeight(monitor int) int {
|
||||||
|
cmonitor := (C.int)(monitor)
|
||||||
|
ret := C.GetMonitorPhysicalHeight(cmonitor)
|
||||||
|
v := (int)(ret)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMonitorName - Get the human-readable, UTF-8 encoded name of the primary monitor
|
||||||
|
func GetMonitorName(monitor int) string {
|
||||||
|
cmonitor := (C.int)(monitor)
|
||||||
|
ret := C.GetMonitorName(cmonitor)
|
||||||
|
v := C.GoString(ret)
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +322,7 @@ func ColorNormalize(color Color) Vector4 {
|
||||||
|
|
||||||
// Vector3ToFloat - Converts Vector3 to float32 slice
|
// Vector3ToFloat - Converts Vector3 to float32 slice
|
||||||
func Vector3ToFloat(vec Vector3) []float32 {
|
func Vector3ToFloat(vec Vector3) []float32 {
|
||||||
data := make([]float32, 3)
|
data := make([]float32, 0)
|
||||||
data[0] = vec.X
|
data[0] = vec.X
|
||||||
data[1] = vec.Y
|
data[1] = vec.Y
|
||||||
data[2] = vec.Z
|
data[2] = vec.Z
|
||||||
|
@ -285,7 +332,7 @@ func Vector3ToFloat(vec Vector3) []float32 {
|
||||||
|
|
||||||
// MatrixToFloat - Converts Matrix to float32 slice
|
// MatrixToFloat - Converts Matrix to float32 slice
|
||||||
func MatrixToFloat(mat Matrix) []float32 {
|
func MatrixToFloat(mat Matrix) []float32 {
|
||||||
data := make([]float32, 16)
|
data := make([]float32, 0)
|
||||||
|
|
||||||
data[0] = mat.M0
|
data[0] = mat.M0
|
||||||
data[1] = mat.M4
|
data[1] = mat.M4
|
||||||
|
|
55
raylib/external/alsa/alisp.h
vendored
55
raylib/external/alsa/alisp.h
vendored
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* ALSA lisp implementation
|
|
||||||
* Copyright (c) 2003 by Jaroslav Kysela <perex@perex.cz>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct alisp_cfg {
|
|
||||||
int verbose: 1,
|
|
||||||
warning: 1,
|
|
||||||
debug: 1;
|
|
||||||
snd_input_t *in; /* program code */
|
|
||||||
snd_output_t *out; /* program output */
|
|
||||||
snd_output_t *eout; /* error output */
|
|
||||||
snd_output_t *vout; /* verbose output */
|
|
||||||
snd_output_t *wout; /* warning output */
|
|
||||||
snd_output_t *dout; /* debug output */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct alisp_instance;
|
|
||||||
struct alisp_object;
|
|
||||||
struct alisp_seq_iterator;
|
|
||||||
|
|
||||||
struct alisp_cfg *alsa_lisp_default_cfg(snd_input_t *input);
|
|
||||||
void alsa_lisp_default_cfg_free(struct alisp_cfg *cfg);
|
|
||||||
int alsa_lisp(struct alisp_cfg *cfg, struct alisp_instance **instance);
|
|
||||||
void alsa_lisp_free(struct alisp_instance *instance);
|
|
||||||
int alsa_lisp_function(struct alisp_instance *instance, struct alisp_seq_iterator **result,
|
|
||||||
const char *id, const char *args, ...)
|
|
||||||
#ifndef DOC_HIDDEN
|
|
||||||
__attribute__ ((format (printf, 4, 5)))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
void alsa_lisp_result_free(struct alisp_instance *instance,
|
|
||||||
struct alisp_seq_iterator *result);
|
|
||||||
int alsa_lisp_seq_first(struct alisp_instance *instance, const char *id,
|
|
||||||
struct alisp_seq_iterator **seq);
|
|
||||||
int alsa_lisp_seq_next(struct alisp_seq_iterator **seq);
|
|
||||||
int alsa_lisp_seq_count(struct alisp_seq_iterator *seq);
|
|
||||||
int alsa_lisp_seq_integer(struct alisp_seq_iterator *seq, long *val);
|
|
||||||
int alsa_lisp_seq_pointer(struct alisp_seq_iterator *seq, const char *ptr_id, void **ptr);
|
|
310
raylib/external/alsa/asoundef.h
vendored
310
raylib/external/alsa/asoundef.h
vendored
|
@ -1,310 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/asoundef.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Definitions of constants for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_ASOUNDEF_H
|
|
||||||
#define __ALSA_ASOUNDEF_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Digital_Audio_Interface Constants for Digital Audio Interfaces
|
|
||||||
* AES/IEC958 channel status bits.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define IEC958_AES0_PROFESSIONAL (1<<0) /**< 0 = consumer, 1 = professional */
|
|
||||||
#define IEC958_AES0_NONAUDIO (1<<1) /**< 0 = audio, 1 = non-audio */
|
|
||||||
#define IEC958_AES0_PRO_EMPHASIS (7<<2) /**< mask - emphasis */
|
|
||||||
#define IEC958_AES0_PRO_EMPHASIS_NOTID (0<<2) /**< emphasis not indicated */
|
|
||||||
#define IEC958_AES0_PRO_EMPHASIS_NONE (1<<2) /**< no emphasis */
|
|
||||||
#define IEC958_AES0_PRO_EMPHASIS_5015 (3<<2) /**< 50/15us emphasis */
|
|
||||||
#define IEC958_AES0_PRO_EMPHASIS_CCITT (7<<2) /**< CCITT J.17 emphasis */
|
|
||||||
#define IEC958_AES0_PRO_FREQ_UNLOCKED (1<<5) /**< source sample frequency: 0 = locked, 1 = unlocked */
|
|
||||||
#define IEC958_AES0_PRO_FS (3<<6) /**< mask - sample frequency */
|
|
||||||
#define IEC958_AES0_PRO_FS_NOTID (0<<6) /**< fs not indicated */
|
|
||||||
#define IEC958_AES0_PRO_FS_44100 (1<<6) /**< 44.1kHz */
|
|
||||||
#define IEC958_AES0_PRO_FS_48000 (2<<6) /**< 48kHz */
|
|
||||||
#define IEC958_AES0_PRO_FS_32000 (3<<6) /**< 32kHz */
|
|
||||||
#define IEC958_AES0_CON_NOT_COPYRIGHT (1<<2) /**< 0 = copyright, 1 = not copyright */
|
|
||||||
#define IEC958_AES0_CON_EMPHASIS (7<<3) /**< mask - emphasis */
|
|
||||||
#define IEC958_AES0_CON_EMPHASIS_NONE (0<<3) /**< no emphasis */
|
|
||||||
#define IEC958_AES0_CON_EMPHASIS_5015 (1<<3) /**< 50/15us emphasis */
|
|
||||||
#define IEC958_AES0_CON_MODE (3<<6) /**< mask - mode */
|
|
||||||
#define IEC958_AES1_PRO_MODE (15<<0) /**< mask - channel mode */
|
|
||||||
#define IEC958_AES1_PRO_MODE_NOTID (0<<0) /**< mode not indicated */
|
|
||||||
#define IEC958_AES1_PRO_MODE_STEREOPHONIC (2<<0) /**< stereophonic - ch A is left */
|
|
||||||
#define IEC958_AES1_PRO_MODE_SINGLE (4<<0) /**< single channel */
|
|
||||||
#define IEC958_AES1_PRO_MODE_TWO (8<<0) /**< two channels */
|
|
||||||
#define IEC958_AES1_PRO_MODE_PRIMARY (12<<0) /**< primary/secondary */
|
|
||||||
#define IEC958_AES1_PRO_MODE_BYTE3 (15<<0) /**< vector to byte 3 */
|
|
||||||
#define IEC958_AES1_PRO_USERBITS (15<<4) /**< mask - user bits */
|
|
||||||
#define IEC958_AES1_PRO_USERBITS_NOTID (0<<4) /**< user bits not indicated */
|
|
||||||
#define IEC958_AES1_PRO_USERBITS_192 (8<<4) /**< 192-bit structure */
|
|
||||||
#define IEC958_AES1_PRO_USERBITS_UDEF (12<<4) /**< user defined application */
|
|
||||||
#define IEC958_AES1_CON_CATEGORY 0x7f /**< consumer category */
|
|
||||||
#define IEC958_AES1_CON_GENERAL 0x00 /**< general category */
|
|
||||||
#define IEC958_AES1_CON_LASEROPT_MASK 0x07 /**< Laser-optical mask */
|
|
||||||
#define IEC958_AES1_CON_LASEROPT_ID 0x01 /**< Laser-optical ID */
|
|
||||||
#define IEC958_AES1_CON_IEC908_CD (IEC958_AES1_CON_LASEROPT_ID|0x00) /**< IEC958 CD compatible device */
|
|
||||||
#define IEC958_AES1_CON_NON_IEC908_CD (IEC958_AES1_CON_LASEROPT_ID|0x08) /**< non-IEC958 CD compatible device */
|
|
||||||
#define IEC958_AES1_CON_MINI_DISC (IEC958_AES1_CON_LASEROPT_ID|0x48) /**< Mini-Disc device */
|
|
||||||
#define IEC958_AES1_CON_DVD (IEC958_AES1_CON_LASEROPT_ID|0x18) /**< DVD device */
|
|
||||||
#define IEC958_AES1_CON_LASTEROPT_OTHER (IEC958_AES1_CON_LASEROPT_ID|0x78) /**< Other laser-optical product */
|
|
||||||
#define IEC958_AES1_CON_DIGDIGCONV_MASK 0x07 /**< digital<->digital converter mask */
|
|
||||||
#define IEC958_AES1_CON_DIGDIGCONV_ID 0x02 /**< digital<->digital converter id */
|
|
||||||
#define IEC958_AES1_CON_PCM_CODER (IEC958_AES1_CON_DIGDIGCONV_ID|0x00) /**< PCM coder */
|
|
||||||
#define IEC958_AES1_CON_MIXER (IEC958_AES1_CON_DIGDIGCONV_ID|0x10) /**< Digital signal mixer */
|
|
||||||
#define IEC958_AES1_CON_RATE_CONVERTER (IEC958_AES1_CON_DIGDIGCONV_ID|0x18) /**< Rate converter */
|
|
||||||
#define IEC958_AES1_CON_SAMPLER (IEC958_AES1_CON_DIGDIGCONV_ID|0x20) /**< PCM sampler */
|
|
||||||
#define IEC958_AES1_CON_DSP (IEC958_AES1_CON_DIGDIGCONV_ID|0x28) /**< Digital sound processor */
|
|
||||||
#define IEC958_AES1_CON_DIGDIGCONV_OTHER (IEC958_AES1_CON_DIGDIGCONV_ID|0x78) /**< Other digital<->digital product */
|
|
||||||
#define IEC958_AES1_CON_MAGNETIC_MASK 0x07 /**< Magnetic device mask */
|
|
||||||
#define IEC958_AES1_CON_MAGNETIC_ID 0x03 /**< Magnetic device ID */
|
|
||||||
#define IEC958_AES1_CON_DAT (IEC958_AES1_CON_MAGNETIC_ID|0x00) /**< Digital Audio Tape */
|
|
||||||
#define IEC958_AES1_CON_VCR (IEC958_AES1_CON_MAGNETIC_ID|0x08) /**< Video recorder */
|
|
||||||
#define IEC958_AES1_CON_DCC (IEC958_AES1_CON_MAGNETIC_ID|0x40) /**< Digital compact cassette */
|
|
||||||
#define IEC958_AES1_CON_MAGNETIC_DISC (IEC958_AES1_CON_MAGNETIC_ID|0x18) /**< Magnetic disc digital audio device */
|
|
||||||
#define IEC958_AES1_CON_MAGNETIC_OTHER (IEC958_AES1_CON_MAGNETIC_ID|0x78) /**< Other magnetic device */
|
|
||||||
#define IEC958_AES1_CON_BROADCAST1_MASK 0x07 /**< Broadcast mask */
|
|
||||||
#define IEC958_AES1_CON_BROADCAST1_ID 0x04 /**< Broadcast ID */
|
|
||||||
#define IEC958_AES1_CON_DAB_JAPAN (IEC958_AES1_CON_BROADCAST1_ID|0x00) /**< Digital audio broadcast (Japan) */
|
|
||||||
#define IEC958_AES1_CON_DAB_EUROPE (IEC958_AES1_CON_BROADCAST1_ID|0x08) /**< Digital audio broadcast (Europe) */
|
|
||||||
#define IEC958_AES1_CON_DAB_USA (IEC958_AES1_CON_BROADCAST1_ID|0x60) /**< Digital audio broadcast (USA) */
|
|
||||||
#define IEC958_AES1_CON_SOFTWARE (IEC958_AES1_CON_BROADCAST1_ID|0x40) /**< Electronic software delivery */
|
|
||||||
#define IEC958_AES1_CON_IEC62105 (IEC958_AES1_CON_BROADCAST1_ID|0x20) /**< Used by another standard (IEC 62105) */
|
|
||||||
#define IEC958_AES1_CON_BROADCAST1_OTHER (IEC958_AES1_CON_BROADCAST1_ID|0x78) /**< Other broadcast product */
|
|
||||||
#define IEC958_AES1_CON_BROADCAST2_MASK 0x0f /**< Broadcast alternative mask */
|
|
||||||
#define IEC958_AES1_CON_BROADCAST2_ID 0x0e /**< Broadcast alternative ID */
|
|
||||||
#define IEC958_AES1_CON_MUSICAL_MASK 0x07 /**< Musical device mask */
|
|
||||||
#define IEC958_AES1_CON_MUSICAL_ID 0x05 /**< Musical device ID */
|
|
||||||
#define IEC958_AES1_CON_SYNTHESIZER (IEC958_AES1_CON_MUSICAL_ID|0x00) /**< Synthesizer */
|
|
||||||
#define IEC958_AES1_CON_MICROPHONE (IEC958_AES1_CON_MUSICAL_ID|0x08) /**< Microphone */
|
|
||||||
#define IEC958_AES1_CON_MUSICAL_OTHER (IEC958_AES1_CON_MUSICAL_ID|0x78) /**< Other musical device */
|
|
||||||
#define IEC958_AES1_CON_ADC_MASK 0x1f /**< ADC Mask */
|
|
||||||
#define IEC958_AES1_CON_ADC_ID 0x06 /**< ADC ID */
|
|
||||||
#define IEC958_AES1_CON_ADC (IEC958_AES1_CON_ADC_ID|0x00) /**< ADC without copyright information */
|
|
||||||
#define IEC958_AES1_CON_ADC_OTHER (IEC958_AES1_CON_ADC_ID|0x60) /**< Other ADC product (with no copyright information) */
|
|
||||||
#define IEC958_AES1_CON_ADC_COPYRIGHT_MASK 0x1f /**< ADC Copyright mask */
|
|
||||||
#define IEC958_AES1_CON_ADC_COPYRIGHT_ID 0x16 /**< ADC Copyright ID */
|
|
||||||
#define IEC958_AES1_CON_ADC_COPYRIGHT (IEC958_AES1_CON_ADC_COPYRIGHT_ID|0x00) /**< ADC with copyright information */
|
|
||||||
#define IEC958_AES1_CON_ADC_COPYRIGHT_OTHER (IEC958_AES1_CON_ADC_COPYRIGHT_ID|0x60) /**< Other ADC with copyright information product */
|
|
||||||
#define IEC958_AES1_CON_SOLIDMEM_MASK 0x0f /**< Solid memory based products mask */
|
|
||||||
#define IEC958_AES1_CON_SOLIDMEM_ID 0x08 /**< Solid memory based products ID */
|
|
||||||
#define IEC958_AES1_CON_SOLIDMEM_DIGITAL_RECORDER_PLAYER (IEC958_AES1_CON_SOLIDMEM_ID|0x00) /**< Digital audio recorder and player using solid state memory */
|
|
||||||
#define IEC958_AES1_CON_SOLIDMEM_OTHER (IEC958_AES1_CON_SOLIDMEM_ID|0x70) /**< Other solid state memory based product */
|
|
||||||
#define IEC958_AES1_CON_EXPERIMENTAL 0x40 /**< experimental category */
|
|
||||||
#define IEC958_AES1_CON_ORIGINAL (1<<7) /**< this bits depends on the category code */
|
|
||||||
#define IEC958_AES2_PRO_SBITS (7<<0) /**< mask - sample bits */
|
|
||||||
#define IEC958_AES2_PRO_SBITS_20 (2<<0) /**< 20-bit - coordination */
|
|
||||||
#define IEC958_AES2_PRO_SBITS_24 (4<<0) /**< 24-bit - main audio */
|
|
||||||
#define IEC958_AES2_PRO_SBITS_UDEF (6<<0) /**< user defined application */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN (7<<3) /**< mask - source word length */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN_NOTID (0<<3) /**< source word length not indicated */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN_22_18 (2<<3) /**< 22-bit or 18-bit */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN_23_19 (4<<3) /**< 23-bit or 19-bit */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN_24_20 (5<<3) /**< 24-bit or 20-bit */
|
|
||||||
#define IEC958_AES2_PRO_WORDLEN_20_16 (6<<3) /**< 20-bit or 16-bit */
|
|
||||||
#define IEC958_AES2_CON_SOURCE (15<<0) /**< mask - source number */
|
|
||||||
#define IEC958_AES2_CON_SOURCE_UNSPEC (0<<0) /**< source number unspecified */
|
|
||||||
#define IEC958_AES2_CON_CHANNEL (15<<4) /**< mask - channel number */
|
|
||||||
#define IEC958_AES2_CON_CHANNEL_UNSPEC (0<<4) /**< channel number unspecified */
|
|
||||||
#define IEC958_AES3_CON_FS (15<<0) /**< mask - sample frequency */
|
|
||||||
#define IEC958_AES3_CON_FS_44100 (0<<0) /**< 44.1kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_NOTID (1<<0) /**< sample frequency non indicated */
|
|
||||||
#define IEC958_AES3_CON_FS_48000 (2<<0) /**< 48kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_32000 (3<<0) /**< 32kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_22050 (4<<0) /**< 22.05kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_24000 (6<<0) /**< 24kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_88200 (8<<0) /**< 88.2kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_768000 (9<<0) /**< 768kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_96000 (10<<0) /**< 96kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_176400 (12<<0) /**< 176.4kHz */
|
|
||||||
#define IEC958_AES3_CON_FS_192000 (14<<0) /**< 192kHz */
|
|
||||||
#define IEC958_AES3_CON_CLOCK (3<<4) /**< mask - clock accuracy */
|
|
||||||
#define IEC958_AES3_CON_CLOCK_1000PPM (0<<4) /**< 1000 ppm */
|
|
||||||
#define IEC958_AES3_CON_CLOCK_50PPM (1<<4) /**< 50 ppm */
|
|
||||||
#define IEC958_AES3_CON_CLOCK_VARIABLE (2<<4) /**< variable pitch */
|
|
||||||
#define IEC958_AES4_CON_MAX_WORDLEN_24 (1<<0) /**< 0 = 20-bit, 1 = 24-bit */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN (7<<1) /**< mask - sample word length */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_NOTID (0<<1) /**< not indicated */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_20_16 (1<<1) /**< 20-bit or 16-bit */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_22_18 (2<<1) /**< 22-bit or 18-bit */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_23_19 (4<<1) /**< 23-bit or 19-bit */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_24_20 (5<<1) /**< 24-bit or 20-bit */
|
|
||||||
#define IEC958_AES4_CON_WORDLEN_21_17 (6<<1) /**< 21-bit or 17-bit */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS (15<<4) /**< mask - original sample frequency */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_NOTID (0<<4) /**< original sample frequency not indicated */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_192000 (1<<4) /**< 192kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_12000 (2<<4) /**< 12kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_176400 (3<<4) /**< 176.4kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_96000 (5<<4) /**< 96kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_8000 (6<<4) /**< 8kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_88200 (7<<4) /**< 88.2kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_16000 (8<<4) /**< 16kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_24000 (9<<4) /**< 24kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_11025 (10<<4) /**< 11.025kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_22050 (11<<4) /**< 22.05kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_32000 (12<<4) /**< 32kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_48000 (13<<4) /**< 48kHz */
|
|
||||||
#define IEC958_AES4_CON_ORIGFS_44100 (15<<4) /**< 44.1kHz */
|
|
||||||
#define IEC958_AES5_CON_CGMSA (3<<0) /**< mask - CGMS-A */
|
|
||||||
#define IEC958_AES5_CON_CGMSA_COPYFREELY (0<<0) /**< copying is permitted without restriction */
|
|
||||||
#define IEC958_AES5_CON_CGMSA_COPYONCE (1<<0) /**< one generation of copies may be made */
|
|
||||||
#define IEC958_AES5_CON_CGMSA_COPYNOMORE (2<<0) /**< condition not be used */
|
|
||||||
#define IEC958_AES5_CON_CGMSA_COPYNEVER (3<<0) /**< no copying is permitted */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup MIDI_Interface Constants for MIDI v1.0
|
|
||||||
* Constants for MIDI v1.0.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MIDI_CHANNELS 16 /**< Number of channels per port/cable. */
|
|
||||||
#define MIDI_GM_DRUM_CHANNEL (10-1) /**< Channel number for GM drums. */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup MIDI_Commands MIDI Commands
|
|
||||||
* MIDI command codes.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MIDI_CMD_NOTE_OFF 0x80 /**< note off */
|
|
||||||
#define MIDI_CMD_NOTE_ON 0x90 /**< note on */
|
|
||||||
#define MIDI_CMD_NOTE_PRESSURE 0xa0 /**< key pressure */
|
|
||||||
#define MIDI_CMD_CONTROL 0xb0 /**< control change */
|
|
||||||
#define MIDI_CMD_PGM_CHANGE 0xc0 /**< program change */
|
|
||||||
#define MIDI_CMD_CHANNEL_PRESSURE 0xd0 /**< channel pressure */
|
|
||||||
#define MIDI_CMD_BENDER 0xe0 /**< pitch bender */
|
|
||||||
|
|
||||||
#define MIDI_CMD_COMMON_SYSEX 0xf0 /**< sysex (system exclusive) begin */
|
|
||||||
#define MIDI_CMD_COMMON_MTC_QUARTER 0xf1 /**< MTC quarter frame */
|
|
||||||
#define MIDI_CMD_COMMON_SONG_POS 0xf2 /**< song position */
|
|
||||||
#define MIDI_CMD_COMMON_SONG_SELECT 0xf3 /**< song select */
|
|
||||||
#define MIDI_CMD_COMMON_TUNE_REQUEST 0xf6 /**< tune request */
|
|
||||||
#define MIDI_CMD_COMMON_SYSEX_END 0xf7 /**< end of sysex */
|
|
||||||
#define MIDI_CMD_COMMON_CLOCK 0xf8 /**< clock */
|
|
||||||
#define MIDI_CMD_COMMON_START 0xfa /**< start */
|
|
||||||
#define MIDI_CMD_COMMON_CONTINUE 0xfb /**< continue */
|
|
||||||
#define MIDI_CMD_COMMON_STOP 0xfc /**< stop */
|
|
||||||
#define MIDI_CMD_COMMON_SENSING 0xfe /**< active sensing */
|
|
||||||
#define MIDI_CMD_COMMON_RESET 0xff /**< reset */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup MIDI_Controllers MIDI Controllers
|
|
||||||
* MIDI controller numbers.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MIDI_CTL_MSB_BANK 0x00 /**< Bank selection */
|
|
||||||
#define MIDI_CTL_MSB_MODWHEEL 0x01 /**< Modulation */
|
|
||||||
#define MIDI_CTL_MSB_BREATH 0x02 /**< Breath */
|
|
||||||
#define MIDI_CTL_MSB_FOOT 0x04 /**< Foot */
|
|
||||||
#define MIDI_CTL_MSB_PORTAMENTO_TIME 0x05 /**< Portamento time */
|
|
||||||
#define MIDI_CTL_MSB_DATA_ENTRY 0x06 /**< Data entry */
|
|
||||||
#define MIDI_CTL_MSB_MAIN_VOLUME 0x07 /**< Main volume */
|
|
||||||
#define MIDI_CTL_MSB_BALANCE 0x08 /**< Balance */
|
|
||||||
#define MIDI_CTL_MSB_PAN 0x0a /**< Panpot */
|
|
||||||
#define MIDI_CTL_MSB_EXPRESSION 0x0b /**< Expression */
|
|
||||||
#define MIDI_CTL_MSB_EFFECT1 0x0c /**< Effect1 */
|
|
||||||
#define MIDI_CTL_MSB_EFFECT2 0x0d /**< Effect2 */
|
|
||||||
#define MIDI_CTL_MSB_GENERAL_PURPOSE1 0x10 /**< General purpose 1 */
|
|
||||||
#define MIDI_CTL_MSB_GENERAL_PURPOSE2 0x11 /**< General purpose 2 */
|
|
||||||
#define MIDI_CTL_MSB_GENERAL_PURPOSE3 0x12 /**< General purpose 3 */
|
|
||||||
#define MIDI_CTL_MSB_GENERAL_PURPOSE4 0x13 /**< General purpose 4 */
|
|
||||||
#define MIDI_CTL_LSB_BANK 0x20 /**< Bank selection */
|
|
||||||
#define MIDI_CTL_LSB_MODWHEEL 0x21 /**< Modulation */
|
|
||||||
#define MIDI_CTL_LSB_BREATH 0x22 /**< Breath */
|
|
||||||
#define MIDI_CTL_LSB_FOOT 0x24 /**< Foot */
|
|
||||||
#define MIDI_CTL_LSB_PORTAMENTO_TIME 0x25 /**< Portamento time */
|
|
||||||
#define MIDI_CTL_LSB_DATA_ENTRY 0x26 /**< Data entry */
|
|
||||||
#define MIDI_CTL_LSB_MAIN_VOLUME 0x27 /**< Main volume */
|
|
||||||
#define MIDI_CTL_LSB_BALANCE 0x28 /**< Balance */
|
|
||||||
#define MIDI_CTL_LSB_PAN 0x2a /**< Panpot */
|
|
||||||
#define MIDI_CTL_LSB_EXPRESSION 0x2b /**< Expression */
|
|
||||||
#define MIDI_CTL_LSB_EFFECT1 0x2c /**< Effect1 */
|
|
||||||
#define MIDI_CTL_LSB_EFFECT2 0x2d /**< Effect2 */
|
|
||||||
#define MIDI_CTL_LSB_GENERAL_PURPOSE1 0x30 /**< General purpose 1 */
|
|
||||||
#define MIDI_CTL_LSB_GENERAL_PURPOSE2 0x31 /**< General purpose 2 */
|
|
||||||
#define MIDI_CTL_LSB_GENERAL_PURPOSE3 0x32 /**< General purpose 3 */
|
|
||||||
#define MIDI_CTL_LSB_GENERAL_PURPOSE4 0x33 /**< General purpose 4 */
|
|
||||||
#define MIDI_CTL_SUSTAIN 0x40 /**< Sustain pedal */
|
|
||||||
#define MIDI_CTL_PORTAMENTO 0x41 /**< Portamento */
|
|
||||||
#define MIDI_CTL_SOSTENUTO 0x42 /**< Sostenuto */
|
|
||||||
#define MIDI_CTL_SUSTENUTO 0x42 /**< Sostenuto (a typo in the older version) */
|
|
||||||
#define MIDI_CTL_SOFT_PEDAL 0x43 /**< Soft pedal */
|
|
||||||
#define MIDI_CTL_LEGATO_FOOTSWITCH 0x44 /**< Legato foot switch */
|
|
||||||
#define MIDI_CTL_HOLD2 0x45 /**< Hold2 */
|
|
||||||
#define MIDI_CTL_SC1_SOUND_VARIATION 0x46 /**< SC1 Sound Variation */
|
|
||||||
#define MIDI_CTL_SC2_TIMBRE 0x47 /**< SC2 Timbre */
|
|
||||||
#define MIDI_CTL_SC3_RELEASE_TIME 0x48 /**< SC3 Release Time */
|
|
||||||
#define MIDI_CTL_SC4_ATTACK_TIME 0x49 /**< SC4 Attack Time */
|
|
||||||
#define MIDI_CTL_SC5_BRIGHTNESS 0x4a /**< SC5 Brightness */
|
|
||||||
#define MIDI_CTL_SC6 0x4b /**< SC6 */
|
|
||||||
#define MIDI_CTL_SC7 0x4c /**< SC7 */
|
|
||||||
#define MIDI_CTL_SC8 0x4d /**< SC8 */
|
|
||||||
#define MIDI_CTL_SC9 0x4e /**< SC9 */
|
|
||||||
#define MIDI_CTL_SC10 0x4f /**< SC10 */
|
|
||||||
#define MIDI_CTL_GENERAL_PURPOSE5 0x50 /**< General purpose 5 */
|
|
||||||
#define MIDI_CTL_GENERAL_PURPOSE6 0x51 /**< General purpose 6 */
|
|
||||||
#define MIDI_CTL_GENERAL_PURPOSE7 0x52 /**< General purpose 7 */
|
|
||||||
#define MIDI_CTL_GENERAL_PURPOSE8 0x53 /**< General purpose 8 */
|
|
||||||
#define MIDI_CTL_PORTAMENTO_CONTROL 0x54 /**< Portamento control */
|
|
||||||
#define MIDI_CTL_E1_REVERB_DEPTH 0x5b /**< E1 Reverb Depth */
|
|
||||||
#define MIDI_CTL_E2_TREMOLO_DEPTH 0x5c /**< E2 Tremolo Depth */
|
|
||||||
#define MIDI_CTL_E3_CHORUS_DEPTH 0x5d /**< E3 Chorus Depth */
|
|
||||||
#define MIDI_CTL_E4_DETUNE_DEPTH 0x5e /**< E4 Detune Depth */
|
|
||||||
#define MIDI_CTL_E5_PHASER_DEPTH 0x5f /**< E5 Phaser Depth */
|
|
||||||
#define MIDI_CTL_DATA_INCREMENT 0x60 /**< Data Increment */
|
|
||||||
#define MIDI_CTL_DATA_DECREMENT 0x61 /**< Data Decrement */
|
|
||||||
#define MIDI_CTL_NONREG_PARM_NUM_LSB 0x62 /**< Non-registered parameter number */
|
|
||||||
#define MIDI_CTL_NONREG_PARM_NUM_MSB 0x63 /**< Non-registered parameter number */
|
|
||||||
#define MIDI_CTL_REGIST_PARM_NUM_LSB 0x64 /**< Registered parameter number */
|
|
||||||
#define MIDI_CTL_REGIST_PARM_NUM_MSB 0x65 /**< Registered parameter number */
|
|
||||||
#define MIDI_CTL_ALL_SOUNDS_OFF 0x78 /**< All sounds off */
|
|
||||||
#define MIDI_CTL_RESET_CONTROLLERS 0x79 /**< Reset Controllers */
|
|
||||||
#define MIDI_CTL_LOCAL_CONTROL_SWITCH 0x7a /**< Local control switch */
|
|
||||||
#define MIDI_CTL_ALL_NOTES_OFF 0x7b /**< All notes off */
|
|
||||||
#define MIDI_CTL_OMNI_OFF 0x7c /**< Omni off */
|
|
||||||
#define MIDI_CTL_OMNI_ON 0x7d /**< Omni on */
|
|
||||||
#define MIDI_CTL_MONO1 0x7e /**< Mono1 */
|
|
||||||
#define MIDI_CTL_MONO2 0x7f /**< Mono2 */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_ASOUNDEF_H */
|
|
65
raylib/external/alsa/asoundlib.h
vendored
65
raylib/external/alsa/asoundlib.h
vendored
|
@ -1,65 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/asoundlib.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ASOUNDLIB_H
|
|
||||||
#define __ASOUNDLIB_H
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <poll.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <endian.h>
|
|
||||||
|
|
||||||
#ifndef __GNUC__
|
|
||||||
#define __inline__ inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <alsa/asoundef.h>
|
|
||||||
#include <alsa/version.h>
|
|
||||||
#include <alsa/global.h>
|
|
||||||
#include <alsa/input.h>
|
|
||||||
#include <alsa/output.h>
|
|
||||||
#include <alsa/error.h>
|
|
||||||
#include <alsa/conf.h>
|
|
||||||
#include <alsa/pcm.h>
|
|
||||||
#include <alsa/rawmidi.h>
|
|
||||||
#include <alsa/timer.h>
|
|
||||||
#include <alsa/hwdep.h>
|
|
||||||
#include <alsa/control.h>
|
|
||||||
#include <alsa/mixer.h>
|
|
||||||
#include <alsa/seq_event.h>
|
|
||||||
#include <alsa/seq.h>
|
|
||||||
#include <alsa/seqmid.h>
|
|
||||||
#include <alsa/seq_midi_event.h>
|
|
||||||
|
|
||||||
#endif /* __ASOUNDLIB_H */
|
|
214
raylib/external/alsa/conf.h
vendored
214
raylib/external/alsa/conf.h
vendored
|
@ -1,214 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/conf.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_CONF_H
|
|
||||||
#define __ALSA_CONF_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Config Configuration Interface
|
|
||||||
* The configuration functions and types allow you to read, enumerate,
|
|
||||||
* modify and write the contents of ALSA configuration files.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** \brief \c dlsym version for the config evaluate callback. */
|
|
||||||
#define SND_CONFIG_DLSYM_VERSION_EVALUATE _dlsym_config_evaluate_001
|
|
||||||
/** \brief \c dlsym version for the config hook callback. */
|
|
||||||
#define SND_CONFIG_DLSYM_VERSION_HOOK _dlsym_config_hook_001
|
|
||||||
|
|
||||||
/** \brief Configuration node type. */
|
|
||||||
typedef enum _snd_config_type {
|
|
||||||
/** Integer number. */
|
|
||||||
SND_CONFIG_TYPE_INTEGER,
|
|
||||||
/** 64-bit integer number. */
|
|
||||||
SND_CONFIG_TYPE_INTEGER64,
|
|
||||||
/** Real number. */
|
|
||||||
SND_CONFIG_TYPE_REAL,
|
|
||||||
/** Character string. */
|
|
||||||
SND_CONFIG_TYPE_STRING,
|
|
||||||
/** Pointer (runtime only, cannot be saved). */
|
|
||||||
SND_CONFIG_TYPE_POINTER,
|
|
||||||
/** Compound node. */
|
|
||||||
SND_CONFIG_TYPE_COMPOUND = 1024
|
|
||||||
} snd_config_type_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Internal structure for a configuration node object.
|
|
||||||
*
|
|
||||||
* The ALSA library uses a pointer to this structure as a handle to a
|
|
||||||
* configuration node. Applications don't access its contents directly.
|
|
||||||
*/
|
|
||||||
typedef struct _snd_config snd_config_t;
|
|
||||||
/**
|
|
||||||
* \brief Type for a configuration compound iterator.
|
|
||||||
*
|
|
||||||
* The ALSA library uses this pointer type as a handle to a configuration
|
|
||||||
* compound iterator. Applications don't directly access the contents of
|
|
||||||
* the structure pointed to by this type.
|
|
||||||
*/
|
|
||||||
typedef struct _snd_config_iterator *snd_config_iterator_t;
|
|
||||||
/**
|
|
||||||
* \brief Internal structure for a configuration private update object.
|
|
||||||
*
|
|
||||||
* The ALSA library uses this structure to save private update information.
|
|
||||||
*/
|
|
||||||
typedef struct _snd_config_update snd_config_update_t;
|
|
||||||
|
|
||||||
extern snd_config_t *snd_config;
|
|
||||||
|
|
||||||
const char *snd_config_topdir(void);
|
|
||||||
|
|
||||||
int snd_config_top(snd_config_t **config);
|
|
||||||
|
|
||||||
int snd_config_load(snd_config_t *config, snd_input_t *in);
|
|
||||||
int snd_config_load_override(snd_config_t *config, snd_input_t *in);
|
|
||||||
int snd_config_save(snd_config_t *config, snd_output_t *out);
|
|
||||||
int snd_config_update(void);
|
|
||||||
int snd_config_update_r(snd_config_t **top, snd_config_update_t **update, const char *path);
|
|
||||||
int snd_config_update_free(snd_config_update_t *update);
|
|
||||||
int snd_config_update_free_global(void);
|
|
||||||
|
|
||||||
int snd_config_update_ref(snd_config_t **top);
|
|
||||||
void snd_config_ref(snd_config_t *top);
|
|
||||||
void snd_config_unref(snd_config_t *top);
|
|
||||||
|
|
||||||
int snd_config_search(snd_config_t *config, const char *key,
|
|
||||||
snd_config_t **result);
|
|
||||||
int snd_config_searchv(snd_config_t *config,
|
|
||||||
snd_config_t **result, ...);
|
|
||||||
int snd_config_search_definition(snd_config_t *config,
|
|
||||||
const char *base, const char *key,
|
|
||||||
snd_config_t **result);
|
|
||||||
|
|
||||||
int snd_config_expand(snd_config_t *config, snd_config_t *root,
|
|
||||||
const char *args, snd_config_t *private_data,
|
|
||||||
snd_config_t **result);
|
|
||||||
int snd_config_evaluate(snd_config_t *config, snd_config_t *root,
|
|
||||||
snd_config_t *private_data, snd_config_t **result);
|
|
||||||
|
|
||||||
int snd_config_add(snd_config_t *config, snd_config_t *leaf);
|
|
||||||
int snd_config_delete(snd_config_t *config);
|
|
||||||
int snd_config_delete_compound_members(const snd_config_t *config);
|
|
||||||
int snd_config_copy(snd_config_t **dst, snd_config_t *src);
|
|
||||||
|
|
||||||
int snd_config_make(snd_config_t **config, const char *key,
|
|
||||||
snd_config_type_t type);
|
|
||||||
int snd_config_make_integer(snd_config_t **config, const char *key);
|
|
||||||
int snd_config_make_integer64(snd_config_t **config, const char *key);
|
|
||||||
int snd_config_make_real(snd_config_t **config, const char *key);
|
|
||||||
int snd_config_make_string(snd_config_t **config, const char *key);
|
|
||||||
int snd_config_make_pointer(snd_config_t **config, const char *key);
|
|
||||||
int snd_config_make_compound(snd_config_t **config, const char *key, int join);
|
|
||||||
|
|
||||||
int snd_config_imake_integer(snd_config_t **config, const char *key, const long value);
|
|
||||||
int snd_config_imake_integer64(snd_config_t **config, const char *key, const long long value);
|
|
||||||
int snd_config_imake_real(snd_config_t **config, const char *key, const double value);
|
|
||||||
int snd_config_imake_string(snd_config_t **config, const char *key, const char *ascii);
|
|
||||||
int snd_config_imake_safe_string(snd_config_t **config, const char *key, const char *ascii);
|
|
||||||
int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr);
|
|
||||||
|
|
||||||
snd_config_type_t snd_config_get_type(const snd_config_t *config);
|
|
||||||
|
|
||||||
int snd_config_set_id(snd_config_t *config, const char *id);
|
|
||||||
int snd_config_set_integer(snd_config_t *config, long value);
|
|
||||||
int snd_config_set_integer64(snd_config_t *config, long long value);
|
|
||||||
int snd_config_set_real(snd_config_t *config, double value);
|
|
||||||
int snd_config_set_string(snd_config_t *config, const char *value);
|
|
||||||
int snd_config_set_ascii(snd_config_t *config, const char *ascii);
|
|
||||||
int snd_config_set_pointer(snd_config_t *config, const void *ptr);
|
|
||||||
int snd_config_get_id(const snd_config_t *config, const char **value);
|
|
||||||
int snd_config_get_integer(const snd_config_t *config, long *value);
|
|
||||||
int snd_config_get_integer64(const snd_config_t *config, long long *value);
|
|
||||||
int snd_config_get_real(const snd_config_t *config, double *value);
|
|
||||||
int snd_config_get_ireal(const snd_config_t *config, double *value);
|
|
||||||
int snd_config_get_string(const snd_config_t *config, const char **value);
|
|
||||||
int snd_config_get_ascii(const snd_config_t *config, char **value);
|
|
||||||
int snd_config_get_pointer(const snd_config_t *config, const void **value);
|
|
||||||
int snd_config_test_id(const snd_config_t *config, const char *id);
|
|
||||||
|
|
||||||
snd_config_iterator_t snd_config_iterator_first(const snd_config_t *node);
|
|
||||||
snd_config_iterator_t snd_config_iterator_next(const snd_config_iterator_t iterator);
|
|
||||||
snd_config_iterator_t snd_config_iterator_end(const snd_config_t *node);
|
|
||||||
snd_config_t *snd_config_iterator_entry(const snd_config_iterator_t iterator);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Helper macro to iterate over the children of a compound node.
|
|
||||||
* \param[in,out] pos Iterator variable for the current node.
|
|
||||||
* \param[in,out] next Temporary iterator variable for the next node.
|
|
||||||
* \param[in] node Handle to the compound configuration node to iterate over.
|
|
||||||
*
|
|
||||||
* Use this macro like a \c for statement, e.g.:
|
|
||||||
* \code
|
|
||||||
* snd_config_iterator_t pos, next;
|
|
||||||
* snd_config_for_each(pos, next, node) {
|
|
||||||
* snd_config_t *entry = snd_config_iterator_entry(pos);
|
|
||||||
* ...
|
|
||||||
* }
|
|
||||||
* \endcode
|
|
||||||
*
|
|
||||||
* This macro allows deleting or removing the current node.
|
|
||||||
*/
|
|
||||||
#define snd_config_for_each(pos, next, node) \
|
|
||||||
for (pos = snd_config_iterator_first(node), next = snd_config_iterator_next(pos); pos != snd_config_iterator_end(node); pos = next, next = snd_config_iterator_next(pos))
|
|
||||||
|
|
||||||
/* Misc functions */
|
|
||||||
|
|
||||||
int snd_config_get_bool_ascii(const char *ascii);
|
|
||||||
int snd_config_get_bool(const snd_config_t *conf);
|
|
||||||
int snd_config_get_ctl_iface_ascii(const char *ascii);
|
|
||||||
int snd_config_get_ctl_iface(const snd_config_t *conf);
|
|
||||||
|
|
||||||
/* Names functions */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device-name list element
|
|
||||||
*/
|
|
||||||
typedef struct snd_devname snd_devname_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Device-name list element (definition)
|
|
||||||
*/
|
|
||||||
struct snd_devname {
|
|
||||||
char *name; /**< Device name string */
|
|
||||||
char *comment; /**< Comments */
|
|
||||||
snd_devname_t *next; /**< Next pointer */
|
|
||||||
};
|
|
||||||
|
|
||||||
int snd_names_list(const char *iface, snd_devname_t **list);
|
|
||||||
void snd_names_list_free(snd_devname_t *list);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_CONF_H */
|
|
622
raylib/external/alsa/control.h
vendored
622
raylib/external/alsa/control.h
vendored
|
@ -1,622 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/control.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_CONTROL_H
|
|
||||||
#define __ALSA_CONTROL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Control Control Interface
|
|
||||||
* The control interface.
|
|
||||||
* See \ref control page for more details.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** dlsym version for interface entry callback */
|
|
||||||
#define SND_CONTROL_DLSYM_VERSION _dlsym_control_001
|
|
||||||
|
|
||||||
/** IEC958 structure */
|
|
||||||
typedef struct snd_aes_iec958 {
|
|
||||||
unsigned char status[24]; /**< AES/IEC958 channel status bits */
|
|
||||||
unsigned char subcode[147]; /**< AES/IEC958 subcode bits */
|
|
||||||
unsigned char pad; /**< nothing */
|
|
||||||
unsigned char dig_subframe[4]; /**< AES/IEC958 subframe bits */
|
|
||||||
} snd_aes_iec958_t;
|
|
||||||
|
|
||||||
/** CTL card info container */
|
|
||||||
typedef struct _snd_ctl_card_info snd_ctl_card_info_t;
|
|
||||||
|
|
||||||
/** CTL element identifier container */
|
|
||||||
typedef struct _snd_ctl_elem_id snd_ctl_elem_id_t;
|
|
||||||
|
|
||||||
/** CTL element identifier list container */
|
|
||||||
typedef struct _snd_ctl_elem_list snd_ctl_elem_list_t;
|
|
||||||
|
|
||||||
/** CTL element info container */
|
|
||||||
typedef struct _snd_ctl_elem_info snd_ctl_elem_info_t;
|
|
||||||
|
|
||||||
/** CTL element value container */
|
|
||||||
typedef struct _snd_ctl_elem_value snd_ctl_elem_value_t;
|
|
||||||
|
|
||||||
/** CTL event container */
|
|
||||||
typedef struct _snd_ctl_event snd_ctl_event_t;
|
|
||||||
|
|
||||||
/** CTL element type */
|
|
||||||
typedef enum _snd_ctl_elem_type {
|
|
||||||
/** Invalid type */
|
|
||||||
SND_CTL_ELEM_TYPE_NONE = 0,
|
|
||||||
/** Boolean contents */
|
|
||||||
SND_CTL_ELEM_TYPE_BOOLEAN,
|
|
||||||
/** Integer contents */
|
|
||||||
SND_CTL_ELEM_TYPE_INTEGER,
|
|
||||||
/** Enumerated contents */
|
|
||||||
SND_CTL_ELEM_TYPE_ENUMERATED,
|
|
||||||
/** Bytes contents */
|
|
||||||
SND_CTL_ELEM_TYPE_BYTES,
|
|
||||||
/** IEC958 (S/PDIF) setting content */
|
|
||||||
SND_CTL_ELEM_TYPE_IEC958,
|
|
||||||
/** 64-bit integer contents */
|
|
||||||
SND_CTL_ELEM_TYPE_INTEGER64,
|
|
||||||
SND_CTL_ELEM_TYPE_LAST = SND_CTL_ELEM_TYPE_INTEGER64
|
|
||||||
} snd_ctl_elem_type_t;
|
|
||||||
|
|
||||||
/** CTL related interface */
|
|
||||||
typedef enum _snd_ctl_elem_iface {
|
|
||||||
/** Card level */
|
|
||||||
SND_CTL_ELEM_IFACE_CARD = 0,
|
|
||||||
/** Hardware dependent device */
|
|
||||||
SND_CTL_ELEM_IFACE_HWDEP,
|
|
||||||
/** Mixer */
|
|
||||||
SND_CTL_ELEM_IFACE_MIXER,
|
|
||||||
/** PCM */
|
|
||||||
SND_CTL_ELEM_IFACE_PCM,
|
|
||||||
/** RawMidi */
|
|
||||||
SND_CTL_ELEM_IFACE_RAWMIDI,
|
|
||||||
/** Timer */
|
|
||||||
SND_CTL_ELEM_IFACE_TIMER,
|
|
||||||
/** Sequencer */
|
|
||||||
SND_CTL_ELEM_IFACE_SEQUENCER,
|
|
||||||
SND_CTL_ELEM_IFACE_LAST = SND_CTL_ELEM_IFACE_SEQUENCER
|
|
||||||
} snd_ctl_elem_iface_t;
|
|
||||||
|
|
||||||
/** Event class */
|
|
||||||
typedef enum _snd_ctl_event_type {
|
|
||||||
/** Elements related event */
|
|
||||||
SND_CTL_EVENT_ELEM = 0,
|
|
||||||
SND_CTL_EVENT_LAST = SND_CTL_EVENT_ELEM
|
|
||||||
}snd_ctl_event_type_t;
|
|
||||||
|
|
||||||
/** Element has been removed (Warning: test this first and if set don't
|
|
||||||
* test the other masks) \hideinitializer */
|
|
||||||
#define SND_CTL_EVENT_MASK_REMOVE (~0U)
|
|
||||||
/** Element value has been changed \hideinitializer */
|
|
||||||
#define SND_CTL_EVENT_MASK_VALUE (1<<0)
|
|
||||||
/** Element info has been changed \hideinitializer */
|
|
||||||
#define SND_CTL_EVENT_MASK_INFO (1<<1)
|
|
||||||
/** Element has been added \hideinitializer */
|
|
||||||
#define SND_CTL_EVENT_MASK_ADD (1<<2)
|
|
||||||
/** Element's TLV value has been changed \hideinitializer */
|
|
||||||
#define SND_CTL_EVENT_MASK_TLV (1<<3)
|
|
||||||
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_NONE ""
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_PLAYBACK "Playback "
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_CAPTURE "Capture "
|
|
||||||
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_NONE ""
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_SWITCH "Switch"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_VOLUME "Volume"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_DEFAULT "Default"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_MASK "Mask"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_CON_MASK "Con Mask"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_PRO_MASK "Pro Mask"
|
|
||||||
/** CTL name helper */
|
|
||||||
#define SND_CTL_NAME_IEC958_PCM_STREAM "PCM Stream"
|
|
||||||
/** Element name for IEC958 (S/PDIF) */
|
|
||||||
#define SND_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SND_CTL_NAME_##direction SND_CTL_NAME_IEC958_##what
|
|
||||||
|
|
||||||
/** Mask for the major Power State identifier */
|
|
||||||
#define SND_CTL_POWER_MASK 0xff00
|
|
||||||
/** ACPI/PCI Power State D0 */
|
|
||||||
#define SND_CTL_POWER_D0 0x0000
|
|
||||||
/** ACPI/PCI Power State D1 */
|
|
||||||
#define SND_CTL_POWER_D1 0x0100
|
|
||||||
/** ACPI/PCI Power State D2 */
|
|
||||||
#define SND_CTL_POWER_D2 0x0200
|
|
||||||
/** ACPI/PCI Power State D3 */
|
|
||||||
#define SND_CTL_POWER_D3 0x0300
|
|
||||||
/** ACPI/PCI Power State D3hot */
|
|
||||||
#define SND_CTL_POWER_D3hot (SND_CTL_POWER_D3|0x0000)
|
|
||||||
/** ACPI/PCI Power State D3cold */
|
|
||||||
#define SND_CTL_POWER_D3cold (SND_CTL_POWER_D3|0x0001)
|
|
||||||
|
|
||||||
/** TLV type - Container */
|
|
||||||
#define SND_CTL_TLVT_CONTAINER 0x0000
|
|
||||||
/** TLV type - basic dB scale */
|
|
||||||
#define SND_CTL_TLVT_DB_SCALE 0x0001
|
|
||||||
/** TLV type - linear volume */
|
|
||||||
#define SND_CTL_TLVT_DB_LINEAR 0x0002
|
|
||||||
/** TLV type - dB range container */
|
|
||||||
#define SND_CTL_TLVT_DB_RANGE 0x0003
|
|
||||||
/** TLV type - dB scale specified by min/max values */
|
|
||||||
#define SND_CTL_TLVT_DB_MINMAX 0x0004
|
|
||||||
/** TLV type - dB scale specified by min/max values (with mute) */
|
|
||||||
#define SND_CTL_TLVT_DB_MINMAX_MUTE 0x0005
|
|
||||||
|
|
||||||
/** Mute state */
|
|
||||||
#define SND_CTL_TLV_DB_GAIN_MUTE -9999999
|
|
||||||
|
|
||||||
/** TLV type - fixed channel map positions */
|
|
||||||
#define SND_CTL_TLVT_CHMAP_FIXED 0x00101
|
|
||||||
/** TLV type - freely swappable channel map positions */
|
|
||||||
#define SND_CTL_TLVT_CHMAP_VAR 0x00102
|
|
||||||
/** TLV type - pair-wise swappable channel map positions */
|
|
||||||
#define SND_CTL_TLVT_CHMAP_PAIRED 0x00103
|
|
||||||
|
|
||||||
/** CTL type */
|
|
||||||
typedef enum _snd_ctl_type {
|
|
||||||
/** Kernel level CTL */
|
|
||||||
SND_CTL_TYPE_HW,
|
|
||||||
/** Shared memory client CTL */
|
|
||||||
SND_CTL_TYPE_SHM,
|
|
||||||
/** INET client CTL (not yet implemented) */
|
|
||||||
SND_CTL_TYPE_INET,
|
|
||||||
/** External control plugin */
|
|
||||||
SND_CTL_TYPE_EXT
|
|
||||||
} snd_ctl_type_t;
|
|
||||||
|
|
||||||
/** Non blocking mode (flag for open mode) \hideinitializer */
|
|
||||||
#define SND_CTL_NONBLOCK 0x0001
|
|
||||||
|
|
||||||
/** Async notification (flag for open mode) \hideinitializer */
|
|
||||||
#define SND_CTL_ASYNC 0x0002
|
|
||||||
|
|
||||||
/** Read only (flag for open mode) \hideinitializer */
|
|
||||||
#define SND_CTL_READONLY 0x0004
|
|
||||||
|
|
||||||
/** CTL handle */
|
|
||||||
typedef struct _snd_ctl snd_ctl_t;
|
|
||||||
|
|
||||||
/** Don't destroy the ctl handle when close */
|
|
||||||
#define SND_SCTL_NOFREE 0x0001
|
|
||||||
|
|
||||||
/** SCTL type */
|
|
||||||
typedef struct _snd_sctl snd_sctl_t;
|
|
||||||
|
|
||||||
int snd_card_load(int card);
|
|
||||||
int snd_card_next(int *card);
|
|
||||||
int snd_card_get_index(const char *name);
|
|
||||||
int snd_card_get_name(int card, char **name);
|
|
||||||
int snd_card_get_longname(int card, char **name);
|
|
||||||
|
|
||||||
int snd_device_name_hint(int card, const char *iface, void ***hints);
|
|
||||||
int snd_device_name_free_hint(void **hints);
|
|
||||||
char *snd_device_name_get_hint(const void *hint, const char *id);
|
|
||||||
|
|
||||||
int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode);
|
|
||||||
int snd_ctl_open_lconf(snd_ctl_t **ctl, const char *name, int mode, snd_config_t *lconf);
|
|
||||||
int snd_ctl_open_fallback(snd_ctl_t **ctl, snd_config_t *root, const char *name, const char *orig_name, int mode);
|
|
||||||
int snd_ctl_close(snd_ctl_t *ctl);
|
|
||||||
int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock);
|
|
||||||
static __inline__ int snd_ctl_abort(snd_ctl_t *ctl) { return snd_ctl_nonblock(ctl, 2); }
|
|
||||||
int snd_async_add_ctl_handler(snd_async_handler_t **handler, snd_ctl_t *ctl,
|
|
||||||
snd_async_callback_t callback, void *private_data);
|
|
||||||
snd_ctl_t *snd_async_handler_get_ctl(snd_async_handler_t *handler);
|
|
||||||
int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl);
|
|
||||||
int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space);
|
|
||||||
int snd_ctl_poll_descriptors_revents(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
|
||||||
int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe);
|
|
||||||
int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info);
|
|
||||||
int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list);
|
|
||||||
int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
|
|
||||||
int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
|
|
||||||
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
|
|
||||||
int snd_ctl_elem_lock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
|
|
||||||
int snd_ctl_elem_unlock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
|
|
||||||
int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
unsigned int *tlv, unsigned int tlv_size);
|
|
||||||
int snd_ctl_elem_tlv_write(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
const unsigned int *tlv);
|
|
||||||
int snd_ctl_elem_tlv_command(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
const unsigned int *tlv);
|
|
||||||
#ifdef __ALSA_HWDEP_H
|
|
||||||
int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int * device);
|
|
||||||
int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info);
|
|
||||||
#endif
|
|
||||||
#ifdef __ALSA_PCM_H
|
|
||||||
int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device);
|
|
||||||
int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info);
|
|
||||||
int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev);
|
|
||||||
#endif
|
|
||||||
#ifdef __ALSA_RAWMIDI_H
|
|
||||||
int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device);
|
|
||||||
int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info);
|
|
||||||
int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev);
|
|
||||||
#endif
|
|
||||||
int snd_ctl_set_power_state(snd_ctl_t *ctl, unsigned int state);
|
|
||||||
int snd_ctl_get_power_state(snd_ctl_t *ctl, unsigned int *state);
|
|
||||||
|
|
||||||
int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_event_t *event);
|
|
||||||
int snd_ctl_wait(snd_ctl_t *ctl, int timeout);
|
|
||||||
const char *snd_ctl_name(snd_ctl_t *ctl);
|
|
||||||
snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl);
|
|
||||||
|
|
||||||
const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type);
|
|
||||||
const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface);
|
|
||||||
const char *snd_ctl_event_type_name(snd_ctl_event_type_t type);
|
|
||||||
|
|
||||||
unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj);
|
|
||||||
unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj);
|
|
||||||
void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr);
|
|
||||||
snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj);
|
|
||||||
unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj);
|
|
||||||
unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj);
|
|
||||||
const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj);
|
|
||||||
unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj);
|
|
||||||
|
|
||||||
int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries);
|
|
||||||
void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj);
|
|
||||||
|
|
||||||
char *snd_ctl_ascii_elem_id_get(snd_ctl_elem_id_t *id);
|
|
||||||
int snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str);
|
|
||||||
int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
|
|
||||||
snd_ctl_elem_value_t *dst,
|
|
||||||
snd_ctl_elem_info_t *info,
|
|
||||||
const char *value);
|
|
||||||
|
|
||||||
size_t snd_ctl_elem_id_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_elem_id_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_elem_id_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_id)
|
|
||||||
int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr);
|
|
||||||
void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj);
|
|
||||||
void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj);
|
|
||||||
void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src);
|
|
||||||
unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj);
|
|
||||||
snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_id_get_device(const snd_ctl_elem_id_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_id_get_subdevice(const snd_ctl_elem_id_t *obj);
|
|
||||||
const char *snd_ctl_elem_id_get_name(const snd_ctl_elem_id_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_id_get_index(const snd_ctl_elem_id_t *obj);
|
|
||||||
void snd_ctl_elem_id_set_numid(snd_ctl_elem_id_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t *obj, snd_ctl_elem_iface_t val);
|
|
||||||
void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_id_set_subdevice(snd_ctl_elem_id_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val);
|
|
||||||
void snd_ctl_elem_id_set_index(snd_ctl_elem_id_t *obj, unsigned int val);
|
|
||||||
|
|
||||||
size_t snd_ctl_card_info_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_card_info_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_card_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_card_info)
|
|
||||||
int snd_ctl_card_info_malloc(snd_ctl_card_info_t **ptr);
|
|
||||||
void snd_ctl_card_info_free(snd_ctl_card_info_t *obj);
|
|
||||||
void snd_ctl_card_info_clear(snd_ctl_card_info_t *obj);
|
|
||||||
void snd_ctl_card_info_copy(snd_ctl_card_info_t *dst, const snd_ctl_card_info_t *src);
|
|
||||||
int snd_ctl_card_info_get_card(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_id(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_driver(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_name(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_longname(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_mixername(const snd_ctl_card_info_t *obj);
|
|
||||||
const char *snd_ctl_card_info_get_components(const snd_ctl_card_info_t *obj);
|
|
||||||
|
|
||||||
size_t snd_ctl_event_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_event_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_event_alloca(ptr) __snd_alloca(ptr, snd_ctl_event)
|
|
||||||
int snd_ctl_event_malloc(snd_ctl_event_t **ptr);
|
|
||||||
void snd_ctl_event_free(snd_ctl_event_t *obj);
|
|
||||||
void snd_ctl_event_clear(snd_ctl_event_t *obj);
|
|
||||||
void snd_ctl_event_copy(snd_ctl_event_t *dst, const snd_ctl_event_t *src);
|
|
||||||
snd_ctl_event_type_t snd_ctl_event_get_type(const snd_ctl_event_t *obj);
|
|
||||||
|
|
||||||
size_t snd_ctl_elem_list_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_elem_list_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_elem_list_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_list)
|
|
||||||
int snd_ctl_elem_list_malloc(snd_ctl_elem_list_t **ptr);
|
|
||||||
void snd_ctl_elem_list_free(snd_ctl_elem_list_t *obj);
|
|
||||||
void snd_ctl_elem_list_clear(snd_ctl_elem_list_t *obj);
|
|
||||||
void snd_ctl_elem_list_copy(snd_ctl_elem_list_t *dst, const snd_ctl_elem_list_t *src);
|
|
||||||
void snd_ctl_elem_list_set_offset(snd_ctl_elem_list_t *obj, unsigned int val);
|
|
||||||
unsigned int snd_ctl_elem_list_get_used(const snd_ctl_elem_list_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_list_get_count(const snd_ctl_elem_list_t *obj);
|
|
||||||
void snd_ctl_elem_list_get_id(const snd_ctl_elem_list_t *obj, unsigned int idx, snd_ctl_elem_id_t *ptr);
|
|
||||||
unsigned int snd_ctl_elem_list_get_numid(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
snd_ctl_elem_iface_t snd_ctl_elem_list_get_interface(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
unsigned int snd_ctl_elem_list_get_device(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
unsigned int snd_ctl_elem_list_get_subdevice(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
const char *snd_ctl_elem_list_get_name(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
unsigned int snd_ctl_elem_list_get_index(const snd_ctl_elem_list_t *obj, unsigned int idx);
|
|
||||||
|
|
||||||
size_t snd_ctl_elem_info_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_elem_info_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_elem_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_info)
|
|
||||||
int snd_ctl_elem_info_malloc(snd_ctl_elem_info_t **ptr);
|
|
||||||
void snd_ctl_elem_info_free(snd_ctl_elem_info_t *obj);
|
|
||||||
void snd_ctl_elem_info_clear(snd_ctl_elem_info_t *obj);
|
|
||||||
void snd_ctl_elem_info_copy(snd_ctl_elem_info_t *dst, const snd_ctl_elem_info_t *src);
|
|
||||||
snd_ctl_elem_type_t snd_ctl_elem_info_get_type(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_readable(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_writable(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_volatile(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_inactive(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_locked(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_tlv_readable(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_tlv_writable(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_tlv_commandable(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_owner(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj);
|
|
||||||
pid_t snd_ctl_elem_info_get_owner(const snd_ctl_elem_info_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_info_get_count(const snd_ctl_elem_info_t *obj);
|
|
||||||
long snd_ctl_elem_info_get_min(const snd_ctl_elem_info_t *obj);
|
|
||||||
long snd_ctl_elem_info_get_max(const snd_ctl_elem_info_t *obj);
|
|
||||||
long snd_ctl_elem_info_get_step(const snd_ctl_elem_info_t *obj);
|
|
||||||
long long snd_ctl_elem_info_get_min64(const snd_ctl_elem_info_t *obj);
|
|
||||||
long long snd_ctl_elem_info_get_max64(const snd_ctl_elem_info_t *obj);
|
|
||||||
long long snd_ctl_elem_info_get_step64(const snd_ctl_elem_info_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_info_get_items(const snd_ctl_elem_info_t *obj);
|
|
||||||
void snd_ctl_elem_info_set_item(snd_ctl_elem_info_t *obj, unsigned int val);
|
|
||||||
const char *snd_ctl_elem_info_get_item_name(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_get_dimensions(const snd_ctl_elem_info_t *obj);
|
|
||||||
int snd_ctl_elem_info_get_dimension(const snd_ctl_elem_info_t *obj, unsigned int idx);
|
|
||||||
int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info,
|
|
||||||
const int dimension[4]);
|
|
||||||
void snd_ctl_elem_info_get_id(const snd_ctl_elem_info_t *obj, snd_ctl_elem_id_t *ptr);
|
|
||||||
unsigned int snd_ctl_elem_info_get_numid(const snd_ctl_elem_info_t *obj);
|
|
||||||
snd_ctl_elem_iface_t snd_ctl_elem_info_get_interface(const snd_ctl_elem_info_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_info_get_device(const snd_ctl_elem_info_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_info_get_subdevice(const snd_ctl_elem_info_t *obj);
|
|
||||||
const char *snd_ctl_elem_info_get_name(const snd_ctl_elem_info_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_info_get_index(const snd_ctl_elem_info_t *obj);
|
|
||||||
void snd_ctl_elem_info_set_id(snd_ctl_elem_info_t *obj, const snd_ctl_elem_id_t *ptr);
|
|
||||||
void snd_ctl_elem_info_set_numid(snd_ctl_elem_info_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_info_set_interface(snd_ctl_elem_info_t *obj, snd_ctl_elem_iface_t val);
|
|
||||||
void snd_ctl_elem_info_set_device(snd_ctl_elem_info_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_info_set_subdevice(snd_ctl_elem_info_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val);
|
|
||||||
void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val);
|
|
||||||
|
|
||||||
int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|
||||||
unsigned int element_count,
|
|
||||||
unsigned int member_count,
|
|
||||||
long min, long max, long step);
|
|
||||||
int snd_ctl_add_integer64_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|
||||||
unsigned int element_count,
|
|
||||||
unsigned int member_count,
|
|
||||||
long long min, long long max,
|
|
||||||
long long step);
|
|
||||||
int snd_ctl_add_boolean_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|
||||||
unsigned int element_count,
|
|
||||||
unsigned int member_count);
|
|
||||||
int snd_ctl_add_enumerated_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|
||||||
unsigned int element_count,
|
|
||||||
unsigned int member_count,
|
|
||||||
unsigned int items,
|
|
||||||
const char *const labels[]);
|
|
||||||
int snd_ctl_add_bytes_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
|
|
||||||
unsigned int element_count,
|
|
||||||
unsigned int member_count);
|
|
||||||
|
|
||||||
int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long imin, long imax, long istep);
|
|
||||||
int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long long imin, long long imax, long long istep);
|
|
||||||
int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count);
|
|
||||||
int snd_ctl_elem_add_enumerated(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, unsigned int items, const char *const names[]);
|
|
||||||
int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id);
|
|
||||||
int snd_ctl_elem_remove(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
|
|
||||||
|
|
||||||
size_t snd_ctl_elem_value_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_ctl_elem_value_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_ctl_elem_value_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_value)
|
|
||||||
int snd_ctl_elem_value_malloc(snd_ctl_elem_value_t **ptr);
|
|
||||||
void snd_ctl_elem_value_free(snd_ctl_elem_value_t *obj);
|
|
||||||
void snd_ctl_elem_value_clear(snd_ctl_elem_value_t *obj);
|
|
||||||
void snd_ctl_elem_value_copy(snd_ctl_elem_value_t *dst, const snd_ctl_elem_value_t *src);
|
|
||||||
int snd_ctl_elem_value_compare(snd_ctl_elem_value_t *left, const snd_ctl_elem_value_t *right);
|
|
||||||
void snd_ctl_elem_value_get_id(const snd_ctl_elem_value_t *obj, snd_ctl_elem_id_t *ptr);
|
|
||||||
unsigned int snd_ctl_elem_value_get_numid(const snd_ctl_elem_value_t *obj);
|
|
||||||
snd_ctl_elem_iface_t snd_ctl_elem_value_get_interface(const snd_ctl_elem_value_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_value_get_device(const snd_ctl_elem_value_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_value_get_subdevice(const snd_ctl_elem_value_t *obj);
|
|
||||||
const char *snd_ctl_elem_value_get_name(const snd_ctl_elem_value_t *obj);
|
|
||||||
unsigned int snd_ctl_elem_value_get_index(const snd_ctl_elem_value_t *obj);
|
|
||||||
void snd_ctl_elem_value_set_id(snd_ctl_elem_value_t *obj, const snd_ctl_elem_id_t *ptr);
|
|
||||||
void snd_ctl_elem_value_set_numid(snd_ctl_elem_value_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_value_set_interface(snd_ctl_elem_value_t *obj, snd_ctl_elem_iface_t val);
|
|
||||||
void snd_ctl_elem_value_set_device(snd_ctl_elem_value_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_value_set_subdevice(snd_ctl_elem_value_t *obj, unsigned int val);
|
|
||||||
void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val);
|
|
||||||
void snd_ctl_elem_value_set_index(snd_ctl_elem_value_t *obj, unsigned int val);
|
|
||||||
int snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t *obj, unsigned int idx);
|
|
||||||
long snd_ctl_elem_value_get_integer(const snd_ctl_elem_value_t *obj, unsigned int idx);
|
|
||||||
long long snd_ctl_elem_value_get_integer64(const snd_ctl_elem_value_t *obj, unsigned int idx);
|
|
||||||
unsigned int snd_ctl_elem_value_get_enumerated(const snd_ctl_elem_value_t *obj, unsigned int idx);
|
|
||||||
unsigned char snd_ctl_elem_value_get_byte(const snd_ctl_elem_value_t *obj, unsigned int idx);
|
|
||||||
void snd_ctl_elem_value_set_boolean(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
|
|
||||||
void snd_ctl_elem_value_set_integer(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
|
|
||||||
void snd_ctl_elem_value_set_integer64(snd_ctl_elem_value_t *obj, unsigned int idx, long long val);
|
|
||||||
void snd_ctl_elem_value_set_enumerated(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val);
|
|
||||||
void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val);
|
|
||||||
void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size);
|
|
||||||
const void * snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t *obj);
|
|
||||||
void snd_ctl_elem_value_get_iec958(const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr);
|
|
||||||
void snd_ctl_elem_value_set_iec958(snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr);
|
|
||||||
|
|
||||||
int snd_tlv_parse_dB_info(unsigned int *tlv, unsigned int tlv_size,
|
|
||||||
unsigned int **db_tlvp);
|
|
||||||
int snd_tlv_get_dB_range(unsigned int *tlv, long rangemin, long rangemax,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_tlv_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,
|
|
||||||
long volume, long *db_gain);
|
|
||||||
int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
|
|
||||||
long db_gain, long *value, int xdir);
|
|
||||||
int snd_ctl_get_dB_range(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_ctl_convert_to_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
long volume, long *db_gain);
|
|
||||||
int snd_ctl_convert_from_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
|
|
||||||
long db_gain, long *value, int xdir);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup HControl High level Control Interface
|
|
||||||
* \ingroup Control
|
|
||||||
* The high level control interface.
|
|
||||||
* See \ref hcontrol page for more details.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** HCTL element handle */
|
|
||||||
typedef struct _snd_hctl_elem snd_hctl_elem_t;
|
|
||||||
|
|
||||||
/** HCTL handle */
|
|
||||||
typedef struct _snd_hctl snd_hctl_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Compare function for sorting HCTL elements
|
|
||||||
* \param e1 First element
|
|
||||||
* \param e2 Second element
|
|
||||||
* \return -1 if e1 < e2, 0 if e1 == e2, 1 if e1 > e2
|
|
||||||
*/
|
|
||||||
typedef int (*snd_hctl_compare_t)(const snd_hctl_elem_t *e1,
|
|
||||||
const snd_hctl_elem_t *e2);
|
|
||||||
int snd_hctl_compare_fast(const snd_hctl_elem_t *c1,
|
|
||||||
const snd_hctl_elem_t *c2);
|
|
||||||
/**
|
|
||||||
* \brief HCTL callback function
|
|
||||||
* \param hctl HCTL handle
|
|
||||||
* \param mask event mask
|
|
||||||
* \param elem related HCTL element (if any)
|
|
||||||
* \return 0 on success otherwise a negative error code
|
|
||||||
*/
|
|
||||||
typedef int (*snd_hctl_callback_t)(snd_hctl_t *hctl,
|
|
||||||
unsigned int mask,
|
|
||||||
snd_hctl_elem_t *elem);
|
|
||||||
/**
|
|
||||||
* \brief HCTL element callback function
|
|
||||||
* \param elem HCTL element
|
|
||||||
* \param mask event mask
|
|
||||||
* \return 0 on success otherwise a negative error code
|
|
||||||
*/
|
|
||||||
typedef int (*snd_hctl_elem_callback_t)(snd_hctl_elem_t *elem,
|
|
||||||
unsigned int mask);
|
|
||||||
|
|
||||||
int snd_hctl_open(snd_hctl_t **hctl, const char *name, int mode);
|
|
||||||
int snd_hctl_open_ctl(snd_hctl_t **hctlp, snd_ctl_t *ctl);
|
|
||||||
int snd_hctl_close(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock);
|
|
||||||
static __inline__ int snd_hctl_abort(snd_hctl_t *hctl) { return snd_hctl_nonblock(hctl, 2); }
|
|
||||||
int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space);
|
|
||||||
int snd_hctl_poll_descriptors_revents(snd_hctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
|
||||||
unsigned int snd_hctl_get_count(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort);
|
|
||||||
snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl);
|
|
||||||
snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl);
|
|
||||||
snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id);
|
|
||||||
void snd_hctl_set_callback(snd_hctl_t *hctl, snd_hctl_callback_t callback);
|
|
||||||
void snd_hctl_set_callback_private(snd_hctl_t *hctl, void *data);
|
|
||||||
void *snd_hctl_get_callback_private(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_load(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_free(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_handle_events(snd_hctl_t *hctl);
|
|
||||||
const char *snd_hctl_name(snd_hctl_t *hctl);
|
|
||||||
int snd_hctl_wait(snd_hctl_t *hctl, int timeout);
|
|
||||||
snd_ctl_t *snd_hctl_ctl(snd_hctl_t *hctl);
|
|
||||||
|
|
||||||
snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem);
|
|
||||||
snd_hctl_elem_t *snd_hctl_elem_prev(snd_hctl_elem_t *elem);
|
|
||||||
int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t * info);
|
|
||||||
int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
|
|
||||||
int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
|
|
||||||
int snd_hctl_elem_tlv_read(snd_hctl_elem_t *elem, unsigned int *tlv, unsigned int tlv_size);
|
|
||||||
int snd_hctl_elem_tlv_write(snd_hctl_elem_t *elem, const unsigned int *tlv);
|
|
||||||
int snd_hctl_elem_tlv_command(snd_hctl_elem_t *elem, const unsigned int *tlv);
|
|
||||||
|
|
||||||
snd_hctl_t *snd_hctl_elem_get_hctl(snd_hctl_elem_t *elem);
|
|
||||||
|
|
||||||
void snd_hctl_elem_get_id(const snd_hctl_elem_t *obj, snd_ctl_elem_id_t *ptr);
|
|
||||||
unsigned int snd_hctl_elem_get_numid(const snd_hctl_elem_t *obj);
|
|
||||||
snd_ctl_elem_iface_t snd_hctl_elem_get_interface(const snd_hctl_elem_t *obj);
|
|
||||||
unsigned int snd_hctl_elem_get_device(const snd_hctl_elem_t *obj);
|
|
||||||
unsigned int snd_hctl_elem_get_subdevice(const snd_hctl_elem_t *obj);
|
|
||||||
const char *snd_hctl_elem_get_name(const snd_hctl_elem_t *obj);
|
|
||||||
unsigned int snd_hctl_elem_get_index(const snd_hctl_elem_t *obj);
|
|
||||||
void snd_hctl_elem_set_callback(snd_hctl_elem_t *obj, snd_hctl_elem_callback_t val);
|
|
||||||
void * snd_hctl_elem_get_callback_private(const snd_hctl_elem_t *obj);
|
|
||||||
void snd_hctl_elem_set_callback_private(snd_hctl_elem_t *obj, void * val);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup SControl Setup Control Interface
|
|
||||||
* \ingroup Control
|
|
||||||
* The setup control interface - set or modify control elements from a configuration file.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
|
|
||||||
snd_config_t *private_data, int mode);
|
|
||||||
int snd_sctl_free(snd_sctl_t *handle);
|
|
||||||
int snd_sctl_install(snd_sctl_t *handle);
|
|
||||||
int snd_sctl_remove(snd_sctl_t *handle);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_CONTROL_H */
|
|
286
raylib/external/alsa/control_external.h
vendored
286
raylib/external/alsa/control_external.h
vendored
|
@ -1,286 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/control_external.h
|
|
||||||
* \brief External control plugin SDK
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 2005
|
|
||||||
*
|
|
||||||
* External control plugin SDK.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef __ALSA_CONTROL_EXTERNAL_H
|
|
||||||
#define __ALSA_CONTROL_EXTERNAL_H
|
|
||||||
|
|
||||||
#include "control.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup CtlPlugin_SDK External Control Plugin SDK
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the object entry for external control plugins
|
|
||||||
*/
|
|
||||||
#define SND_CTL_PLUGIN_ENTRY(name) _snd_ctl_##name##_open
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the symbols of the given control plugin with versions
|
|
||||||
*/
|
|
||||||
#define SND_CTL_PLUGIN_SYMBOL(name) SND_DLSYM_BUILD_VERSION(SND_CTL_PLUGIN_ENTRY(name), SND_CONTROL_DLSYM_VERSION);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the control plugin
|
|
||||||
*/
|
|
||||||
#define SND_CTL_PLUGIN_DEFINE_FUNC(plugin) \
|
|
||||||
int SND_CTL_PLUGIN_ENTRY(plugin) (snd_ctl_t **handlep, const char *name,\
|
|
||||||
snd_config_t *root, snd_config_t *conf, int mode)
|
|
||||||
|
|
||||||
/** External control plugin handle */
|
|
||||||
typedef struct snd_ctl_ext snd_ctl_ext_t;
|
|
||||||
/** Callback table of control ext */
|
|
||||||
typedef struct snd_ctl_ext_callback snd_ctl_ext_callback_t;
|
|
||||||
/** Key to access a control pointer */
|
|
||||||
typedef unsigned long snd_ctl_ext_key_t;
|
|
||||||
#ifdef DOC_HIDDEN
|
|
||||||
/* redefine typedef's for stupid doxygen */
|
|
||||||
typedef snd_ctl_ext snd_ctl_ext_t;
|
|
||||||
typedef snd_ctl_ext_callback snd_ctl_ext_callback_t;
|
|
||||||
#endif
|
|
||||||
/** Callback to handle TLV commands. */
|
|
||||||
typedef int (snd_ctl_ext_tlv_rw_t)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int op_flag, unsigned int numid,
|
|
||||||
unsigned int *tlv, unsigned int tlv_size);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Protocol version
|
|
||||||
*/
|
|
||||||
#define SND_CTL_EXT_VERSION_MAJOR 1 /**< Protocol major version */
|
|
||||||
#define SND_CTL_EXT_VERSION_MINOR 0 /**< Protocol minor version */
|
|
||||||
#define SND_CTL_EXT_VERSION_TINY 1 /**< Protocol tiny version */
|
|
||||||
/**
|
|
||||||
* external plugin protocol version
|
|
||||||
*/
|
|
||||||
#define SND_CTL_EXT_VERSION ((SND_CTL_EXT_VERSION_MAJOR<<16) |\
|
|
||||||
(SND_CTL_EXT_VERSION_MINOR<<8) |\
|
|
||||||
(SND_CTL_EXT_VERSION_TINY))
|
|
||||||
|
|
||||||
/** Handle of control ext */
|
|
||||||
struct snd_ctl_ext {
|
|
||||||
/**
|
|
||||||
* protocol version; #SND_CTL_EXT_VERSION must be filled here
|
|
||||||
* before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
unsigned int version;
|
|
||||||
/**
|
|
||||||
* Index of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
int card_idx;
|
|
||||||
/**
|
|
||||||
* ID string of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
char id[16];
|
|
||||||
/**
|
|
||||||
* Driver name of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
char driver[16];
|
|
||||||
/**
|
|
||||||
* short name of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
char name[32];
|
|
||||||
/**
|
|
||||||
* Long name of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
char longname[80];
|
|
||||||
/**
|
|
||||||
* Mixer name of this card; must be filled before calling #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
char mixername[80];
|
|
||||||
/**
|
|
||||||
* poll descriptor
|
|
||||||
*/
|
|
||||||
int poll_fd;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* callbacks of this plugin; must be filled before calling #snd_pcm_ioplug_create()
|
|
||||||
*/
|
|
||||||
const snd_ctl_ext_callback_t *callback;
|
|
||||||
/**
|
|
||||||
* private data, which can be used freely in the driver callbacks
|
|
||||||
*/
|
|
||||||
void *private_data;
|
|
||||||
/**
|
|
||||||
* control handle filled by #snd_ctl_ext_create()
|
|
||||||
*/
|
|
||||||
snd_ctl_t *handle;
|
|
||||||
|
|
||||||
int nonblock; /**< non-block mode; read-only */
|
|
||||||
int subscribed; /**< events subscribed; read-only */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* optional TLV data for the control (since protocol 1.0.1)
|
|
||||||
*/
|
|
||||||
union {
|
|
||||||
snd_ctl_ext_tlv_rw_t *c;
|
|
||||||
const unsigned int *p;
|
|
||||||
} tlv;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Callback table of ext. */
|
|
||||||
struct snd_ctl_ext_callback {
|
|
||||||
/**
|
|
||||||
* close the control handle; optional
|
|
||||||
*/
|
|
||||||
void (*close)(snd_ctl_ext_t *ext);
|
|
||||||
/**
|
|
||||||
* return the total number of elements; required
|
|
||||||
*/
|
|
||||||
int (*elem_count)(snd_ctl_ext_t *ext);
|
|
||||||
/**
|
|
||||||
* return the element id of the given offset (array index); required
|
|
||||||
*/
|
|
||||||
int (*elem_list)(snd_ctl_ext_t *ext, unsigned int offset, snd_ctl_elem_id_t *id);
|
|
||||||
/**
|
|
||||||
* convert the element id to a search key; required
|
|
||||||
*/
|
|
||||||
snd_ctl_ext_key_t (*find_elem)(snd_ctl_ext_t *ext, const snd_ctl_elem_id_t *id);
|
|
||||||
/**
|
|
||||||
* the destructor of the key; optional
|
|
||||||
*/
|
|
||||||
void (*free_key)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key);
|
|
||||||
/**
|
|
||||||
* get the attribute of the element; required
|
|
||||||
*/
|
|
||||||
int (*get_attribute)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
|
|
||||||
int *type, unsigned int *acc, unsigned int *count);
|
|
||||||
/**
|
|
||||||
* get the element information of integer type
|
|
||||||
*/
|
|
||||||
int (*get_integer_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
|
|
||||||
long *imin, long *imax, long *istep);
|
|
||||||
/**
|
|
||||||
* get the element information of integer64 type
|
|
||||||
*/
|
|
||||||
int (*get_integer64_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key,
|
|
||||||
int64_t *imin, int64_t *imax, int64_t *istep);
|
|
||||||
/**
|
|
||||||
* get the element information of enumerated type
|
|
||||||
*/
|
|
||||||
int (*get_enumerated_info)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
|
|
||||||
/**
|
|
||||||
* get the name of the enumerated item
|
|
||||||
*/
|
|
||||||
int (*get_enumerated_name)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int item,
|
|
||||||
char *name, size_t name_max_len);
|
|
||||||
/**
|
|
||||||
* read the current values of integer type
|
|
||||||
*/
|
|
||||||
int (*read_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
|
|
||||||
/**
|
|
||||||
* read the current values of integer64 type
|
|
||||||
*/
|
|
||||||
int (*read_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
|
|
||||||
/**
|
|
||||||
* read the current values of enumerated type
|
|
||||||
*/
|
|
||||||
int (*read_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
|
|
||||||
/**
|
|
||||||
* read the current values of bytes type
|
|
||||||
*/
|
|
||||||
int (*read_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
|
|
||||||
size_t max_bytes);
|
|
||||||
/**
|
|
||||||
* read the current values of iec958 type
|
|
||||||
*/
|
|
||||||
int (*read_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
|
|
||||||
/**
|
|
||||||
* update the current values of integer type with the given values
|
|
||||||
*/
|
|
||||||
int (*write_integer)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, long *value);
|
|
||||||
/**
|
|
||||||
* update the current values of integer64 type with the given values
|
|
||||||
*/
|
|
||||||
int (*write_integer64)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, int64_t *value);
|
|
||||||
/**
|
|
||||||
* update the current values of enumerated type with the given values
|
|
||||||
*/
|
|
||||||
int (*write_enumerated)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned int *items);
|
|
||||||
/**
|
|
||||||
* update the current values of bytes type with the given values
|
|
||||||
*/
|
|
||||||
int (*write_bytes)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, unsigned char *data,
|
|
||||||
size_t max_bytes);
|
|
||||||
/**
|
|
||||||
* update the current values of iec958 type with the given values
|
|
||||||
*/
|
|
||||||
int (*write_iec958)(snd_ctl_ext_t *ext, snd_ctl_ext_key_t key, snd_aes_iec958_t *iec958);
|
|
||||||
/**
|
|
||||||
* subscribe/unsubscribe the event notification; optional
|
|
||||||
*/
|
|
||||||
void (*subscribe_events)(snd_ctl_ext_t *ext, int subscribe);
|
|
||||||
/**
|
|
||||||
* read a pending notification event; optional
|
|
||||||
*/
|
|
||||||
int (*read_event)(snd_ctl_ext_t *ext, snd_ctl_elem_id_t *id, unsigned int *event_mask);
|
|
||||||
/**
|
|
||||||
* return the number of poll descriptors; optional
|
|
||||||
*/
|
|
||||||
int (*poll_descriptors_count)(snd_ctl_ext_t *ext);
|
|
||||||
/**
|
|
||||||
* fill the poll descriptors; optional
|
|
||||||
*/
|
|
||||||
int (*poll_descriptors)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int space);
|
|
||||||
/**
|
|
||||||
* mangle the revents of poll descriptors
|
|
||||||
*/
|
|
||||||
int (*poll_revents)(snd_ctl_ext_t *ext, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The access type bits stored in get_attribute callback
|
|
||||||
*/
|
|
||||||
typedef enum snd_ctl_ext_access {
|
|
||||||
SND_CTL_EXT_ACCESS_READ = (1<<0),
|
|
||||||
SND_CTL_EXT_ACCESS_WRITE = (1<<1),
|
|
||||||
SND_CTL_EXT_ACCESS_READWRITE = (3<<0),
|
|
||||||
SND_CTL_EXT_ACCESS_VOLATILE = (1<<2),
|
|
||||||
SND_CTL_EXT_ACCESS_TLV_READ = (1<<4),
|
|
||||||
SND_CTL_EXT_ACCESS_TLV_WRITE = (1<<5),
|
|
||||||
SND_CTL_EXT_ACCESS_TLV_READWRITE = (3<<4),
|
|
||||||
SND_CTL_EXT_ACCESS_TLV_COMMAND = (1<<6),
|
|
||||||
SND_CTL_EXT_ACCESS_INACTIVE = (1<<8),
|
|
||||||
SND_CTL_EXT_ACCESS_TLV_CALLBACK = (1<<28),
|
|
||||||
} snd_ctl_ext_access_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* find_elem callback returns this if no matching control element is found
|
|
||||||
*/
|
|
||||||
#define SND_CTL_EXT_KEY_NOT_FOUND (snd_ctl_ext_key_t)(-1)
|
|
||||||
|
|
||||||
int snd_ctl_ext_create(snd_ctl_ext_t *ext, const char *name, int mode);
|
|
||||||
int snd_ctl_ext_delete(snd_ctl_ext_t *ext);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_CONTROL_EXTERNAL_H */
|
|
85
raylib/external/alsa/error.h
vendored
85
raylib/external/alsa/error.h
vendored
|
@ -1,85 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/error.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_ERROR_H
|
|
||||||
#define __ALSA_ERROR_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Error Error handling
|
|
||||||
* Error handling macros and functions.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define SND_ERROR_BEGIN 500000 /**< Lower boundary of sound error codes. */
|
|
||||||
#define SND_ERROR_INCOMPATIBLE_VERSION (SND_ERROR_BEGIN+0) /**< Kernel/library protocols are not compatible. */
|
|
||||||
#define SND_ERROR_ALISP_NIL (SND_ERROR_BEGIN+1) /**< Lisp encountered an error during acall. */
|
|
||||||
|
|
||||||
const char *snd_strerror(int errnum);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Error handler callback.
|
|
||||||
* \param file Source file name.
|
|
||||||
* \param line Line number.
|
|
||||||
* \param function Function name.
|
|
||||||
* \param err Value of \c errno, or 0 if not relevant.
|
|
||||||
* \param fmt \c printf(3) format.
|
|
||||||
* \param ... \c printf(3) arguments.
|
|
||||||
*
|
|
||||||
* A function of this type is called by the ALSA library when an error occurs.
|
|
||||||
* This function usually shows the message on the screen, and/or logs it.
|
|
||||||
*/
|
|
||||||
typedef void (*snd_lib_error_handler_t)(const char *file, int line, const char *function, int err, const char *fmt, ...) /* __attribute__ ((format (printf, 5, 6))) */;
|
|
||||||
extern snd_lib_error_handler_t snd_lib_error;
|
|
||||||
extern int snd_lib_error_set_handler(snd_lib_error_handler_t handler);
|
|
||||||
|
|
||||||
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 95)
|
|
||||||
#define SNDERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, __VA_ARGS__) /**< Shows a sound error message. */
|
|
||||||
#define SYSERR(...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, __VA_ARGS__) /**< Shows a system error message (related to \c errno). */
|
|
||||||
#else
|
|
||||||
#define SNDERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, 0, ##args) /**< Shows a sound error message. */
|
|
||||||
#define SYSERR(args...) snd_lib_error(__FILE__, __LINE__, __FUNCTION__, errno, ##args) /**< Shows a system error message (related to \c errno). */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Local error handler function type */
|
|
||||||
typedef void (*snd_local_error_handler_t)(const char *file, int line,
|
|
||||||
const char *func, int err,
|
|
||||||
const char *fmt, va_list arg);
|
|
||||||
|
|
||||||
snd_local_error_handler_t snd_lib_error_set_local(snd_local_error_handler_t func);
|
|
||||||
|
|
||||||
#endif /* __ALSA_ERROR_H */
|
|
||||||
|
|
161
raylib/external/alsa/global.h
vendored
161
raylib/external/alsa/global.h
vendored
|
@ -1,161 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/global.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_GLOBAL_H_
|
|
||||||
#define __ALSA_GLOBAL_H_
|
|
||||||
|
|
||||||
/* for timeval and timespec */
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Global Global defines and functions
|
|
||||||
* Global defines and functions.
|
|
||||||
* \par
|
|
||||||
* The ALSA library implementation uses these macros and functions.
|
|
||||||
* Most applications probably do not need them.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
const char *snd_asoundlib_version(void);
|
|
||||||
|
|
||||||
#ifndef ATTRIBUTE_UNUSED
|
|
||||||
/** do not print warning (gcc) when function parameter is not used */
|
|
||||||
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef PIC /* dynamic build */
|
|
||||||
|
|
||||||
/** \hideinitializer \brief Helper macro for #SND_DLSYM_BUILD_VERSION. */
|
|
||||||
#define __SND_DLSYM_VERSION(name, version) _ ## name ## version
|
|
||||||
/**
|
|
||||||
* \hideinitializer
|
|
||||||
* \brief Appends the build version to the name of a versioned dynamic symbol.
|
|
||||||
*/
|
|
||||||
#define SND_DLSYM_BUILD_VERSION(name, version) char __SND_DLSYM_VERSION(name, version);
|
|
||||||
|
|
||||||
#else /* static build */
|
|
||||||
|
|
||||||
struct snd_dlsym_link {
|
|
||||||
struct snd_dlsym_link *next;
|
|
||||||
const char *dlsym_name;
|
|
||||||
const void *dlsym_ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern struct snd_dlsym_link *snd_dlsym_start;
|
|
||||||
|
|
||||||
/** \hideinitializer \brief Helper macro for #SND_DLSYM_BUILD_VERSION. */
|
|
||||||
#define __SND_DLSYM_VERSION(prefix, name, version) _ ## prefix ## name ## version
|
|
||||||
/**
|
|
||||||
* \hideinitializer
|
|
||||||
* \brief Appends the build version to the name of a versioned dynamic symbol.
|
|
||||||
*/
|
|
||||||
#define SND_DLSYM_BUILD_VERSION(name, version) \
|
|
||||||
static struct snd_dlsym_link __SND_DLSYM_VERSION(snd_dlsym_, name, version); \
|
|
||||||
void __SND_DLSYM_VERSION(snd_dlsym_constructor_, name, version) (void) __attribute__ ((constructor)); \
|
|
||||||
void __SND_DLSYM_VERSION(snd_dlsym_constructor_, name, version) (void) { \
|
|
||||||
__SND_DLSYM_VERSION(snd_dlsym_, name, version).next = snd_dlsym_start; \
|
|
||||||
__SND_DLSYM_VERSION(snd_dlsym_, name, version).dlsym_name = # name; \
|
|
||||||
__SND_DLSYM_VERSION(snd_dlsym_, name, version).dlsym_ptr = (void *)&name; \
|
|
||||||
snd_dlsym_start = &__SND_DLSYM_VERSION(snd_dlsym_, name, version); \
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __STRING
|
|
||||||
/** \brief Return 'x' argument as string */
|
|
||||||
#define __STRING(x) #x
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** \brief Returns the version of a dynamic symbol as a string. */
|
|
||||||
#define SND_DLSYM_VERSION(version) __STRING(version)
|
|
||||||
|
|
||||||
void *snd_dlopen(const char *file, int mode);
|
|
||||||
void *snd_dlsym(void *handle, const char *name, const char *version);
|
|
||||||
int snd_dlclose(void *handle);
|
|
||||||
|
|
||||||
|
|
||||||
/** \brief alloca helper macro. */
|
|
||||||
#define __snd_alloca(ptr,type) do { *ptr = (type##_t *) alloca(type##_sizeof()); memset(*ptr, 0, type##_sizeof()); } while (0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Internal structure for an async notification client handler.
|
|
||||||
*
|
|
||||||
* The ALSA library uses a pointer to this structure as a handle to an async
|
|
||||||
* notification object. Applications don't access its contents directly.
|
|
||||||
*/
|
|
||||||
typedef struct _snd_async_handler snd_async_handler_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Async notification callback.
|
|
||||||
*
|
|
||||||
* See the #snd_async_add_handler function for details.
|
|
||||||
*/
|
|
||||||
typedef void (*snd_async_callback_t)(snd_async_handler_t *handler);
|
|
||||||
|
|
||||||
int snd_async_add_handler(snd_async_handler_t **handler, int fd,
|
|
||||||
snd_async_callback_t callback, void *private_data);
|
|
||||||
int snd_async_del_handler(snd_async_handler_t *handler);
|
|
||||||
int snd_async_handler_get_fd(snd_async_handler_t *handler);
|
|
||||||
int snd_async_handler_get_signo(snd_async_handler_t *handler);
|
|
||||||
void *snd_async_handler_get_callback_private(snd_async_handler_t *handler);
|
|
||||||
|
|
||||||
struct snd_shm_area *snd_shm_area_create(int shmid, void *ptr);
|
|
||||||
struct snd_shm_area *snd_shm_area_share(struct snd_shm_area *area);
|
|
||||||
int snd_shm_area_destroy(struct snd_shm_area *area);
|
|
||||||
|
|
||||||
int snd_user_file(const char *file, char **result);
|
|
||||||
|
|
||||||
#ifdef __GLIBC__
|
|
||||||
#if !defined(_POSIX_C_SOURCE) && !defined(_POSIX_SOURCE)
|
|
||||||
struct timeval {
|
|
||||||
time_t tv_sec; /* seconds */
|
|
||||||
long tv_usec; /* microseconds */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct timespec {
|
|
||||||
time_t tv_sec; /* seconds */
|
|
||||||
long tv_nsec; /* nanoseconds */
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** Timestamp */
|
|
||||||
typedef struct timeval snd_timestamp_t;
|
|
||||||
/** Hi-res timestamp */
|
|
||||||
typedef struct timespec snd_htimestamp_t;
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_GLOBAL_H */
|
|
172
raylib/external/alsa/hwdep.h
vendored
172
raylib/external/alsa/hwdep.h
vendored
|
@ -1,172 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/hwdep.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_HWDEP_H
|
|
||||||
#define __ALSA_HWDEP_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup HwDep Hardware Dependant Interface
|
|
||||||
* The Hardware Dependant Interface.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** dlsym version for interface entry callback */
|
|
||||||
#define SND_HWDEP_DLSYM_VERSION _dlsym_hwdep_001
|
|
||||||
|
|
||||||
/** HwDep information container */
|
|
||||||
typedef struct _snd_hwdep_info snd_hwdep_info_t;
|
|
||||||
|
|
||||||
/** HwDep DSP status container */
|
|
||||||
typedef struct _snd_hwdep_dsp_status snd_hwdep_dsp_status_t;
|
|
||||||
|
|
||||||
/** HwDep DSP image container */
|
|
||||||
typedef struct _snd_hwdep_dsp_image snd_hwdep_dsp_image_t;
|
|
||||||
|
|
||||||
/** HwDep interface */
|
|
||||||
typedef enum _snd_hwdep_iface {
|
|
||||||
SND_HWDEP_IFACE_OPL2 = 0, /**< OPL2 raw driver */
|
|
||||||
SND_HWDEP_IFACE_OPL3, /**< OPL3 raw driver */
|
|
||||||
SND_HWDEP_IFACE_OPL4, /**< OPL4 raw driver */
|
|
||||||
SND_HWDEP_IFACE_SB16CSP, /**< SB16CSP driver */
|
|
||||||
SND_HWDEP_IFACE_EMU10K1, /**< EMU10K1 driver */
|
|
||||||
SND_HWDEP_IFACE_YSS225, /**< YSS225 driver */
|
|
||||||
SND_HWDEP_IFACE_ICS2115, /**< ICS2115 driver */
|
|
||||||
SND_HWDEP_IFACE_SSCAPE, /**< Ensoniq SoundScape ISA card (MC68EC000) */
|
|
||||||
SND_HWDEP_IFACE_VX, /**< Digigram VX cards */
|
|
||||||
SND_HWDEP_IFACE_MIXART, /**< Digigram miXart cards */
|
|
||||||
SND_HWDEP_IFACE_USX2Y, /**< Tascam US122, US224 & US428 usb */
|
|
||||||
SND_HWDEP_IFACE_EMUX_WAVETABLE, /**< EmuX wavetable */
|
|
||||||
SND_HWDEP_IFACE_BLUETOOTH, /**< Bluetooth audio */
|
|
||||||
SND_HWDEP_IFACE_USX2Y_PCM, /**< Tascam US122, US224 & US428 raw USB PCM */
|
|
||||||
SND_HWDEP_IFACE_PCXHR, /**< Digigram PCXHR */
|
|
||||||
SND_HWDEP_IFACE_SB_RC, /**< SB Extigy/Audigy2NX remote control */
|
|
||||||
SND_HWDEP_IFACE_HDA, /**< HD-audio */
|
|
||||||
SND_HWDEP_IFACE_USB_STREAM, /**< direct access to usb stream */
|
|
||||||
SND_HWDEP_IFACE_FW_DICE, /**< TC DICE FireWire device */
|
|
||||||
SND_HWDEP_IFACE_FW_FIREWORKS, /**< Echo Audio Fireworks based device */
|
|
||||||
SND_HWDEP_IFACE_FW_BEBOB, /**< BridgeCo BeBoB based device */
|
|
||||||
SND_HWDEP_IFACE_FW_OXFW, /**< Oxford OXFW970/971 based device */
|
|
||||||
SND_HWDEP_IFACE_FW_DIGI00X, /* Digidesign Digi 002/003 family */
|
|
||||||
SND_HWDEP_IFACE_FW_TASCAM, /* TASCAM FireWire series */
|
|
||||||
SND_HWDEP_IFACE_LINE6, /* Line6 USB processors */
|
|
||||||
SND_HWDEP_IFACE_FW_MOTU, /* MOTU FireWire series */
|
|
||||||
SND_HWDEP_IFACE_FW_FIREFACE, /* RME Fireface series */
|
|
||||||
|
|
||||||
SND_HWDEP_IFACE_LAST = SND_HWDEP_IFACE_FW_FIREFACE, /**< last known hwdep interface */
|
|
||||||
} snd_hwdep_iface_t;
|
|
||||||
|
|
||||||
/** open for reading */
|
|
||||||
#define SND_HWDEP_OPEN_READ (O_RDONLY)
|
|
||||||
/** open for writing */
|
|
||||||
#define SND_HWDEP_OPEN_WRITE (O_WRONLY)
|
|
||||||
/** open for reading and writing */
|
|
||||||
#define SND_HWDEP_OPEN_DUPLEX (O_RDWR)
|
|
||||||
/** open mode flag: open in nonblock mode */
|
|
||||||
#define SND_HWDEP_OPEN_NONBLOCK (O_NONBLOCK)
|
|
||||||
|
|
||||||
/** HwDep handle type */
|
|
||||||
typedef enum _snd_hwdep_type {
|
|
||||||
/** Kernel level HwDep */
|
|
||||||
SND_HWDEP_TYPE_HW,
|
|
||||||
/** Shared memory client HwDep (not yet implemented) */
|
|
||||||
SND_HWDEP_TYPE_SHM,
|
|
||||||
/** INET client HwDep (not yet implemented) */
|
|
||||||
SND_HWDEP_TYPE_INET
|
|
||||||
} snd_hwdep_type_t;
|
|
||||||
|
|
||||||
/** HwDep handle */
|
|
||||||
typedef struct _snd_hwdep snd_hwdep_t;
|
|
||||||
|
|
||||||
int snd_hwdep_open(snd_hwdep_t **hwdep, const char *name, int mode);
|
|
||||||
int snd_hwdep_close(snd_hwdep_t *hwdep);
|
|
||||||
int snd_hwdep_poll_descriptors(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int space);
|
|
||||||
int snd_hwdep_poll_descriptors_count(snd_hwdep_t *hwdep);
|
|
||||||
int snd_hwdep_poll_descriptors_revents(snd_hwdep_t *hwdep, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
|
||||||
int snd_hwdep_nonblock(snd_hwdep_t *hwdep, int nonblock);
|
|
||||||
int snd_hwdep_info(snd_hwdep_t *hwdep, snd_hwdep_info_t * info);
|
|
||||||
int snd_hwdep_dsp_status(snd_hwdep_t *hwdep, snd_hwdep_dsp_status_t *status);
|
|
||||||
int snd_hwdep_dsp_load(snd_hwdep_t *hwdep, snd_hwdep_dsp_image_t *block);
|
|
||||||
int snd_hwdep_ioctl(snd_hwdep_t *hwdep, unsigned int request, void * arg);
|
|
||||||
ssize_t snd_hwdep_write(snd_hwdep_t *hwdep, const void *buffer, size_t size);
|
|
||||||
ssize_t snd_hwdep_read(snd_hwdep_t *hwdep, void *buffer, size_t size);
|
|
||||||
|
|
||||||
size_t snd_hwdep_info_sizeof(void);
|
|
||||||
/** allocate #snd_hwdep_info_t container on stack */
|
|
||||||
#define snd_hwdep_info_alloca(ptr) __snd_alloca(ptr, snd_hwdep_info)
|
|
||||||
int snd_hwdep_info_malloc(snd_hwdep_info_t **ptr);
|
|
||||||
void snd_hwdep_info_free(snd_hwdep_info_t *obj);
|
|
||||||
void snd_hwdep_info_copy(snd_hwdep_info_t *dst, const snd_hwdep_info_t *src);
|
|
||||||
|
|
||||||
unsigned int snd_hwdep_info_get_device(const snd_hwdep_info_t *obj);
|
|
||||||
int snd_hwdep_info_get_card(const snd_hwdep_info_t *obj);
|
|
||||||
const char *snd_hwdep_info_get_id(const snd_hwdep_info_t *obj);
|
|
||||||
const char *snd_hwdep_info_get_name(const snd_hwdep_info_t *obj);
|
|
||||||
snd_hwdep_iface_t snd_hwdep_info_get_iface(const snd_hwdep_info_t *obj);
|
|
||||||
void snd_hwdep_info_set_device(snd_hwdep_info_t *obj, unsigned int val);
|
|
||||||
|
|
||||||
size_t snd_hwdep_dsp_status_sizeof(void);
|
|
||||||
/** allocate #snd_hwdep_dsp_status_t container on stack */
|
|
||||||
#define snd_hwdep_dsp_status_alloca(ptr) __snd_alloca(ptr, snd_hwdep_dsp_status)
|
|
||||||
int snd_hwdep_dsp_status_malloc(snd_hwdep_dsp_status_t **ptr);
|
|
||||||
void snd_hwdep_dsp_status_free(snd_hwdep_dsp_status_t *obj);
|
|
||||||
void snd_hwdep_dsp_status_copy(snd_hwdep_dsp_status_t *dst, const snd_hwdep_dsp_status_t *src);
|
|
||||||
|
|
||||||
unsigned int snd_hwdep_dsp_status_get_version(const snd_hwdep_dsp_status_t *obj);
|
|
||||||
const char *snd_hwdep_dsp_status_get_id(const snd_hwdep_dsp_status_t *obj);
|
|
||||||
unsigned int snd_hwdep_dsp_status_get_num_dsps(const snd_hwdep_dsp_status_t *obj);
|
|
||||||
unsigned int snd_hwdep_dsp_status_get_dsp_loaded(const snd_hwdep_dsp_status_t *obj);
|
|
||||||
unsigned int snd_hwdep_dsp_status_get_chip_ready(const snd_hwdep_dsp_status_t *obj);
|
|
||||||
|
|
||||||
size_t snd_hwdep_dsp_image_sizeof(void);
|
|
||||||
/** allocate #snd_hwdep_dsp_image_t container on stack */
|
|
||||||
#define snd_hwdep_dsp_image_alloca(ptr) __snd_alloca(ptr, snd_hwdep_dsp_image)
|
|
||||||
int snd_hwdep_dsp_image_malloc(snd_hwdep_dsp_image_t **ptr);
|
|
||||||
void snd_hwdep_dsp_image_free(snd_hwdep_dsp_image_t *obj);
|
|
||||||
void snd_hwdep_dsp_image_copy(snd_hwdep_dsp_image_t *dst, const snd_hwdep_dsp_image_t *src);
|
|
||||||
|
|
||||||
unsigned int snd_hwdep_dsp_image_get_index(const snd_hwdep_dsp_image_t *obj);
|
|
||||||
const char *snd_hwdep_dsp_image_get_name(const snd_hwdep_dsp_image_t *obj);
|
|
||||||
const void *snd_hwdep_dsp_image_get_image(const snd_hwdep_dsp_image_t *obj);
|
|
||||||
size_t snd_hwdep_dsp_image_get_length(const snd_hwdep_dsp_image_t *obj);
|
|
||||||
|
|
||||||
void snd_hwdep_dsp_image_set_index(snd_hwdep_dsp_image_t *obj, unsigned int _index);
|
|
||||||
void snd_hwdep_dsp_image_set_name(snd_hwdep_dsp_image_t *obj, const char *name);
|
|
||||||
void snd_hwdep_dsp_image_set_image(snd_hwdep_dsp_image_t *obj, void *buffer);
|
|
||||||
void snd_hwdep_dsp_image_set_length(snd_hwdep_dsp_image_t *obj, size_t length);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_HWDEP_H */
|
|
||||||
|
|
83
raylib/external/alsa/input.h
vendored
83
raylib/external/alsa/input.h
vendored
|
@ -1,83 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/input.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_INPUT_H
|
|
||||||
#define __ALSA_INPUT_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Input Input Interface
|
|
||||||
*
|
|
||||||
* The input functions present an interface similar to the stdio functions
|
|
||||||
* on top of different underlying input sources.
|
|
||||||
*
|
|
||||||
* The #snd_config_load function uses such an input handle to be able to
|
|
||||||
* load configurations not only from standard files but also from other
|
|
||||||
* sources, e.g. from memory buffers.
|
|
||||||
*
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Internal structure for an input object.
|
|
||||||
*
|
|
||||||
* The ALSA library uses a pointer to this structure as a handle to an
|
|
||||||
* input object. Applications don't access its contents directly.
|
|
||||||
*/
|
|
||||||
typedef struct _snd_input snd_input_t;
|
|
||||||
|
|
||||||
/** Input type. */
|
|
||||||
typedef enum _snd_input_type {
|
|
||||||
/** Input from a stdio stream. */
|
|
||||||
SND_INPUT_STDIO,
|
|
||||||
/** Input from a memory buffer. */
|
|
||||||
SND_INPUT_BUFFER
|
|
||||||
} snd_input_type_t;
|
|
||||||
|
|
||||||
int snd_input_stdio_open(snd_input_t **inputp, const char *file, const char *mode);
|
|
||||||
int snd_input_stdio_attach(snd_input_t **inputp, FILE *fp, int _close);
|
|
||||||
int snd_input_buffer_open(snd_input_t **inputp, const char *buffer, ssize_t size);
|
|
||||||
int snd_input_close(snd_input_t *input);
|
|
||||||
int snd_input_scanf(snd_input_t *input, const char *format, ...)
|
|
||||||
#ifndef DOC_HIDDEN
|
|
||||||
__attribute__ ((format (scanf, 2, 3)))
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
char *snd_input_gets(snd_input_t *input, char *str, size_t size);
|
|
||||||
int snd_input_getc(snd_input_t *input);
|
|
||||||
int snd_input_ungetc(snd_input_t *input, int c);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_INPUT_H */
|
|
317
raylib/external/alsa/mixer.h
vendored
317
raylib/external/alsa/mixer.h
vendored
|
@ -1,317 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/mixer.h
|
|
||||||
* \brief Application interface library for the ALSA driver
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
||||||
* \author Takashi Iwai <tiwai@suse.de>
|
|
||||||
* \date 1998-2001
|
|
||||||
*
|
|
||||||
* Application interface library for the ALSA driver
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_MIXER_H
|
|
||||||
#define __ALSA_MIXER_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Mixer Mixer Interface
|
|
||||||
* The mixer interface.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Mixer handle */
|
|
||||||
typedef struct _snd_mixer snd_mixer_t;
|
|
||||||
/** Mixer elements class handle */
|
|
||||||
typedef struct _snd_mixer_class snd_mixer_class_t;
|
|
||||||
/** Mixer element handle */
|
|
||||||
typedef struct _snd_mixer_elem snd_mixer_elem_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Mixer callback function
|
|
||||||
* \param mixer Mixer handle
|
|
||||||
* \param mask event mask
|
|
||||||
* \param elem related mixer element (if any)
|
|
||||||
* \return 0 on success otherwise a negative error code
|
|
||||||
*/
|
|
||||||
typedef int (*snd_mixer_callback_t)(snd_mixer_t *ctl,
|
|
||||||
unsigned int mask,
|
|
||||||
snd_mixer_elem_t *elem);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Mixer element callback function
|
|
||||||
* \param elem Mixer element
|
|
||||||
* \param mask event mask
|
|
||||||
* \return 0 on success otherwise a negative error code
|
|
||||||
*/
|
|
||||||
typedef int (*snd_mixer_elem_callback_t)(snd_mixer_elem_t *elem,
|
|
||||||
unsigned int mask);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Compare function for sorting mixer elements
|
|
||||||
* \param e1 First element
|
|
||||||
* \param e2 Second element
|
|
||||||
* \return -1 if e1 < e2, 0 if e1 == e2, 1 if e1 > e2
|
|
||||||
*/
|
|
||||||
typedef int (*snd_mixer_compare_t)(const snd_mixer_elem_t *e1,
|
|
||||||
const snd_mixer_elem_t *e2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Event callback for the mixer class
|
|
||||||
* \param class_ Mixer class
|
|
||||||
* \param mask Event mask (SND_CTL_EVENT_*)
|
|
||||||
* \param helem HCTL element which invoked the event
|
|
||||||
* \param melem Mixer element associated to HCTL element
|
|
||||||
* \return zero if success, otherwise a negative error value
|
|
||||||
*/
|
|
||||||
typedef int (*snd_mixer_event_t)(snd_mixer_class_t *class_, unsigned int mask,
|
|
||||||
snd_hctl_elem_t *helem, snd_mixer_elem_t *melem);
|
|
||||||
|
|
||||||
|
|
||||||
/** Mixer element type */
|
|
||||||
typedef enum _snd_mixer_elem_type {
|
|
||||||
/* Simple mixer elements */
|
|
||||||
SND_MIXER_ELEM_SIMPLE,
|
|
||||||
SND_MIXER_ELEM_LAST = SND_MIXER_ELEM_SIMPLE
|
|
||||||
} snd_mixer_elem_type_t;
|
|
||||||
|
|
||||||
int snd_mixer_open(snd_mixer_t **mixer, int mode);
|
|
||||||
int snd_mixer_close(snd_mixer_t *mixer);
|
|
||||||
snd_mixer_elem_t *snd_mixer_first_elem(snd_mixer_t *mixer);
|
|
||||||
snd_mixer_elem_t *snd_mixer_last_elem(snd_mixer_t *mixer);
|
|
||||||
int snd_mixer_handle_events(snd_mixer_t *mixer);
|
|
||||||
int snd_mixer_attach(snd_mixer_t *mixer, const char *name);
|
|
||||||
int snd_mixer_attach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl);
|
|
||||||
int snd_mixer_detach(snd_mixer_t *mixer, const char *name);
|
|
||||||
int snd_mixer_detach_hctl(snd_mixer_t *mixer, snd_hctl_t *hctl);
|
|
||||||
int snd_mixer_get_hctl(snd_mixer_t *mixer, const char *name, snd_hctl_t **hctl);
|
|
||||||
int snd_mixer_poll_descriptors_count(snd_mixer_t *mixer);
|
|
||||||
int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space);
|
|
||||||
int snd_mixer_poll_descriptors_revents(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
|
||||||
int snd_mixer_load(snd_mixer_t *mixer);
|
|
||||||
void snd_mixer_free(snd_mixer_t *mixer);
|
|
||||||
int snd_mixer_wait(snd_mixer_t *mixer, int timeout);
|
|
||||||
int snd_mixer_set_compare(snd_mixer_t *mixer, snd_mixer_compare_t msort);
|
|
||||||
void snd_mixer_set_callback(snd_mixer_t *obj, snd_mixer_callback_t val);
|
|
||||||
void * snd_mixer_get_callback_private(const snd_mixer_t *obj);
|
|
||||||
void snd_mixer_set_callback_private(snd_mixer_t *obj, void * val);
|
|
||||||
unsigned int snd_mixer_get_count(const snd_mixer_t *obj);
|
|
||||||
int snd_mixer_class_unregister(snd_mixer_class_t *clss);
|
|
||||||
|
|
||||||
snd_mixer_elem_t *snd_mixer_elem_next(snd_mixer_elem_t *elem);
|
|
||||||
snd_mixer_elem_t *snd_mixer_elem_prev(snd_mixer_elem_t *elem);
|
|
||||||
void snd_mixer_elem_set_callback(snd_mixer_elem_t *obj, snd_mixer_elem_callback_t val);
|
|
||||||
void * snd_mixer_elem_get_callback_private(const snd_mixer_elem_t *obj);
|
|
||||||
void snd_mixer_elem_set_callback_private(snd_mixer_elem_t *obj, void * val);
|
|
||||||
snd_mixer_elem_type_t snd_mixer_elem_get_type(const snd_mixer_elem_t *obj);
|
|
||||||
|
|
||||||
int snd_mixer_class_register(snd_mixer_class_t *class_, snd_mixer_t *mixer);
|
|
||||||
int snd_mixer_elem_new(snd_mixer_elem_t **elem,
|
|
||||||
snd_mixer_elem_type_t type,
|
|
||||||
int compare_weight,
|
|
||||||
void *private_data,
|
|
||||||
void (*private_free)(snd_mixer_elem_t *elem));
|
|
||||||
int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class_);
|
|
||||||
int snd_mixer_elem_remove(snd_mixer_elem_t *elem);
|
|
||||||
void snd_mixer_elem_free(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_elem_info(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_elem_value(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_elem_attach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
|
|
||||||
int snd_mixer_elem_detach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
|
|
||||||
int snd_mixer_elem_empty(snd_mixer_elem_t *melem);
|
|
||||||
void *snd_mixer_elem_get_private(const snd_mixer_elem_t *melem);
|
|
||||||
|
|
||||||
size_t snd_mixer_class_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_mixer_class_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_mixer_class_alloca(ptr) __snd_alloca(ptr, snd_mixer_class)
|
|
||||||
int snd_mixer_class_malloc(snd_mixer_class_t **ptr);
|
|
||||||
void snd_mixer_class_free(snd_mixer_class_t *obj);
|
|
||||||
void snd_mixer_class_copy(snd_mixer_class_t *dst, const snd_mixer_class_t *src);
|
|
||||||
snd_mixer_t *snd_mixer_class_get_mixer(const snd_mixer_class_t *class_);
|
|
||||||
snd_mixer_event_t snd_mixer_class_get_event(const snd_mixer_class_t *class_);
|
|
||||||
void *snd_mixer_class_get_private(const snd_mixer_class_t *class_);
|
|
||||||
snd_mixer_compare_t snd_mixer_class_get_compare(const snd_mixer_class_t *class_);
|
|
||||||
int snd_mixer_class_set_event(snd_mixer_class_t *class_, snd_mixer_event_t event);
|
|
||||||
int snd_mixer_class_set_private(snd_mixer_class_t *class_, void *private_data);
|
|
||||||
int snd_mixer_class_set_private_free(snd_mixer_class_t *class_, void (*private_free)(snd_mixer_class_t *));
|
|
||||||
int snd_mixer_class_set_compare(snd_mixer_class_t *class_, snd_mixer_compare_t compare);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup SimpleMixer Simple Mixer Interface
|
|
||||||
* \ingroup Mixer
|
|
||||||
* The simple mixer interface.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Simple mixer elements API */
|
|
||||||
|
|
||||||
/** Mixer simple element channel identifier */
|
|
||||||
typedef enum _snd_mixer_selem_channel_id {
|
|
||||||
/** Unknown */
|
|
||||||
SND_MIXER_SCHN_UNKNOWN = -1,
|
|
||||||
/** Front left */
|
|
||||||
SND_MIXER_SCHN_FRONT_LEFT = 0,
|
|
||||||
/** Front right */
|
|
||||||
SND_MIXER_SCHN_FRONT_RIGHT,
|
|
||||||
/** Rear left */
|
|
||||||
SND_MIXER_SCHN_REAR_LEFT,
|
|
||||||
/** Rear right */
|
|
||||||
SND_MIXER_SCHN_REAR_RIGHT,
|
|
||||||
/** Front center */
|
|
||||||
SND_MIXER_SCHN_FRONT_CENTER,
|
|
||||||
/** Woofer */
|
|
||||||
SND_MIXER_SCHN_WOOFER,
|
|
||||||
/** Side Left */
|
|
||||||
SND_MIXER_SCHN_SIDE_LEFT,
|
|
||||||
/** Side Right */
|
|
||||||
SND_MIXER_SCHN_SIDE_RIGHT,
|
|
||||||
/** Rear Center */
|
|
||||||
SND_MIXER_SCHN_REAR_CENTER,
|
|
||||||
SND_MIXER_SCHN_LAST = 31,
|
|
||||||
/** Mono (Front left alias) */
|
|
||||||
SND_MIXER_SCHN_MONO = SND_MIXER_SCHN_FRONT_LEFT
|
|
||||||
} snd_mixer_selem_channel_id_t;
|
|
||||||
|
|
||||||
/** Mixer simple element - register options - abstraction level */
|
|
||||||
enum snd_mixer_selem_regopt_abstract {
|
|
||||||
/** no abstraction - try use all universal controls from driver */
|
|
||||||
SND_MIXER_SABSTRACT_NONE = 0,
|
|
||||||
/** basic abstraction - Master,PCM,CD,Aux,Record-Gain etc. */
|
|
||||||
SND_MIXER_SABSTRACT_BASIC,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Mixer simple element - register options */
|
|
||||||
struct snd_mixer_selem_regopt {
|
|
||||||
/** structure version */
|
|
||||||
int ver;
|
|
||||||
/** v1: abstract layer selection */
|
|
||||||
enum snd_mixer_selem_regopt_abstract abstract;
|
|
||||||
/** v1: device name (must be NULL when playback_pcm or capture_pcm != NULL) */
|
|
||||||
const char *device;
|
|
||||||
/** v1: playback PCM connected to mixer device (NULL == none) */
|
|
||||||
snd_pcm_t *playback_pcm;
|
|
||||||
/** v1: capture PCM connected to mixer device (NULL == none) */
|
|
||||||
snd_pcm_t *capture_pcm;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Mixer simple element identifier */
|
|
||||||
typedef struct _snd_mixer_selem_id snd_mixer_selem_id_t;
|
|
||||||
|
|
||||||
const char *snd_mixer_selem_channel_name(snd_mixer_selem_channel_id_t channel);
|
|
||||||
|
|
||||||
int snd_mixer_selem_register(snd_mixer_t *mixer,
|
|
||||||
struct snd_mixer_selem_regopt *options,
|
|
||||||
snd_mixer_class_t **classp);
|
|
||||||
void snd_mixer_selem_get_id(snd_mixer_elem_t *element,
|
|
||||||
snd_mixer_selem_id_t *id);
|
|
||||||
const char *snd_mixer_selem_get_name(snd_mixer_elem_t *elem);
|
|
||||||
unsigned int snd_mixer_selem_get_index(snd_mixer_elem_t *elem);
|
|
||||||
snd_mixer_elem_t *snd_mixer_find_selem(snd_mixer_t *mixer,
|
|
||||||
const snd_mixer_selem_id_t *id);
|
|
||||||
|
|
||||||
int snd_mixer_selem_is_active(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_is_playback_mono(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_playback_channel(snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel);
|
|
||||||
int snd_mixer_selem_is_capture_mono(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_channel(snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel);
|
|
||||||
int snd_mixer_selem_get_capture_group(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_common_volume(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_playback_volume(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_playback_volume_joined(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_volume(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_volume_joined(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_common_switch(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_playback_switch(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_playback_switch_joined(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_switch(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_switch_joined(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_has_capture_switch_exclusive(snd_mixer_elem_t *elem);
|
|
||||||
|
|
||||||
int snd_mixer_selem_ask_playback_vol_dB(snd_mixer_elem_t *elem, long value, long *dBvalue);
|
|
||||||
int snd_mixer_selem_ask_capture_vol_dB(snd_mixer_elem_t *elem, long value, long *dBvalue);
|
|
||||||
int snd_mixer_selem_ask_playback_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value);
|
|
||||||
int snd_mixer_selem_ask_capture_dB_vol(snd_mixer_elem_t *elem, long dBvalue, int dir, long *value);
|
|
||||||
int snd_mixer_selem_get_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int snd_mixer_selem_get_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int snd_mixer_selem_get_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int snd_mixer_selem_get_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int snd_mixer_selem_get_playback_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value);
|
|
||||||
int snd_mixer_selem_get_capture_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int *value);
|
|
||||||
int snd_mixer_selem_set_playback_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value);
|
|
||||||
int snd_mixer_selem_set_capture_volume(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value);
|
|
||||||
int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir);
|
|
||||||
int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir);
|
|
||||||
int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t *elem, long value);
|
|
||||||
int snd_mixer_selem_set_capture_volume_all(snd_mixer_elem_t *elem, long value);
|
|
||||||
int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir);
|
|
||||||
int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir);
|
|
||||||
int snd_mixer_selem_set_playback_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
|
|
||||||
int snd_mixer_selem_set_capture_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
|
|
||||||
int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t *elem, int value);
|
|
||||||
int snd_mixer_selem_set_capture_switch_all(snd_mixer_elem_t *elem, int value);
|
|
||||||
int snd_mixer_selem_get_playback_volume_range(snd_mixer_elem_t *elem,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_mixer_selem_get_playback_dB_range(snd_mixer_elem_t *elem,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_mixer_selem_set_playback_volume_range(snd_mixer_elem_t *elem,
|
|
||||||
long min, long max);
|
|
||||||
int snd_mixer_selem_get_capture_volume_range(snd_mixer_elem_t *elem,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_mixer_selem_get_capture_dB_range(snd_mixer_elem_t *elem,
|
|
||||||
long *min, long *max);
|
|
||||||
int snd_mixer_selem_set_capture_volume_range(snd_mixer_elem_t *elem,
|
|
||||||
long min, long max);
|
|
||||||
|
|
||||||
int snd_mixer_selem_is_enumerated(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_is_enum_playback(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_is_enum_capture(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_get_enum_items(snd_mixer_elem_t *elem);
|
|
||||||
int snd_mixer_selem_get_enum_item_name(snd_mixer_elem_t *elem, unsigned int idx, size_t maxlen, char *str);
|
|
||||||
int snd_mixer_selem_get_enum_item(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int *idxp);
|
|
||||||
int snd_mixer_selem_set_enum_item(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int idx);
|
|
||||||
|
|
||||||
size_t snd_mixer_selem_id_sizeof(void);
|
|
||||||
/** \hideinitializer
|
|
||||||
* \brief allocate an invalid #snd_mixer_selem_id_t using standard alloca
|
|
||||||
* \param ptr returned pointer
|
|
||||||
*/
|
|
||||||
#define snd_mixer_selem_id_alloca(ptr) __snd_alloca(ptr, snd_mixer_selem_id)
|
|
||||||
int snd_mixer_selem_id_malloc(snd_mixer_selem_id_t **ptr);
|
|
||||||
void snd_mixer_selem_id_free(snd_mixer_selem_id_t *obj);
|
|
||||||
void snd_mixer_selem_id_copy(snd_mixer_selem_id_t *dst, const snd_mixer_selem_id_t *src);
|
|
||||||
const char *snd_mixer_selem_id_get_name(const snd_mixer_selem_id_t *obj);
|
|
||||||
unsigned int snd_mixer_selem_id_get_index(const snd_mixer_selem_id_t *obj);
|
|
||||||
void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t *obj, const char *val);
|
|
||||||
void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t *obj, unsigned int val);
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_MIXER_H */
|
|
||||||
|
|
112
raylib/external/alsa/mixer_abst.h
vendored
112
raylib/external/alsa/mixer_abst.h
vendored
|
@ -1,112 +0,0 @@
|
||||||
/**
|
|
||||||
* \file include/mixer_abst.h
|
|
||||||
* \brief Mixer abstract implementation interface library for the ALSA library
|
|
||||||
* \author Jaroslav Kysela <perex@perex.cz>
|
|
||||||
* \date 2005
|
|
||||||
*
|
|
||||||
* Mixer abstact implementation interface library for the ALSA library
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* This library is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2.1 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __ALSA_MIXER_ABST_H
|
|
||||||
#define __ALSA_MIXER_ABST_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \defgroup Mixer_Abstract Mixer Abstact Module Interface
|
|
||||||
* The mixer abstact module interface.
|
|
||||||
* \{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define SM_PLAY 0
|
|
||||||
#define SM_CAPT 1
|
|
||||||
|
|
||||||
#define SM_CAP_GVOLUME (1<<1)
|
|
||||||
#define SM_CAP_GSWITCH (1<<2)
|
|
||||||
#define SM_CAP_PVOLUME (1<<3)
|
|
||||||
#define SM_CAP_PVOLUME_JOIN (1<<4)
|
|
||||||
#define SM_CAP_PSWITCH (1<<5)
|
|
||||||
#define SM_CAP_PSWITCH_JOIN (1<<6)
|
|
||||||
#define SM_CAP_CVOLUME (1<<7)
|
|
||||||
#define SM_CAP_CVOLUME_JOIN (1<<8)
|
|
||||||
#define SM_CAP_CSWITCH (1<<9)
|
|
||||||
#define SM_CAP_CSWITCH_JOIN (1<<10)
|
|
||||||
#define SM_CAP_CSWITCH_EXCL (1<<11)
|
|
||||||
#define SM_CAP_PENUM (1<<12)
|
|
||||||
#define SM_CAP_CENUM (1<<13)
|
|
||||||
/* SM_CAP_* 24-31 => private for module use */
|
|
||||||
|
|
||||||
#define SM_OPS_IS_ACTIVE 0
|
|
||||||
#define SM_OPS_IS_MONO 1
|
|
||||||
#define SM_OPS_IS_CHANNEL 2
|
|
||||||
#define SM_OPS_IS_ENUMERATED 3
|
|
||||||
#define SM_OPS_IS_ENUMCNT 4
|
|
||||||
|
|
||||||
#define sm_selem(x) ((sm_selem_t *)((x)->private_data))
|
|
||||||
#define sm_selem_ops(x) ((sm_selem_t *)((x)->private_data))->ops
|
|
||||||
|
|
||||||
typedef struct _sm_selem {
|
|
||||||
snd_mixer_selem_id_t *id;
|
|
||||||
struct sm_elem_ops *ops;
|
|
||||||
unsigned int caps;
|
|
||||||
unsigned int capture_group;
|
|
||||||
} sm_selem_t;
|
|
||||||
|
|
||||||
typedef struct _sm_class_basic {
|
|
||||||
char *device;
|
|
||||||
snd_ctl_t *ctl;
|
|
||||||
snd_hctl_t *hctl;
|
|
||||||
snd_ctl_card_info_t *info;
|
|
||||||
} sm_class_basic_t;
|
|
||||||
|
|
||||||
struct sm_elem_ops {
|
|
||||||
int (*is)(snd_mixer_elem_t *elem, int dir, int cmd, int val);
|
|
||||||
int (*get_range)(snd_mixer_elem_t *elem, int dir, long *min, long *max);
|
|
||||||
int (*set_range)(snd_mixer_elem_t *elem, int dir, long min, long max);
|
|
||||||
int (*get_dB_range)(snd_mixer_elem_t *elem, int dir, long *min, long *max);
|
|
||||||
int (*ask_vol_dB)(snd_mixer_elem_t *elem, int dir, long value, long *dbValue);
|
|
||||||
int (*ask_dB_vol)(snd_mixer_elem_t *elem, int dir, long dbValue, long *value, int xdir);
|
|
||||||
int (*get_volume)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int (*get_dB)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long *value);
|
|
||||||
int (*set_volume)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long value);
|
|
||||||
int (*set_dB)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long value, int xdir);
|
|
||||||
int (*get_switch)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, int *value);
|
|
||||||
int (*set_switch)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, int value);
|
|
||||||
int (*enum_item_name)(snd_mixer_elem_t *elem, unsigned int item, size_t maxlen, char *buf);
|
|
||||||
int (*get_enum_item)(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int *itemp);
|
|
||||||
int (*set_enum_item)(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int item);
|
|
||||||
};
|
|
||||||
|
|
||||||
int snd_mixer_selem_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2);
|
|
||||||
|
|
||||||
int snd_mixer_sbasic_info(const snd_mixer_class_t *class, sm_class_basic_t *info);
|
|
||||||
void *snd_mixer_sbasic_get_private(const snd_mixer_class_t *class);
|
|
||||||
void snd_mixer_sbasic_set_private(const snd_mixer_class_t *class, void *private_data);
|
|
||||||
void snd_mixer_sbasic_set_private_free(const snd_mixer_class_t *class, void (*private_free)(snd_mixer_class_t *class));
|
|
||||||
|
|
||||||
/** \} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* __ALSA_MIXER_ABST_H */
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue