Update examples
This commit is contained in:
parent
2013bc4628
commit
7b91ce25fb
8 changed files with 32 additions and 36 deletions
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"math"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -17,7 +17,7 @@ func main() {
|
|||
rl.InitAudioDevice()
|
||||
|
||||
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||
stream := rl.InitAudioStream(22050, 32, 1)
|
||||
stream := rl.LoadAudioStream(22050, 32, 1)
|
||||
|
||||
//// Fill audio stream with some samples (sine wave)
|
||||
data := make([]float32, maxSamples)
|
||||
|
@ -73,7 +73,7 @@ func main() {
|
|||
rl.EndDrawing()
|
||||
}
|
||||
|
||||
rl.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
rl.UnloadAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||
|
||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ func main() {
|
|||
}
|
||||
|
||||
if btnSaveMouseHover && rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsKeyPressed(rl.KeyS) {
|
||||
image := rl.GetTextureData(target.Texture)
|
||||
image := rl.LoadImageFromTexture(target.Texture)
|
||||
rl.ImageFlipVertical(*&image)
|
||||
rl.ExportImage(*image, "export.png")
|
||||
rl.UnloadImage(image)
|
||||
|
@ -214,4 +214,3 @@ func main() {
|
|||
os.Exit(0)
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -21,8 +21,7 @@ func main() {
|
|||
cubeSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||
|
||||
var ray rl.Ray
|
||||
|
||||
collision := false
|
||||
var collision rl.RayCollision
|
||||
|
||||
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||
|
||||
|
@ -32,12 +31,16 @@ func main() {
|
|||
rl.UpdateCamera(&camera) // Update camera
|
||||
|
||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
if !collision.Hit {
|
||||
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
||||
|
||||
// Check collision between ray and box
|
||||
min := rl.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 = rl.CheckCollisionRayBox(ray, rl.NewBoundingBox(min, max))
|
||||
collision = rl.GetRayCollisionBox(ray, rl.NewBoundingBox(min, max))
|
||||
} else {
|
||||
collision.Hit = false
|
||||
}
|
||||
}
|
||||
|
||||
rl.BeginDrawing()
|
||||
|
@ -46,7 +49,7 @@ func main() {
|
|||
|
||||
rl.BeginMode3D(camera)
|
||||
|
||||
if collision {
|
||||
if collision.Hit {
|
||||
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Red)
|
||||
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Maroon)
|
||||
|
||||
|
@ -64,7 +67,7 @@ func main() {
|
|||
|
||||
rl.DrawText("Try selecting the box with mouse!", 240, 10, 20, rl.DarkGray)
|
||||
|
||||
if collision {
|
||||
if collision.Hit {
|
||||
rl.DrawText("BOX SELECTED", (screenWidth-rl.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, rl.Green)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -29,7 +29,7 @@ func main() {
|
|||
if rl.IsGamepadAvailable(rl.GamepadPlayer1) {
|
||||
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(rl.GamepadPlayer1)), 10, 10, 10, rl.Black)
|
||||
|
||||
if rl.IsGamepadName(rl.GamepadPlayer1, xbox360NameID) {
|
||||
if rl.GetGamepadName(rl.GamepadPlayer1) == xbox360NameID {
|
||||
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)
|
||||
|
||||
// Draw buttons: xbox home
|
||||
|
@ -99,7 +99,7 @@ func main() {
|
|||
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLt))/2.0)*70), rl.Red)
|
||||
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRt))/2.0)*70), rl.Red)
|
||||
|
||||
} else if rl.IsGamepadName(rl.GamepadPlayer1, ps3NameID) {
|
||||
} else if rl.GetGamepadName(rl.GamepadPlayer1) == ps3NameID {
|
||||
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)
|
||||
|
||||
// Draw buttons: ps
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const numTextures = 7
|
||||
|
@ -17,7 +17,6 @@ func main() {
|
|||
radialGradient := rl.GenImageGradientRadial(screenWidth, screenHeight, 0, rl.White, rl.Black)
|
||||
checked := rl.GenImageChecked(screenWidth, screenHeight, 32, 32, rl.Red, rl.Blue)
|
||||
whiteNoise := rl.GenImageWhiteNoise(screenWidth, screenHeight, 0.5)
|
||||
perlinNoise := rl.GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0)
|
||||
cellular := rl.GenImageCellular(screenWidth, screenHeight, 32)
|
||||
|
||||
textures := make([]rl.Texture2D, numTextures)
|
||||
|
@ -26,8 +25,7 @@ func main() {
|
|||
textures[2] = rl.LoadTextureFromImage(radialGradient)
|
||||
textures[3] = rl.LoadTextureFromImage(checked)
|
||||
textures[4] = rl.LoadTextureFromImage(whiteNoise)
|
||||
textures[5] = rl.LoadTextureFromImage(perlinNoise)
|
||||
textures[6] = rl.LoadTextureFromImage(cellular)
|
||||
textures[5] = rl.LoadTextureFromImage(cellular)
|
||||
|
||||
// Unload image data (CPU RAM)
|
||||
rl.UnloadImage(verticalGradient)
|
||||
|
@ -35,7 +33,6 @@ func main() {
|
|||
rl.UnloadImage(radialGradient)
|
||||
rl.UnloadImage(checked)
|
||||
rl.UnloadImage(whiteNoise)
|
||||
rl.UnloadImage(perlinNoise)
|
||||
rl.UnloadImage(cellular)
|
||||
|
||||
currentTexture := 0
|
||||
|
@ -74,9 +71,6 @@ func main() {
|
|||
rl.DrawText("WHITE NOISE", 640, 10, 20, rl.Red)
|
||||
break
|
||||
case 5:
|
||||
rl.DrawText("PERLIN NOISE", 630, 10, 20, rl.RayWhite)
|
||||
break
|
||||
case 6:
|
||||
rl.DrawText("CELLULAR", 670, 10, 20, rl.RayWhite)
|
||||
break
|
||||
default:
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"image/png"
|
||||
"os"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -35,7 +35,7 @@ func main() {
|
|||
|
||||
for !rl.WindowShouldClose() {
|
||||
if rl.IsKeyPressed(rl.KeyS) {
|
||||
rimg := rl.GetTextureData(texture)
|
||||
rimg := rl.LoadImageFromTexture(texture)
|
||||
|
||||
f, err := os.Create("image_saved.png")
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const numProcesses = 8
|
||||
|
@ -98,7 +98,7 @@ func main() {
|
|||
break
|
||||
}
|
||||
|
||||
pixels := rl.GetImageData(image) // Get pixel data from image (RGBA 32bit)
|
||||
pixels := rl.LoadImageColors(image) // Get pixel data from image (RGBA 32bit)
|
||||
rl.UpdateTexture(texture, pixels) // Update texture with new image data
|
||||
|
||||
textureReload = false
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -14,7 +14,7 @@ func main() {
|
|||
texture := rl.LoadTextureFromImage(image) // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
rl.UnloadImage(image) // Unload image data from CPU memory (RAM)
|
||||
|
||||
image = rl.GetTextureData(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
image = rl.LoadImageFromTexture(texture) // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
rl.UnloadTexture(texture) // Unload texture from GPU memory (VRAM)
|
||||
|
||||
texture = rl.LoadTextureFromImage(image) // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue