From 3908769a219a050c2b09272d95f26fc1eb030f01 Mon Sep 17 00:00:00 2001 From: Milan Nikolic Date: Wed, 26 May 2021 12:01:51 +0200 Subject: [PATCH] Add FromMemory functions --- raylib/raudio.go | 24 +++++++++++++++++++++++- raylib/text.go | 14 ++++++++++++++ raylib/textures.go | 11 +++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/raylib/raudio.go b/raylib/raudio.go index 789d5f6..162d27c 100644 --- a/raylib/raudio.go +++ b/raylib/raudio.go @@ -58,6 +58,17 @@ func LoadWave(fileName string) Wave { return v } +// LoadWaveFromMemory - Load wave from memory buffer, fileType refers to extension: i.e. ".wav" +func LoadWaveFromMemory(fileType string, fileData []byte, dataSize int32) Wave { + cfileType := C.CString(fileType) + defer C.free(unsafe.Pointer(cfileType)) + cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) + cdataSize := (C.int)(dataSize) + ret := C.LoadWaveFromMemory(cfileType, cfileData, cdataSize) + v := newWaveFromPointer(unsafe.Pointer(&ret)) + return v +} + // LoadSound - Load sound to memory func LoadSound(fileName string) Sound { cfileName := C.CString(fileName) @@ -193,7 +204,18 @@ func LoadMusicStream(fileName string) Music { cfileName := C.CString(fileName) defer C.free(unsafe.Pointer(cfileName)) ret := C.LoadMusicStream(cfileName) - v := *(*Music)(unsafe.Pointer(&ret)) + v := newMusicFromPointer(unsafe.Pointer(&ret)) + return v +} + +// LoadMusicStreamFromMemory - Load music stream from data +func LoadMusicStreamFromMemory(fileType string, fileData []byte, dataSize int32) Music { + cfileType := C.CString(fileType) + defer C.free(unsafe.Pointer(cfileType)) + cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) + cdataSize := (C.int)(dataSize) + ret := C.LoadMusicStreamFromMemory(cfileType, cfileData, cdataSize) + v := newMusicFromPointer(unsafe.Pointer(&ret)) return v } diff --git a/raylib/text.go b/raylib/text.go index 2148539..0189aa6 100644 --- a/raylib/text.go +++ b/raylib/text.go @@ -55,6 +55,20 @@ func LoadFontFromImage(image Image, key Color, firstChar int32) Font { return v } +// LoadFontFromMemory - Load font from memory buffer, fileType refers to extension: i.e. ".ttf" +func LoadFontFromMemory(fileType string, fileData []byte, dataSize int32, fontSize int32, fontChars *int32, charsCount int32) Font { + cfileType := C.CString(fileType) + defer C.free(unsafe.Pointer(cfileType)) + cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) + cdataSize := (C.int)(dataSize) + cfontSize := (C.int)(fontSize) + cfontChars := (*C.int)(unsafe.Pointer(fontChars)) + ccharsCount := (C.int)(charsCount) + ret := C.LoadFontFromMemory(cfileType, cfileData, cdataSize, cfontSize, cfontChars, ccharsCount) + v := newFontFromPointer(unsafe.Pointer(&ret)) + return v +} + // LoadFontData - Load font data for further use func LoadFontData(fileData []byte, dataSize int32, fontSize int32, fontChars *int32, charsCount, typ int32) *CharInfo { cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) diff --git a/raylib/textures.go b/raylib/textures.go index 8bbff38..b1c04a6 100644 --- a/raylib/textures.go +++ b/raylib/textures.go @@ -72,6 +72,17 @@ func LoadImageAnim(fileName string, frames *int32) *Image { return v } +// LoadImageFromMemory - Load image from memory buffer, fileType refers to extension: i.e. ".png" +func LoadImageFromMemory(fileType string, fileData []byte, dataSize int32) *Image { + cfileType := C.CString(fileType) + defer C.free(unsafe.Pointer(cfileType)) + cfileData := (*C.uchar)(unsafe.Pointer(&fileData[0])) + cdataSize := (C.int)(dataSize) + ret := C.LoadImageFromMemory(cfileType, cfileData, cdataSize) + v := newImageFromPointer(unsafe.Pointer(&ret)) + return v +} + // LoadTexture - Load an image as texture into GPU memory func LoadTexture(fileName string) Texture2D { cfileName := C.CString(fileName)