Merge branch 'master' into master
This commit is contained in:
commit
5173b74485
144 changed files with 166843 additions and 8091 deletions
|
@ -4,13 +4,13 @@ To compile example to shared library you will need [Android NDK](https://develop
|
|||
To build Android apk you will need [Android SDK](http://developer.android.com/sdk/index.html#Other).
|
||||
Download and unpack archives somewhere.
|
||||
|
||||
Go must be cross compiled for android. There is a bootstrap.sh script that you can use to compile Go and OpenAL for android/arm and android/arm64.
|
||||
Go must be cross compiled for android. There is a bootstrap.sh script that you can use to compile Go for android/arm and android/arm64.
|
||||
|
||||
Export path to Android NDK, point to location where you have unpacked archive:
|
||||
|
||||
export ANDROID_NDK_HOME=/opt/android-ndk
|
||||
|
||||
Compile Go, OpenAL and android_native_app_glue, /usr/local is prefix where Go and Android toolchains will be installed:
|
||||
Compile Go and android_native_app_glue, /usr/local is prefix where Go and Android toolchains will be installed:
|
||||
|
||||
./bootstrap.sh /usr/local
|
||||
|
||||
|
|
|
@ -37,10 +37,6 @@ if [[ -z "$GO_VERSION" ]]; then
|
|||
# go1.9.2
|
||||
GO_VERSION=`curl -s https://golang.org/dl/ | grep 'id="go' | head -n1 | awk -F'"' '{print $4}'`
|
||||
fi
|
||||
if [[ -z "$OPENAL_VERSION" ]]; then
|
||||
# 1.18.2
|
||||
OPENAL_VERSION=`curl -s http://kcat.strangesoft.net/openal.html | grep 'tar.bz2' | awk -F'"' '{print $2}' | awk -F'-' '{print $4}' | sed 's/.tar.bz2//'`
|
||||
fi
|
||||
if [[ -z "$NDK_VERSION" ]]; then
|
||||
# r15c
|
||||
NDK_VERSION=`curl -s https://developer.android.com/ndk/downloads/index.html | grep 'id="stable-downloads"' | awk -F'(' '{print $2}' | awk -F')' '{print $1}'`
|
||||
|
@ -114,50 +110,6 @@ cp -r -f ${BUILD_DIR}/go ${INSTALL_PREFIX}
|
|||
|
||||
###################################################
|
||||
|
||||
echo; echo "##### Download OpenAL ${OPENAL_VERSION}"
|
||||
|
||||
cd ${BUILD_DIR} && curl -L --progress-bar http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2 | tar -xj || exit 1
|
||||
|
||||
echo; echo "##### Compile OpenAL ${OPENAL_VERSION}"
|
||||
|
||||
cat << EOF > ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/android-arm.cmake
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_ANDROID_ARCH arm)
|
||||
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
|
||||
set(TOOLCHAIN_PREFIX arm-linux-androideabi)
|
||||
set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-${MYCC})
|
||||
set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PREFIX}-${MYCXX})
|
||||
set(CMAKE_FIND_ROOT_PATH \${INSTALL_PREFIX}/android-arm)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
EOF
|
||||
|
||||
cat << EOF > ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/android-arm64.cmake
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_ANDROID_ARCH arm64)
|
||||
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
|
||||
set(TOOLCHAIN_PREFIX aarch64-linux-android)
|
||||
set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-${MYCC})
|
||||
set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PREFIX}-${MYCXX})
|
||||
set(CMAKE_FIND_ROOT_PATH \${INSTALL_PREFIX}/android-arm64)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
EOF
|
||||
|
||||
mkdir -p ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-arm
|
||||
cd ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-arm
|
||||
cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../android-arm.cmake -DCMAKE_C_FLAGS="-DANDROID -D__ANDROID_API__=${API_VERSION_ARM}" -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/android-arm -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${INSTALL_PREFIX}/android-arm -DALSOFT_NO_CONFIG_UTIL=ON -DALSOFT_UTILS=OFF -DALSOFT_EXAMPLES=OFF -DALSOFT_TESTS=OFF -DALSOFT_CONFIG=OFF -DALSOFT_HRTF_DEFS=OFF -DALSOFT_AMBDEC_PRESETS=OFF .. || exit 1
|
||||
make -j $(nproc) VERBOSE=1 && make install || exit 1
|
||||
|
||||
mkdir -p ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-arm64
|
||||
cd ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-arm64
|
||||
cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../android-arm64.cmake -DCMAKE_C_FLAGS="-DANDROID -D__ANDROID_API__=${API_VERSION_ARM64}" -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/android-arm64 -DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=${INSTALL_PREFIX}/android-arm64 -DALSOFT_NO_CONFIG_UTIL=ON -DALSOFT_UTILS=OFF -DALSOFT_EXAMPLES=OFF -DALSOFT_TESTS=OFF -DALSOFT_CONFIG=OFF -DALSOFT_HRTF_DEFS=OFF -DALSOFT_AMBDEC_PRESETS=OFF .. || exit 1
|
||||
make -j $(nproc) VERBOSE=1 && make install || exit 1
|
||||
|
||||
###################################################
|
||||
|
||||
echo; echo "##### Compile android_native_app_glue"
|
||||
mkdir -p ${BUILD_DIR}/native_app_glue/jni
|
||||
cp -r ${ANDROID_NDK_HOME}/sources/android/native_app_glue/* ${BUILD_DIR}/native_app_glue/jni/
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
@ -48,7 +47,7 @@ func main() {
|
|||
numSamples = samplesLeft
|
||||
}
|
||||
|
||||
raylib.UpdateAudioStream(stream, unsafe.Pointer(&data[totalSamples-samplesLeft]), numSamples)
|
||||
raylib.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||
|
||||
samplesLeft -= numSamples
|
||||
|
||||
|
|
8
examples/others/resources/data.h
Normal file
8
examples/others/resources/data.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#define NUM_RESOURCES 6
|
||||
|
||||
#define RES_coin.wav 0x00000000 // Embedded as WAVE
|
||||
#define RES_raylib_logo.gif 0x00000001 // Embedded as IMAGE
|
||||
#define RES_raylib_logo.jpg 0x00000002 // Embedded as IMAGE
|
||||
#define RES_raylib_logo.png 0x00000003 // Embedded as IMAGE
|
||||
#define RES_raylib_logo.tga 0x00000004 // Embedded as IMAGE
|
||||
#define RES_tanatana.ogg 0x00000005 // Embedded as VORBIS
|
BIN
examples/others/resources/data.rres
Normal file
BIN
examples/others/resources/data.rres
Normal file
Binary file not shown.
95
examples/others/resources/main.go
Normal file
95
examples/others/resources/main.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
//"bytes"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const numTextures = 4
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
||||
raylib.InitWindow(screenWidth, screenHeight, "raylib [core] example - resources loading")
|
||||
|
||||
raylib.InitAudioDevice()
|
||||
|
||||
// OpenAsset() will also work on Android (reads files from assets/)
|
||||
reader, err := raylib.OpenAsset("data.rres")
|
||||
if err != nil {
|
||||
raylib.TraceLog(raylib.LogWarning, "[%s] rRES raylib resource file could not be opened: %v", "data.rres", err)
|
||||
}
|
||||
|
||||
defer reader.Close()
|
||||
|
||||
// bindata
|
||||
//b := MustAsset("data.rres")
|
||||
//reader := bytes.NewReader(b)
|
||||
|
||||
res := raylib.LoadResource(reader, 0, nil)
|
||||
wav := raylib.LoadWaveEx(res.Data, int32(res.Param1), int32(res.Param2), int32(res.Param3), int32(res.Param4))
|
||||
snd := raylib.LoadSoundFromWave(wav)
|
||||
raylib.UnloadWave(wav)
|
||||
|
||||
textures := make([]raylib.Texture2D, numTextures)
|
||||
for i := 0; i < numTextures; i++ {
|
||||
r := raylib.LoadResource(reader, i+1, nil)
|
||||
image := raylib.LoadImagePro(r.Data, int32(r.Param1), int32(r.Param2), raylib.TextureFormat(r.Param3))
|
||||
textures[i] = raylib.LoadTextureFromImage(image)
|
||||
raylib.UnloadImage(image)
|
||||
}
|
||||
|
||||
currentTexture := 0
|
||||
|
||||
raylib.SetTargetFPS(60)
|
||||
|
||||
for !raylib.WindowShouldClose() {
|
||||
if raylib.IsKeyPressed(raylib.KeySpace) {
|
||||
raylib.PlaySound(snd)
|
||||
}
|
||||
|
||||
if raylib.IsMouseButtonPressed(raylib.MouseLeftButton) {
|
||||
currentTexture = (currentTexture + 1) % numTextures // Cycle between the textures
|
||||
}
|
||||
|
||||
raylib.BeginDrawing()
|
||||
|
||||
raylib.ClearBackground(raylib.RayWhite)
|
||||
|
||||
raylib.DrawTexture(textures[currentTexture], screenWidth/2-textures[currentTexture].Width/2, screenHeight/2-textures[currentTexture].Height/2, raylib.RayWhite)
|
||||
|
||||
raylib.DrawText("MOUSE LEFT BUTTON to CYCLE TEXTURES", 40, 410, 10, raylib.Gray)
|
||||
raylib.DrawText("SPACE to PLAY SOUND", 40, 430, 10, raylib.Gray)
|
||||
|
||||
switch currentTexture {
|
||||
case 0:
|
||||
raylib.DrawText("GIF", 272, 70, 20, raylib.Gray)
|
||||
break
|
||||
case 1:
|
||||
raylib.DrawText("JPEG", 272, 70, 20, raylib.Gray)
|
||||
break
|
||||
case 2:
|
||||
raylib.DrawText("PNG", 272, 70, 20, raylib.Gray)
|
||||
break
|
||||
case 3:
|
||||
raylib.DrawText("TGA", 272, 70, 20, raylib.Gray)
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
raylib.EndDrawing()
|
||||
}
|
||||
|
||||
raylib.UnloadSound(snd)
|
||||
|
||||
for _, t := range textures {
|
||||
raylib.UnloadTexture(t)
|
||||
}
|
||||
|
||||
raylib.CloseAudioDevice()
|
||||
|
||||
raylib.CloseWindow()
|
||||
}
|
|
@ -9,8 +9,6 @@ GO_OS="linux"
|
|||
GO_ARCH="amd64"
|
||||
GO_VERSION=`curl -s https://golang.org/dl/ | grep 'id="go' | head -n1 | awk -F'"' '{print $4}'`
|
||||
|
||||
OPENAL_VERSION="1.17.2"
|
||||
|
||||
INSTALL_PREFIX="$1"
|
||||
export PATH=${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}
|
||||
|
||||
|
@ -39,23 +37,5 @@ GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=arm-linux-gnueabihf-gcc
|
|||
|
||||
cp -r -f ${BUILD_DIR}/go ${INSTALL_PREFIX}
|
||||
|
||||
echo "##### Compile OpenAL"
|
||||
|
||||
cd ${BUILD_DIR} && curl -s -L http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2 | tar -xj
|
||||
|
||||
cat << EOF > ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/linux-rpi.cmake
|
||||
set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
|
||||
set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_FIND_ROOT_PATH \${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
EOF
|
||||
|
||||
mkdir -p ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-rpi
|
||||
cd ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-rpi
|
||||
cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../linux-rpi.cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 ..
|
||||
make -j $(nproc) && make install
|
||||
|
||||
echo "##### Remove build directory"
|
||||
rm -rf ${BUILD_DIR}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue