Initial commit

This commit is contained in:
Milan Nikolic 2017-01-27 09:35:30 +01:00
commit d7ff68b487
196 changed files with 286314 additions and 0 deletions

405
raylib/audio.go Normal file
View file

@ -0,0 +1,405 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "reflect"
// Wave type, defines audio wave data
type Wave struct {
// Number of samples
SampleCount uint32
// Frequency (samples per second)
SampleRate uint32
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
SampleSize uint32
// Number of channels (1-mono, 2-stereo)
Channels uint32
// Buffer data pointer
Data unsafe.Pointer
}
func (w *Wave) cptr() *C.Wave {
return (*C.Wave)(unsafe.Pointer(w))
}
// Returns new Wave
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data unsafe.Pointer) Wave {
return Wave{sampleCount, sampleRate, sampleSize, channels, data}
}
// Returns new Wave from pointer
func NewWaveFromPointer(ptr unsafe.Pointer) Wave {
return *(*Wave)(ptr)
}
// Sound source type
type Sound struct {
// OpenAL audio source id
Source uint32
// OpenAL audio buffer id
Buffer uint32
// OpenAL audio format specifier
Format int32
}
func (s *Sound) cptr() *C.Sound {
return (*C.Sound)(unsafe.Pointer(s))
}
// Returns new Sound
func NewSound(source, buffer uint32, format int32) Sound {
return Sound{source, buffer, format}
}
// Returns new Sound from pointer
func NewSoundFromPointer(ptr unsafe.Pointer) Sound {
return *(*Sound)(ptr)
}
// Music type (file streaming from memory)
// NOTE: Anything longer than ~10 seconds should be streamed
type Music C.Music
// Audio stream type
// NOTE: Useful to create custom audio streams not bound to a specific file
type AudioStream struct {
// Frequency (samples per second)
SampleRate uint32
// Bit depth (bits per sample): 8, 16, 32 (24 not supported)
SampleSize uint32
// Number of channels (1-mono, 2-stereo)
Channels uint32
// OpenAL audio format specifier
Format int32
// OpenAL audio source id
Source uint32
// OpenAL audio buffers (double buffering)
Buffers [2]uint32
}
func (a *AudioStream) cptr() *C.AudioStream {
return (*C.AudioStream)(unsafe.Pointer(a))
}
// Returns new AudioStream
func NewAudioStream(sampleRate, sampleSize, channels uint32, format int32, source uint32, buffers [2]uint32) AudioStream {
return AudioStream{sampleRate, sampleSize, channels, format, source, buffers}
}
// Returns new AudioStream from pointer
func NewAudioStreamFromPointer(ptr unsafe.Pointer) AudioStream {
return *(*AudioStream)(ptr)
}
// Initialize audio device and context
func InitAudioDevice() {
C.InitAudioDevice()
}
// Close the audio device and context
func CloseAudioDevice() {
C.CloseAudioDevice()
}
// Check if audio device has been initialized successfully
func IsAudioDeviceReady() bool {
ret := C.IsAudioDeviceReady()
v := bool(int(ret) == 1)
return v
}
// Load wave data from file into RAM
func LoadWave(fileName string) Wave {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadWave(cfileName)
v := NewWaveFromPointer(unsafe.Pointer(&ret))
return v
}
// Load wave data from float array data (32bit)
func LoadWaveEx(data []float32, sampleCount int32, sampleRate int32, sampleSize int32, channels int32) Wave {
cdata := (*C.float)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&data)).Data))
csampleCount := (C.int)(sampleCount)
csampleRate := (C.int)(sampleRate)
csampleSize := (C.int)(sampleSize)
cchannels := (C.int)(channels)
ret := C.LoadWaveEx(cdata, csampleCount, csampleRate, csampleSize, cchannels)
v := NewWaveFromPointer(unsafe.Pointer(&ret))
return v
}
// Load sound to memory
func LoadSound(fileName string) Sound {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadSound(cfileName)
v := NewSoundFromPointer(unsafe.Pointer(&ret))
return v
}
// Load sound to memory from wave data
func LoadSoundFromWave(wave Wave) Sound {
cwave := wave.cptr()
ret := C.LoadSoundFromWave(*cwave)
v := NewSoundFromPointer(unsafe.Pointer(&ret))
return v
}
// Load sound to memory from rRES file (raylib Resource)
func LoadSoundFromRES(rresName string, resId int32) Sound {
crresName := C.CString(rresName)
defer C.free(unsafe.Pointer(crresName))
cresId := (C.int)(resId)
ret := C.LoadSoundFromRES(crresName, cresId)
v := NewSoundFromPointer(unsafe.Pointer(&ret))
return v
}
// Update sound buffer with new data
func UpdateSound(sound Sound, data unsafe.Pointer, numSamples int32) {
csound := sound.cptr()
cdata := (unsafe.Pointer)(unsafe.Pointer(data))
cnumSamples := (C.int)(numSamples)
C.UpdateSound(*csound, cdata, cnumSamples)
}
// Unload wave data
func UnloadWave(wave Wave) {
cwave := wave.cptr()
C.UnloadWave(*cwave)
}
// Unload sound
func UnloadSound(sound Sound) {
csound := sound.cptr()
C.UnloadSound(*csound)
}
// Play a sound
func PlaySound(sound Sound) {
csound := sound.cptr()
C.PlaySound(*csound)
}
// Pause a sound
func PauseSound(sound Sound) {
csound := sound.cptr()
C.PauseSound(*csound)
}
// Resume a paused sound
func ResumeSound(sound Sound) {
csound := sound.cptr()
C.ResumeSound(*csound)
}
// Stop playing a sound
func StopSound(sound Sound) {
csound := sound.cptr()
C.StopSound(*csound)
}
// Check if a sound is currently playing
func IsSoundPlaying(sound Sound) bool {
csound := sound.cptr()
ret := C.IsSoundPlaying(*csound)
v := bool(int(ret) == 1)
return v
}
// Set volume for a sound (1.0 is max level)
func SetSoundVolume(sound Sound, volume float32) {
csound := sound.cptr()
cvolume := (C.float)(volume)
C.SetSoundVolume(*csound, cvolume)
}
// Set pitch for a sound (1.0 is base level)
func SetSoundPitch(sound Sound, pitch float32) {
csound := sound.cptr()
cpitch := (C.float)(pitch)
C.SetSoundPitch(*csound, cpitch)
}
// Convert wave data to desired format
func WaveFormat(wave Wave, sampleRate int32, sampleSize int32, channels int32) {
cwave := wave.cptr()
csampleRate := (C.int)(sampleRate)
csampleSize := (C.int)(sampleSize)
cchannels := (C.int)(channels)
C.WaveFormat(cwave, csampleRate, csampleSize, cchannels)
}
// Copy a wave to a new wave
func WaveCopy(wave Wave) Wave {
cwave := wave.cptr()
ret := C.WaveCopy(*cwave)
v := NewWaveFromPointer(unsafe.Pointer(&ret))
return v
}
// Crop a wave to defined samples range
func WaveCrop(wave Wave, initSample int32, finalSample int32) {
cwave := wave.cptr()
cinitSample := (C.int)(initSample)
cfinalSample := (C.int)(finalSample)
C.WaveCrop(cwave, cinitSample, cfinalSample)
}
// Get samples data from wave as a floats array
func GetWaveData(wave Wave) []float32 {
var data []float32
cwave := wave.cptr()
ret := C.GetWaveData(*cwave)
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
sliceHeader.Cap = int(wave.SampleCount)
sliceHeader.Len = int(wave.SampleCount)
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
return data
}
// Load music stream from file
func LoadMusicStream(fileName string) Music {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadMusicStream(cfileName)
v := *(*Music)(unsafe.Pointer(&ret))
return v
}
// Unload music stream
func UnloadMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.UnloadMusicStream(cmusic)
}
// Start music playing
func PlayMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.PlayMusicStream(cmusic)
}
// Updates buffers for music streaming
func UpdateMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.UpdateMusicStream(cmusic)
}
// Stop music playing
func StopMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.StopMusicStream(cmusic)
}
// Pause music playing
func PauseMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.PauseMusicStream(cmusic)
}
// Resume playing paused music
func ResumeMusicStream(music Music) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
C.ResumeMusicStream(cmusic)
}
// Check if music is playing
func IsMusicPlaying(music Music) bool {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
ret := C.IsMusicPlaying(cmusic)
v := bool(int(ret) == 1)
return v
}
// Set volume for music (1.0 is max level)
func SetMusicVolume(music Music, volume float32) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
cvolume := (C.float)(volume)
C.SetMusicVolume(cmusic, cvolume)
}
// Set pitch for a music (1.0 is base level)
func SetMusicPitch(music Music, pitch float32) {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
cpitch := (C.float)(pitch)
C.SetMusicPitch(cmusic, cpitch)
}
// Get music time length (in seconds)
func GetMusicTimeLength(music Music) float32 {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
ret := C.GetMusicTimeLength(cmusic)
v := (float32)(ret)
return v
}
// Get current music time played (in seconds)
func GetMusicTimePlayed(music Music) float32 {
cmusic := *(*C.Music)(unsafe.Pointer(&music))
ret := C.GetMusicTimePlayed(cmusic)
v := (float32)(ret)
return v
}
// Init audio stream (to stream raw audio pcm data)
func InitAudioStream(sampleRate uint32, sampleSize uint32, channels uint32) AudioStream {
csampleRate := (C.uint)(sampleRate)
csampleSize := (C.uint)(sampleSize)
cchannels := (C.uint)(channels)
ret := C.InitAudioStream(csampleRate, csampleSize, cchannels)
v := NewAudioStreamFromPointer(unsafe.Pointer(&ret))
return v
}
// Update audio stream buffers with data
func UpdateAudioStream(stream AudioStream, data unsafe.Pointer, numSamples int32) {
cstream := stream.cptr()
cdata := (unsafe.Pointer)(unsafe.Pointer(data))
cnumSamples := (C.int)(numSamples)
C.UpdateAudioStream(*cstream, cdata, cnumSamples)
}
// Close audio stream and free memory
func CloseAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.CloseAudioStream(*cstream)
}
// Check if any audio stream buffers requires refill
func IsAudioBufferProcessed(stream AudioStream) bool {
cstream := stream.cptr()
ret := C.IsAudioBufferProcessed(*cstream)
v := bool(int(ret) == 1)
return v
}
// Play audio stream
func PlayAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.PlayAudioStream(*cstream)
}
// Pause audio stream
func PauseAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.PauseAudioStream(*cstream)
}
// Resume audio stream
func ResumeAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.ResumeAudioStream(*cstream)
}
// Stop audio stream
func StopAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.StopAudioStream(*cstream)
}

50
raylib/camera.go Normal file
View file

@ -0,0 +1,50 @@
// +build !android
package raylib
/*
#include "raylib.h"
*/
import "C"
// Set camera mode (multiple camera modes available)
func SetCameraMode(camera Camera, mode CameraMode) {
ccamera := camera.cptr()
cmode := (C.int)(mode)
C.SetCameraMode(*ccamera, cmode)
}
// Update camera position for selected mode
func UpdateCamera(camera *Camera) {
ccamera := camera.cptr()
C.UpdateCamera(ccamera)
}
// Set camera pan key to combine with mouse movement (free camera)
func SetCameraPanControl(panKey int32) {
cpanKey := (C.int)(panKey)
C.SetCameraPanControl(cpanKey)
}
// Set camera alt key to combine with mouse movement (free camera)
func SetCameraAltControl(altKey int32) {
caltKey := (C.int)(altKey)
C.SetCameraAltControl(caltKey)
}
// Set camera smooth zoom key to combine with mouse (free camera)
func SetCameraSmoothZoomControl(szKey int32) {
cszKey := (C.int)(szKey)
C.SetCameraSmoothZoomControl(cszKey)
}
// Set camera move controls (1st person and 3rd person cameras)
func SetCameraMoveControls(frontKey int32, backKey int32, rightKey int32, leftKey int32, upKey int32, downKey int32) {
cfrontKey := (C.int)(frontKey)
cbackKey := (C.int)(backKey)
crightKey := (C.int)(rightKey)
cleftKey := (C.int)(leftKey)
cupKey := (C.int)(upKey)
cdownKey := (C.int)(downKey)
C.SetCameraMoveControls(cfrontKey, cbackKey, crightKey, cleftKey, cupKey, cdownKey)
}

14
raylib/cgo.go Normal file
View file

@ -0,0 +1,14 @@
package raylib
/*
#cgo linux,!arm LDFLAGS: -lraylib -lglfw3 -lGL -lopenal -lm -pthread -ldl -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
#cgo linux,arm,!android LDFLAGS: -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lvcos -lvchiq_arm -lopenal
#cgo windows LDFLAGS: -lraylib -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm
#cgo darwin LDFLAGS: -lraylib -lglfw3 -framework OpenGL -framework OpenAl -framework Cocoa
#cgo android LDFLAGS: -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -lopenal -lm -landroid_native_app_glue
#cgo linux,windows,darwin,!android,!arm CFLAGS: -DPLATFORM_DESKTOP
#cgo linux,arm,!android CFLAGS: -DPLATFORM_RPI
#cgo android CFLAGS: -DPLATFORM_ANDROID
*/
import "C"

973
raylib/core.go Normal file
View file

@ -0,0 +1,973 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "reflect"
const (
// Some basic Defines
Pi = 3.1415927
Deg2rad = 0.017453292
Rad2deg = 57.295776
// Raylib Config Flags
FlagFullscreenMode = 1
FlagResizableWindow = 2
FlagShowLogo = 4
FlagShowMouseCursor = 8
FlagCenteredMode = 16
FlagMsaa4xHint = 32
FlagVsyncHint = 64
// Keyboard Function Keys
KeySpace = 32
KeyEscape = 256
KeyEnter = 257
KeyBackspace = 259
KeyRight = 262
KeyLeft = 263
KeyDown = 264
KeyUp = 265
KeyF1 = 290
KeyF2 = 291
KeyF3 = 292
KeyF4 = 293
KeyF5 = 294
KeyF6 = 295
KeyF7 = 296
KeyF8 = 297
KeyF9 = 298
KeyF10 = 299
KeyF11 = 300
KeyF12 = 301
KeyLeftShift = 340
KeyLeftControl = 341
KeyLeftAlt = 342
KeyRightShift = 344
KeyRightControl = 345
KeyRightAlt = 346
// Keyboard Alpha Numeric Keys
KeyZero = 48
KeyOne = 49
KeyTwo = 50
KeyThree = 51
KeyFour = 52
KeyFive = 53
KeySix = 54
KeySeven = 55
KeyEight = 56
KeyNine = 57
KeyA = 65
KeyB = 66
KeyC = 67
KeyD = 68
KeyE = 69
KeyF = 70
KeyG = 71
KeyH = 72
KeyI = 73
KeyJ = 74
KeyK = 75
KeyL = 76
KeyM = 77
KeyN = 78
KeyO = 79
KeyP = 80
KeyQ = 81
KeyR = 82
KeyS = 83
KeyT = 84
KeyU = 85
KeyV = 86
KeyW = 87
KeyX = 88
KeyY = 89
KeyZ = 90
// Android keys
KeyBack = 4
KeyMenu = 82
KeyVolumeUp = 24
KeyVolumeDown = 25
// Mouse Buttons
MouseLeftButton = 0
MouseRightButton = 1
MouseMiddleButton = 2
// Touch points registered
MaxTouchPoints = 2
// Gamepad Number
GamepadPlayer1 = 0
GamepadPlayer2 = 1
GamepadPlayer3 = 2
GamepadPlayer4 = 3
// Gamepad Buttons/Axis
// PS3 USB Controller Buttons
GamepadPs3ButtonTriangle = 0
GamepadPs3ButtonCircle = 1
GamepadPs3ButtonCross = 2
GamepadPs3ButtonSquare = 3
GamepadPs3ButtonL1 = 6
GamepadPs3ButtonR1 = 7
GamepadPs3ButtonL2 = 4
GamepadPs3ButtonR2 = 5
GamepadPs3ButtonStart = 8
GamepadPs3ButtonSelect = 9
GamepadPs3ButtonUp = 24
GamepadPs3ButtonRight = 25
GamepadPs3ButtonDown = 26
GamepadPs3ButtonLeft = 27
GamepadPs3ButtonPs = 12
// PS3 USB Controller Axis
GamepadPs3AxisLeftX = 0
GamepadPs3AxisLeftY = 1
GamepadPs3AxisRightX = 2
GamepadPs3AxisRightY = 5
// [1..-1] (pressure-level)
GamepadPs3AxisL2 = 3
// [1..-1] (pressure-level)
GamepadPs3AxisR2 = 4
// Xbox360 USB Controller Buttons
GamepadXboxButtonA = 0
GamepadXboxButtonB = 1
GamepadXboxButtonX = 2
GamepadXboxButtonY = 3
GamepadXboxButtonLb = 4
GamepadXboxButtonRb = 5
GamepadXboxButtonSelect = 6
GamepadXboxButtonStart = 7
GamepadXboxButtonUp = 10
GamepadXboxButtonRight = 11
GamepadXboxButtonDown = 12
GamepadXboxButtonLeft = 13
GamepadXboxButtonHome = 8
// Xbox360 USB Controller Axis
// [-1..1] (left->right)
GamepadXboxAxisLeftX = 0
// [1..-1] (up->down)
GamepadXboxAxisLeftY = 1
// [-1..1] (left->right)
GamepadXboxAxisRightX = 2
// [1..-1] (up->down)
GamepadXboxAxisRightY = 3
// [-1..1] (pressure-level)
GamepadXboxAxisLt = 4
// [-1..1] (pressure-level)
GamepadXboxAxisRt = 5
)
type Gestures int32
// Gestures type
// NOTE: It could be used as flags to enable only some gestures
const (
GestureNone Gestures = C.GESTURE_NONE
GestureTap Gestures = C.GESTURE_TAP
GestureDoubletap Gestures = C.GESTURE_DOUBLETAP
GestureHold Gestures = C.GESTURE_HOLD
GestureDrag Gestures = C.GESTURE_DRAG
GestureSwipeRight Gestures = C.GESTURE_SWIPE_RIGHT
GestureSwipeLeft Gestures = C.GESTURE_SWIPE_LEFT
GestureSwipeUp Gestures = C.GESTURE_SWIPE_UP
GestureSwipeDown Gestures = C.GESTURE_SWIPE_DOWN
GesturePinchIn Gestures = C.GESTURE_PINCH_IN
GesturePinchOut Gestures = C.GESTURE_PINCH_OUT
)
type CameraMode int32
// Camera system modes
const (
CameraCustom CameraMode = C.CAMERA_CUSTOM
CameraFree CameraMode = C.CAMERA_FREE
CameraOrbital CameraMode = C.CAMERA_ORBITAL
CameraFirstPerson CameraMode = C.CAMERA_FIRST_PERSON
CameraThirdPerson CameraMode = C.CAMERA_THIRD_PERSON
)
// Some Basic Colors
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
var (
// Light Gray
LightGray Color = NewColor(200, 200, 200, 255)
// Gray
Gray Color = NewColor(130, 130, 130, 255)
// Dark Gray
DarkGray Color = NewColor(80, 80, 80, 255)
// Yellow
Yellow Color = NewColor(253, 249, 0, 255)
// Gold
Gold Color = NewColor(255, 203, 0, 255)
// Orange
Orange Color = NewColor(255, 161, 0, 255)
// Pink
Pink Color = NewColor(255, 109, 194, 255)
// Red
Red Color = NewColor(230, 41, 55, 255)
// Maroon
Maroon Color = NewColor(190, 33, 55, 255)
// Green
Green Color = NewColor(0, 228, 48, 255)
// Lime
Lime Color = NewColor(0, 158, 47, 255)
// Dark Green
DarkGreen Color = NewColor(0, 117, 44, 255)
// Sky Blue
SkyBlue Color = NewColor(102, 191, 255, 255)
// Blue
Blue Color = NewColor(0, 121, 241, 255)
// Dark Blue
DarkBlue Color = NewColor(0, 82, 172, 255)
// Purple
Purple Color = NewColor(200, 122, 255, 255)
// Violet
Violet Color = NewColor(135, 60, 190, 255)
// Dark Purple
DarkPurple Color = NewColor(112, 31, 126, 255)
// Beige
Beige Color = NewColor(211, 176, 131, 255)
// Brown
Brown Color = NewColor(127, 106, 79, 255)
// Dark Brown
DarkBrown Color = NewColor(76, 63, 47, 255)
// White
White Color = NewColor(255, 255, 255, 255)
// Black
Black Color = NewColor(0, 0, 0, 255)
// Blank (Transparent)
Blank Color = NewColor(0, 0, 0, 0)
// Magenta
Magenta Color = NewColor(255, 0, 255, 255)
// Ray White (RayLib Logo White)
RayWhite Color = NewColor(245, 245, 245, 255)
)
// Vector2 type
type Vector2 struct {
X float32
Y float32
}
func (v *Vector2) cptr() *C.Vector2 {
return (*C.Vector2)(unsafe.Pointer(v))
}
// Returns new Vector2
func NewVector2(x, y float32) Vector2 {
return Vector2{x, y}
}
// Returns new Vector2 from pointer
func NewVector2FromPointer(ptr unsafe.Pointer) Vector2 {
return *(*Vector2)(ptr)
}
// Vector3 type
type Vector3 struct {
X float32
Y float32
Z float32
}
func (v *Vector3) cptr() *C.Vector3 {
return (*C.Vector3)(unsafe.Pointer(v))
}
// Returns new Vector3
func NewVector3(X, Y, Z float32) Vector3 {
return Vector3{X, Y, X}
}
// Returns new Vector3 from pointer
func NewVector3FromPointer(ptr unsafe.Pointer) Vector3 {
return *(*Vector3)(ptr)
}
// Matrix type (OpenGL style 4x4 - right handed, column major)
type Matrix struct {
M0, M4, M8, M12 float32
M1, M5, M9, M13 float32
M2, M6, M10, M14 float32
M3, M7, M11, M15 float32
}
func (m *Matrix) cptr() *C.Matrix {
return (*C.Matrix)(unsafe.Pointer(m))
}
// Returns new Matrix
func NewMatrix(m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15 float32) Matrix {
return Matrix{m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15}
}
// Returns new Matrix from pointer
func NewMatrixFromPointer(ptr unsafe.Pointer) Matrix {
return *(*Matrix)(ptr)
}
// Quaternion type
type Quaternion struct {
X float32
Y float32
Z float32
W float32
}
// Returns new Quaternion
func NewQuaternion(x, y, z, w float32) Quaternion {
return Quaternion{x, y, z, w}
}
// Color type, RGBA (32bit)
type Color struct {
R uint8
G uint8
B uint8
A uint8
}
func (color *Color) cptr() *C.Color {
return (*C.Color)(unsafe.Pointer(color))
}
// Returns new Color
func NewColor(r, g, b, a uint8) Color {
return Color{r, g, b, a}
}
// Returns new Color from pointer
func NewColorFromPointer(ptr unsafe.Pointer) Color {
return *(*Color)(ptr)
}
// Rectangle type
type Rectangle struct {
X int32
Y int32
Width int32
Height int32
}
func (r *Rectangle) cptr() *C.Rectangle {
return (*C.Rectangle)(unsafe.Pointer(r))
}
// Returns new Rectangle
func NewRectangle(x, y, width, height int32) Rectangle {
return Rectangle{x, y, width, height}
}
// Returns new Rectangle from pointer
func NewRectangleFromPointer(ptr unsafe.Pointer) Rectangle {
return *(*Rectangle)(ptr)
}
// Camera type, defines a camera position/orientation in 3d space
type Camera struct {
// Camera position
Position Vector3
// Camera target it looks-at
Target Vector3
// Camera up vector (rotation over its axis)
Up Vector3
// Camera field-of-view apperture in Y (degrees)
Fovy float32
}
func (c *Camera) cptr() *C.Camera {
return (*C.Camera)(unsafe.Pointer(c))
}
// Returns new Camera
func NewCamera(pos, target, up Vector3, fovy float32) Camera {
return Camera{pos, target, up, fovy}
}
// Returns new Camera from pointer
func NewCameraFromPointer(ptr unsafe.Pointer) Camera {
return *(*Camera)(ptr)
}
// Camera2D type, defines a 2d camera
type Camera2D struct {
// Camera offset (displacement from target)
Offset Vector2
// Camera target (rotation and zoom origin)
Target Vector2
// Camera rotation in degrees
Rotation float32
// Camera zoom (scaling), should be 1.0f by default
Zoom float32
}
func (c *Camera2D) cptr() *C.Camera2D {
return (*C.Camera2D)(unsafe.Pointer(c))
}
// Returns new Camera2D
func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D {
return Camera2D{offset, target, rotation, zoom}
}
// Returns new Camera2D from pointer
func NewCamera2DFromPointer(ptr unsafe.Pointer) Camera2D {
return *(*Camera2D)(ptr)
}
// Bounding box
type BoundingBox struct {
// Minimum vertex box-corner
Min Vector3
// Maximum vertex box-corner
Max Vector3
}
func (b *BoundingBox) cptr() *C.BoundingBox {
return (*C.BoundingBox)(unsafe.Pointer(b))
}
// Returns new BoundingBox
func NewBoundingBox(min, max Vector3) BoundingBox {
return BoundingBox{min, max}
}
// Returns new BoundingBox from pointer
func NewBoundingBoxFromPointer(ptr unsafe.Pointer) BoundingBox {
return *(*BoundingBox)(ptr)
}
// Close Window and Terminate Context
func CloseWindow() {
C.CloseWindow()
}
// Detect if KEY_ESCAPE pressed or Close icon pressed
func WindowShouldClose() bool {
ret := C.WindowShouldClose()
v := bool(int(ret) == 1)
return v
}
// Detect if window has been minimized (or lost focus)
func IsWindowMinimized() bool {
ret := C.IsWindowMinimized()
v := bool(int(ret) == 1)
return v
}
// Fullscreen toggle (only PLATFORM_DESKTOP)
func ToggleFullscreen() {
C.ToggleFullscreen()
}
// Get current screen width
func GetScreenWidth() int32 {
ret := C.GetScreenWidth()
v := (int32)(ret)
return v
}
// Get current screen height
func GetScreenHeight() int32 {
ret := C.GetScreenHeight()
v := (int32)(ret)
return v
}
// Sets Background Color
func ClearBackground(color Color) {
ccolor := color.cptr()
C.ClearBackground(*ccolor)
}
// Setup drawing canvas to start drawing
func BeginDrawing() {
C.BeginDrawing()
}
// End canvas drawing and Swap Buffers (Double Buffering)
func EndDrawing() {
C.EndDrawing()
}
// Initialize 2D mode with custom camera
func Begin2dMode(camera Camera2D) {
ccamera := camera.cptr()
C.Begin2dMode(*ccamera)
}
// Ends 2D mode custom camera usage
func End2dMode() {
C.End2dMode()
}
// Initializes 3D mode for drawing (Camera setup)
func Begin3dMode(camera Camera) {
ccamera := camera.cptr()
C.Begin3dMode(*ccamera)
}
// Ends 3D mode and returns to default 2D orthographic mode
func End3dMode() {
C.End3dMode()
}
// Initializes render texture for drawing
func BeginTextureMode(target RenderTexture2D) {
ctarget := target.cptr()
C.BeginTextureMode(*ctarget)
}
// Ends drawing to render texture
func EndTextureMode() {
C.EndTextureMode()
}
// Returns a ray trace from mouse position
func GetMouseRay(mousePosition Vector2, camera Camera) Ray {
cmousePosition := mousePosition.cptr()
ccamera := camera.cptr()
ret := C.GetMouseRay(*cmousePosition, *ccamera)
v := NewRayFromPointer(unsafe.Pointer(&ret))
return v
}
// Returns the screen space position from a 3d world space position
func GetWorldToScreen(position Vector3, camera Camera) Vector2 {
cposition := position.cptr()
ccamera := camera.cptr()
ret := C.GetWorldToScreen(*cposition, *ccamera)
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}
// Returns camera transform matrix (view matrix)
func GetCameraMatrix(camera Camera) Matrix {
ccamera := camera.cptr()
ret := C.GetCameraMatrix(*ccamera)
v := NewMatrixFromPointer(unsafe.Pointer(&ret))
return v
}
// Set target FPS (maximum)
func SetTargetFPS(fps int32) {
cfps := (C.int)(fps)
C.SetTargetFPS(cfps)
}
// Returns current FPS
func GetFPS() float32 {
ret := C.GetFPS()
v := (float32)(ret)
return v
}
// Returns time in seconds for one frame
func GetFrameTime() float32 {
ret := C.GetFrameTime()
v := (float32)(ret)
return v
}
// Returns a Color struct from hexadecimal value
func GetColor(hexValue int32) Color {
chexValue := (C.int)(hexValue)
ret := C.GetColor(chexValue)
v := NewColorFromPointer(unsafe.Pointer(&ret))
return v
}
// Returns hexadecimal value for a Color
func GetHexValue(color Color) int32 {
ccolor := color.cptr()
ret := C.GetHexValue(*ccolor)
v := (int32)(ret)
return v
}
// Converts Color to float array and normalizes
func ColorToFloat(color Color) []float32 {
ccolor := color.cptr()
ret := C.ColorToFloat(*ccolor)
var data []float32
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
sliceHeader.Cap = 4
sliceHeader.Len = 4
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
return data
}
// Converts Vector3 to float array
func VectorToFloat(vec Vector3) []float32 {
cvec := vec.cptr()
ret := C.VectorToFloat(*cvec)
var data []float32
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
sliceHeader.Cap = 3
sliceHeader.Len = 3
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
return data
}
// Converts Matrix to float array
func MatrixToFloat(mat Matrix) []float32 {
cmat := mat.cptr()
ret := C.MatrixToFloat(*cmat)
var data []float32
sliceHeader := (*reflect.SliceHeader)((unsafe.Pointer(&data)))
sliceHeader.Cap = 16
sliceHeader.Len = 16
sliceHeader.Data = uintptr(unsafe.Pointer(ret))
return data
}
// Returns a random value between min and max (both included)
func GetRandomValue(min int32, max int32) int32 {
cmin := (C.int)(min)
cmax := (C.int)(max)
ret := C.GetRandomValue(cmin, cmax)
v := (int32)(ret)
return v
}
// Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
func Fade(color Color, alpha float32) Color {
ccolor := color.cptr()
calpha := (C.float)(alpha)
ret := C.Fade(*ccolor, calpha)
v := NewColorFromPointer(unsafe.Pointer(&ret))
return v
}
// Setup some window configuration flags
func SetConfigFlags(flags byte) {
cflags := (C.char)(flags)
C.SetConfigFlags(cflags)
}
// Activates raylib logo at startup (can be done with flags)
func ShowLogo() {
C.ShowLogo()
}
// Storage save integer value (to defined position)
func StorageSaveValue(position int32, value int32) {
cposition := (C.int)(position)
cvalue := (C.int)(value)
C.StorageSaveValue(cposition, cvalue)
}
// Storage load integer value (from defined position)
func StorageLoadValue(position int32) int32 {
cposition := (C.int)(position)
ret := C.StorageLoadValue(cposition)
v := (int32)(ret)
return v
}
// Detect if a key has been pressed once
func IsKeyPressed(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyPressed(ckey)
v := bool(int(ret) == 1)
return v
}
// Detect if a key is being pressed
func IsKeyDown(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyDown(ckey)
v := bool(int(ret) == 1)
return v
}
// Detect if a key has been released once
func IsKeyReleased(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyReleased(ckey)
v := bool(int(ret) == 1)
return v
}
// Detect if a key is NOT being pressed
func IsKeyUp(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyUp(ckey)
v := bool(int(ret) == 1)
return v
}
// Get latest key pressed
func GetKeyPressed() int32 {
ret := C.GetKeyPressed()
v := (int32)(ret)
return v
}
// Set a custom key to exit program (default is ESC)
func SetExitKey(key int32) {
ckey := (C.int)(key)
C.SetExitKey(ckey)
}
// Detect if a gamepad is available
func IsGamepadAvailable(gamepad int32) bool {
cgamepad := (C.int)(gamepad)
ret := C.IsGamepadAvailable(cgamepad)
v := bool(int(ret) == 1)
return v
}
// Check gamepad name (if available)
func IsGamepadName(gamepad int32, name string) bool {
cgamepad := (C.int)(gamepad)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
ret := C.IsGamepadName(cgamepad, cname)
v := bool(int(ret) == 1)
return v
}
// Return gamepad internal name id
func GetGamepadName(gamepad int32) string {
cgamepad := (C.int)(gamepad)
ret := C.GetGamepadName(cgamepad)
v := C.GoString(ret)
return v
}
// Detect if a gamepad button has been pressed once
func IsGamepadButtonPressed(gamepad int32, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonPressed(cgamepad, cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a gamepad button is being pressed
func IsGamepadButtonDown(gamepad int32, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonDown(cgamepad, cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a gamepad button has been released once
func IsGamepadButtonReleased(gamepad int32, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonReleased(cgamepad, cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a gamepad button is NOT being pressed
func IsGamepadButtonUp(gamepad int32, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonUp(cgamepad, cbutton)
v := bool(int(ret) == 1)
return v
}
// Get the last gamepad button pressed
func GetGamepadButtonPressed() int32 {
ret := C.GetGamepadButtonPressed()
v := (int32)(ret)
return v
}
// Return gamepad axis count for a gamepad
func GetGamepadAxisCount(gamepad int32) int32 {
cgamepad := (C.int)(gamepad)
ret := C.GetGamepadAxisCount(cgamepad)
v := (int32)(ret)
return v
}
// Return axis movement value for a gamepad axis
func GetGamepadAxisMovement(gamepad int32, axis int32) float32 {
cgamepad := (C.int)(gamepad)
caxis := (C.int)(axis)
ret := C.GetGamepadAxisMovement(cgamepad, caxis)
v := (float32)(ret)
return v
}
// Detect if a mouse button has been pressed once
func IsMouseButtonPressed(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonPressed(cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a mouse button is being pressed
func IsMouseButtonDown(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonDown(cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a mouse button has been released once
func IsMouseButtonReleased(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonReleased(cbutton)
v := bool(int(ret) == 1)
return v
}
// Detect if a mouse button is NOT being pressed
func IsMouseButtonUp(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonUp(cbutton)
v := bool(int(ret) == 1)
return v
}
// Returns mouse position X
func GetMouseX() int32 {
ret := C.GetMouseX()
v := (int32)(ret)
return v
}
// Returns mouse position Y
func GetMouseY() int32 {
ret := C.GetMouseY()
v := (int32)(ret)
return v
}
// Returns mouse position XY
func GetMousePosition() Vector2 {
ret := C.GetMousePosition()
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}
// Set mouse position XY
func SetMousePosition(position Vector2) {
cposition := position.cptr()
C.SetMousePosition(*cposition)
}
// Returns mouse wheel movement Y
func GetMouseWheelMove() int32 {
ret := C.GetMouseWheelMove()
v := (int32)(ret)
return v
}
// Returns touch position X for touch point 0 (relative to screen size)
func GetTouchX() int32 {
ret := C.GetTouchX()
v := (int32)(ret)
return v
}
// Returns touch position Y for touch point 0 (relative to screen size)
func GetTouchY() int32 {
ret := C.GetTouchY()
v := (int32)(ret)
return v
}
// Returns touch position XY for a touch point index (relative to screen size)
func GetTouchPosition(index int32) Vector2 {
cindex := (C.int)(index)
ret := C.GetTouchPosition(cindex)
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}
// Enable a set of gestures using flags
func SetGesturesEnabled(gestureFlags uint32) {
cgestureFlags := (C.uint)(gestureFlags)
C.SetGesturesEnabled(cgestureFlags)
}
// Check if a gesture have been detected
func IsGestureDetected(gesture Gestures) bool {
cgesture := (C.int)(gesture)
ret := C.IsGestureDetected(cgesture)
v := bool(int(ret) == 1)
return v
}
// Get latest detected gesture
func GetGestureDetected() Gestures {
ret := C.GetGestureDetected()
v := (Gestures)(ret)
return v
}
// Get touch points count
func GetTouchPointsCount() int32 {
ret := C.GetTouchPointsCount()
v := (int32)(ret)
return v
}
// Get gesture hold time in milliseconds
func GetGestureHoldDuration() float32 {
ret := C.GetGestureHoldDuration()
v := (float32)(ret)
return v
}
// Get gesture drag vector
func GetGestureDragVector() Vector2 {
ret := C.GetGestureDragVector()
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}
// Get gesture drag angle
func GetGestureDragAngle() float32 {
ret := C.GetGestureDragAngle()
v := (float32)(ret)
return v
}
// Get gesture pinch delta
func GetGesturePinchVector() Vector2 {
ret := C.GetGesturePinchVector()
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}
// Get gesture pinch angle
func GetGesturePinchAngle() float32 {
ret := C.GetGesturePinchAngle()
v := (float32)(ret)
return v
}
// Shows current FPS
func DrawFPS(posX int32, posY int32) {
cposX := (C.int)(posX)
cposY := (C.int)(posY)
C.DrawFPS(cposX, cposY)
}

2
raylib/doc.go Normal file
View file

@ -0,0 +1,2 @@
// Go bindings for raylib, a simple and easy-to-use library to learn videogames programming.
package raylib

572
raylib/models.go Normal file
View file

@ -0,0 +1,572 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// Vertex data definning a mesh
type Mesh struct {
// Number of vertices stored in arrays
VertexCount int32
// Number of triangles stored (indexed or not)
TriangleCount int32
// Vertex position (XYZ - 3 components per vertex) (shader-location = 0)
Vertices *float32
// Vertex texture coordinates (UV - 2 components per vertex) (shader-location = 1)
Texcoords *float32
// Vertex second texture coordinates (useful for lightmaps) (shader-location = 5)
Texcoords2 *float32
// Vertex normals (XYZ - 3 components per vertex) (shader-location = 2)
Normals *float32
// Vertex tangents (XYZ - 3 components per vertex) (shader-location = 4)
Tangents *float32
// Vertex colors (RGBA - 4 components per vertex) (shader-location = 3)
Colors *uint8
// Vertex indices (in case vertex data comes indexed)
Indices *uint16
// OpenGL Vertex Array Object id
VaoId uint32
// OpenGL Vertex Buffer Objects id (7 types of vertex data)
VboId [7]uint32
}
func (m *Mesh) cptr() *C.Mesh {
return (*C.Mesh)(unsafe.Pointer(m))
}
// Returns new Mesh
func NewMesh(vertexCount, triangleCount int32, vertices, texcoords, texcoords2, normals, tangents *float32, colors *uint8, indices *uint16, vaoId uint32, vboId [7]uint32) Mesh {
return Mesh{vertexCount, triangleCount, vertices, texcoords, texcoords2, normals, tangents, colors, indices, vaoId, vboId}
}
// Returns new Mesh from pointer
func NewMeshFromPointer(ptr unsafe.Pointer) Mesh {
return *(*Mesh)(ptr)
}
// Material type
type Material struct {
// Standard shader (supports 3 map textures)
Shader Shader
// Diffuse texture (binded to shader mapTexture0Loc)
TexDiffuse Texture2D
// Normal texture (binded to shader mapTexture1Loc)
TexNormal Texture2D
// Specular texture (binded to shader mapTexture2Loc)
TexSpecular Texture2D
// Diffuse color
ColDiffuse Color
// Ambient color
ColAmbient Color
// Specular color
ColSpecular Color
// Glossiness level (Ranges from 0 to 1000)
Glossiness float32
}
func (m *Material) cptr() *C.Material {
return (*C.Material)(unsafe.Pointer(m))
}
// Returns new Material
func NewMaterial(shader Shader, texDiffuse, texNormal, texSpecular Texture2D, colDiffuse, colAmbient, colSpecular Color, glossiness float32) Material {
return Material{shader, texDiffuse, texNormal, texSpecular, colDiffuse, colAmbient, colSpecular, glossiness}
}
// Returns new Material from pointer
func NewMaterialFromPointer(ptr unsafe.Pointer) Material {
return *(*Material)(ptr)
}
// Model type
type Model struct {
// Vertex data buffers (RAM and VRAM)
Mesh Mesh
// Local transform matrix
Transform Matrix
// Shader and textures data
Material Material
// Padding
_ [4]byte
}
func (m *Model) cptr() *C.Model {
return (*C.Model)(unsafe.Pointer(m))
}
// Returns new Model
func NewModel(mesh Mesh, transform Matrix, material Material) Model {
return Model{mesh, transform, material, [4]byte{}}
}
// Returns new Model from pointer
func NewModelFromPointer(ptr unsafe.Pointer) Model {
return *(*Model)(ptr)
}
// Light type
type Light struct {
// Light unique id
Id uint32
// Light enabled
Enabled uint32
// Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
Type int32
// Light position
Position Vector3
// Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
Target Vector3
// Light attenuation radius light intensity reduced with distance (world distance)
Radius float32
// Light diffuse color
Diffuse Color
// Light intensity level
Intensity float32
// Light cone max angle: LIGHT_SPOT
ConeAngle float32
}
func (l *Light) cptr() *C.Light {
return (*C.Light)(unsafe.Pointer(l))
}
// Returns new Light
func NewLight(id uint32, enabled uint32, _type int32, position, target Vector3, radius float32, diffuse Color, intensity, coneAngle float32) Light {
return Light{id, enabled, _type, position, target, radius, diffuse, intensity, coneAngle}
}
// Returns new Light from pointer
func NewLightFromPointer(ptr unsafe.Pointer) Light {
return *(*Light)(ptr)
}
type LightType int32
// Light types
const (
LightPoint LightType = C.LIGHT_POINT
LightDirectional LightType = C.LIGHT_DIRECTIONAL
LightSpot LightType = C.LIGHT_SPOT
)
// LightData type
type LightData struct {
// Light unique id
Id uint32
// Light enabled
Enabled uint32
// Light type: LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT
Type int32
// Light position
Position Vector3
// Light direction: LIGHT_DIRECTIONAL and LIGHT_SPOT (cone direction target)
Target Vector3
// Light attenuation radius light intensity reduced with distance (world distance)
Radius float32
// Light diffuse color
Diffuse Color
// Light intensity level
Intensity float32
// Light cone max angle: LIGHT_SPOT
ConeAngle float32
}
func (l *LightData) cptr() *C.LightData {
return (*C.LightData)(unsafe.Pointer(l))
}
// Returns new LightData
func NewLightData(l Light) LightData {
return LightData{l.Id, l.Enabled, l.Type, l.Position, l.Target, l.Radius, l.Diffuse, l.Intensity, l.ConeAngle}
}
// Returns new Light from pointer
func NewLightDataFromPointer(ptr unsafe.Pointer) LightData {
return *(*LightData)(ptr)
}
// Ray type (useful for raycast)
type Ray struct {
// Ray position (origin)
Position Vector3
// Ray direction
Direction Vector3
}
func (r *Ray) cptr() *C.Ray {
return (*C.Ray)(unsafe.Pointer(r))
}
// Returns new Ray
func NewRay(position, direction Vector3) Ray {
return Ray{position, direction}
}
// Returns new Ray from pointer
func NewRayFromPointer(ptr unsafe.Pointer) Ray {
return *(*Ray)(ptr)
}
// Draw a line in 3D world space
func DrawLine3D(startPos Vector3, endPos Vector3, color Color) {
cstartPos := startPos.cptr()
cendPos := endPos.cptr()
ccolor := color.cptr()
C.DrawLine3D(*cstartPos, *cendPos, *ccolor)
}
// Draw a circle in 3D world space
func DrawCircle3D(center Vector3, radius float32, rotationAxis Vector3, rotationAngle float32, color Color) {
ccenter := center.cptr()
cradius := (C.float)(radius)
crotationAxis := rotationAxis.cptr()
crotationAngle := (C.float)(rotationAngle)
ccolor := color.cptr()
C.DrawCircle3D(*ccenter, cradius, *crotationAxis, crotationAngle, *ccolor)
}
// Draw cube
func DrawCube(position Vector3, width float32, height float32, length float32, color Color) {
cposition := position.cptr()
cwidth := (C.float)(width)
cheight := (C.float)(height)
clength := (C.float)(length)
ccolor := color.cptr()
C.DrawCube(*cposition, cwidth, cheight, clength, *ccolor)
}
// Draw cube (Vector version)
func DrawCubeV(position Vector3, size Vector3, color Color) {
cposition := position.cptr()
csize := size.cptr()
ccolor := color.cptr()
C.DrawCubeV(*cposition, *csize, *ccolor)
}
// Draw cube wires
func DrawCubeWires(position Vector3, width float32, height float32, length float32, color Color) {
cposition := position.cptr()
cwidth := (C.float)(width)
cheight := (C.float)(height)
clength := (C.float)(length)
ccolor := color.cptr()
C.DrawCubeWires(*cposition, cwidth, cheight, clength, *ccolor)
}
// Draw cube textured
func DrawCubeTexture(texture Texture2D, position Vector3, width float32, height float32, length float32, color Color) {
ctexture := texture.cptr()
cposition := position.cptr()
cwidth := (C.float)(width)
cheight := (C.float)(height)
clength := (C.float)(length)
ccolor := color.cptr()
C.DrawCubeTexture(*ctexture, *cposition, cwidth, cheight, clength, *ccolor)
}
// Draw sphere
func DrawSphere(centerPos Vector3, radius float32, color Color) {
ccenterPos := centerPos.cptr()
cradius := (C.float)(radius)
ccolor := color.cptr()
C.DrawSphere(*ccenterPos, cradius, *ccolor)
}
// Draw sphere with extended parameters
func DrawSphereEx(centerPos Vector3, radius float32, rings int32, slices int32, color Color) {
ccenterPos := centerPos.cptr()
cradius := (C.float)(radius)
crings := (C.int)(rings)
cslices := (C.int)(slices)
ccolor := color.cptr()
C.DrawSphereEx(*ccenterPos, cradius, crings, cslices, *ccolor)
}
// Draw sphere wires
func DrawSphereWires(centerPos Vector3, radius float32, rings int32, slices int32, color Color) {
ccenterPos := centerPos.cptr()
cradius := (C.float)(radius)
crings := (C.int)(rings)
cslices := (C.int)(slices)
ccolor := color.cptr()
C.DrawSphereWires(*ccenterPos, cradius, crings, cslices, *ccolor)
}
// Draw a cylinder/cone
func DrawCylinder(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, color Color) {
cposition := position.cptr()
cradiusTop := (C.float)(radiusTop)
cradiusBottom := (C.float)(radiusBottom)
cheight := (C.float)(height)
cslices := (C.int)(slices)
ccolor := color.cptr()
C.DrawCylinder(*cposition, cradiusTop, cradiusBottom, cheight, cslices, *ccolor)
}
// Draw a cylinder/cone wires
func DrawCylinderWires(position Vector3, radiusTop float32, radiusBottom float32, height float32, slices int32, color Color) {
cposition := position.cptr()
cradiusTop := (C.float)(radiusTop)
cradiusBottom := (C.float)(radiusBottom)
cheight := (C.float)(height)
cslices := (C.int)(slices)
ccolor := color.cptr()
C.DrawCylinderWires(*cposition, cradiusTop, cradiusBottom, cheight, cslices, *ccolor)
}
// Draw a plane XZ
func DrawPlane(centerPos Vector3, size Vector2, color Color) {
ccenterPos := centerPos.cptr()
csize := size.cptr()
ccolor := color.cptr()
C.DrawPlane(*ccenterPos, *csize, *ccolor)
}
// Draw a ray line
func DrawRay(ray Ray, color Color) {
cray := ray.cptr()
ccolor := color.cptr()
C.DrawRay(*cray, *ccolor)
}
// Draw a grid (centered at (0, 0, 0))
func DrawGrid(slices int32, spacing float32) {
cslices := (C.int)(slices)
cspacing := (C.float)(spacing)
C.DrawGrid(cslices, cspacing)
}
// Draw simple gizmo
func DrawGizmo(position Vector3) {
cposition := position.cptr()
C.DrawGizmo(*cposition)
}
// Draw light in 3D world
func DrawLight(light Light) {
clightdata := NewLightData(light)
C.DrawLight(clightdata.cptr())
}
// Load a 3d model (.OBJ)
func LoadModel(fileName string) Model {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadModel(cfileName)
v := NewModelFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a 3d model (from mesh data)
func LoadModelEx(data Mesh, dynamic bool) Model {
d := 0
if dynamic {
d = 1
}
cdata := data.cptr()
cdynamic := (C.bool)(d)
ret := C.LoadModelEx(*cdata, cdynamic)
v := NewModelFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a 3d model from rRES file (raylib Resource)
func LoadModelFromRES(rresName string, resId int32) Model {
crresName := C.CString(rresName)
defer C.free(unsafe.Pointer(crresName))
cresId := (C.int)(resId)
ret := C.LoadModelFromRES(crresName, cresId)
v := NewModelFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a heightmap image as a 3d model
func LoadHeightmap(heightmap *Image, size Vector3) Model {
cheightmap := heightmap.cptr()
csize := size.cptr()
ret := C.LoadHeightmap(*cheightmap, *csize)
v := NewModelFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a map image as a 3d model (cubes based)
func LoadCubicmap(cubicmap *Image) Model {
ccubicmap := cubicmap.cptr()
ret := C.LoadCubicmap(*ccubicmap)
v := NewModelFromPointer(unsafe.Pointer(&ret))
return v
}
// Unload 3d model from memory
func UnloadModel(model Model) {
cmodel := model.cptr()
C.UnloadModel(*cmodel)
}
// Load material data (.MTL)
func LoadMaterial(fileName string) Material {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadMaterial(cfileName)
v := NewMaterialFromPointer(unsafe.Pointer(&ret))
return v
}
// Load default material (uses default models shader)
func LoadDefaultMaterial() Material {
ret := C.LoadDefaultMaterial()
v := NewMaterialFromPointer(unsafe.Pointer(&ret))
return v
}
// Load standard material (uses material attributes and lighting shader)
func LoadStandardMaterial() Material {
ret := C.LoadStandardMaterial()
v := NewMaterialFromPointer(unsafe.Pointer(&ret))
return v
}
// Unload material textures from VRAM
func UnloadMaterial(material Material) {
cmaterial := material.cptr()
C.UnloadMaterial(*cmaterial)
}
// Draw a model (with texture if set)
func DrawModel(model Model, position Vector3, scale float32, tint Color) {
cmodel := model.cptr()
cposition := position.cptr()
cscale := (C.float)(scale)
ctint := tint.cptr()
C.DrawModel(*cmodel, *cposition, cscale, *ctint)
}
// Draw a model with extended parameters
func DrawModelEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint Color) {
cmodel := model.cptr()
cposition := position.cptr()
crotationAxis := rotationAxis.cptr()
crotationAngle := (C.float)(rotationAngle)
cscale := scale.cptr()
ctint := tint.cptr()
C.DrawModelEx(*cmodel, *cposition, *crotationAxis, crotationAngle, *cscale, *ctint)
}
// Draw a model wires (with texture if set)
func DrawModelWires(model Model, position Vector3, scale float32, tint Color) {
cmodel := model.cptr()
cposition := position.cptr()
cscale := (C.float)(scale)
ctint := tint.cptr()
C.DrawModelWires(*cmodel, *cposition, cscale, *ctint)
}
// Draw a model wires (with texture if set) with extended parameters
func DrawModelWiresEx(model Model, position Vector3, rotationAxis Vector3, rotationAngle float32, scale Vector3, tint Color) {
cmodel := model.cptr()
cposition := position.cptr()
crotationAxis := rotationAxis.cptr()
crotationAngle := (C.float)(rotationAngle)
cscale := scale.cptr()
ctint := tint.cptr()
C.DrawModelWiresEx(*cmodel, *cposition, *crotationAxis, crotationAngle, *cscale, *ctint)
}
// Draw bounding box (wires)
func DrawBoundingBox(box BoundingBox, color Color) {
cbox := box.cptr()
ccolor := color.cptr()
C.DrawBoundingBox(*cbox, *ccolor)
}
// Draw a billboard texture
func DrawBillboard(camera Camera, texture Texture2D, center Vector3, size float32, tint Color) {
ccamera := camera.cptr()
ctexture := texture.cptr()
ccenter := center.cptr()
csize := (C.float)(size)
ctint := tint.cptr()
C.DrawBillboard(*ccamera, *ctexture, *ccenter, csize, *ctint)
}
// Draw a billboard texture defined by sourceRec
func DrawBillboardRec(camera Camera, texture Texture2D, sourceRec Rectangle, center Vector3, size float32, tint Color) {
ccamera := camera.cptr()
ctexture := texture.cptr()
csourceRec := sourceRec.cptr()
ccenter := center.cptr()
csize := (C.float)(size)
ctint := tint.cptr()
C.DrawBillboardRec(*ccamera, *ctexture, *csourceRec, *ccenter, csize, *ctint)
}
// Calculate mesh bounding box limits
func CalculateBoundingBox(mesh Mesh) BoundingBox {
cmesh := mesh.cptr()
ret := C.CalculateBoundingBox(*cmesh)
v := NewBoundingBoxFromPointer(unsafe.Pointer(&ret))
return v
}
// Detect collision between two spheres
func CheckCollisionSpheres(centerA Vector3, radiusA float32, centerB Vector3, radiusB float32) bool {
ccenterA := centerA.cptr()
cradiusA := (C.float)(radiusA)
ccenterB := centerB.cptr()
cradiusB := (C.float)(radiusB)
ret := C.CheckCollisionSpheres(*ccenterA, cradiusA, *ccenterB, cradiusB)
v := bool(int(ret) == 1)
return v
}
// Detect collision between two bounding boxes
func CheckCollisionBoxes(box1 BoundingBox, box2 BoundingBox) bool {
cbox1 := box1.cptr()
cbox2 := box2.cptr()
ret := C.CheckCollisionBoxes(*cbox1, *cbox2)
v := bool(int(ret) == 1)
return v
}
// Detect collision between box and sphere
func CheckCollisionBoxSphere(box BoundingBox, centerSphere Vector3, radiusSphere float32) bool {
cbox := box.cptr()
ccenterSphere := centerSphere.cptr()
cradiusSphere := (C.float)(radiusSphere)
ret := C.CheckCollisionBoxSphere(*cbox, *ccenterSphere, cradiusSphere)
v := bool(int(ret) == 1)
return v
}
// Detect collision between ray and sphere
func CheckCollisionRaySphere(ray Ray, spherePosition Vector3, sphereRadius float32) bool {
cray := ray.cptr()
cspherePosition := spherePosition.cptr()
csphereRadius := (C.float)(sphereRadius)
ret := C.CheckCollisionRaySphere(*cray, *cspherePosition, csphereRadius)
v := bool(int(ret) == 1)
return v
}
// Detect collision between ray and sphere with extended parameters and collision point detection
func CheckCollisionRaySphereEx(ray Ray, spherePosition Vector3, sphereRadius float32, collisionPoint Vector3) bool {
cray := ray.cptr()
cspherePosition := spherePosition.cptr()
csphereRadius := (C.float)(sphereRadius)
ccollisionPoint := collisionPoint.cptr()
ret := C.CheckCollisionRaySphereEx(*cray, *cspherePosition, csphereRadius, ccollisionPoint)
v := bool(int(ret) == 1)
return v
}
// Detect collision between ray and box
func CheckCollisionRayBox(ray Ray, box BoundingBox) bool {
cray := ray.cptr()
cbox := box.cptr()
ret := C.CheckCollisionRayBox(*cray, *cbox)
v := bool(int(ret) == 1)
return v
}

View file

@ -0,0 +1,7 @@
// +build android
#include "_cgo_export.h"
void android_main(struct android_app *app) {
androidMain(app);
}

View file

@ -0,0 +1,33 @@
// +build android
package raylib
/*
#include "raylib.h"
#include "android_native_app_glue.h"
extern void android_main(struct android_app *app);
*/
import "C"
import "unsafe"
var callbackHolder func(unsafe.Pointer)
// Initialize Window and OpenGL Graphics
func InitWindow(width int32, height int32, app unsafe.Pointer) {
cwidth := (C.int)(width)
cheight := (C.int)(height)
C.InitWindow(cwidth, cheight, app)
}
// Sets callback function
func SetCallbackFunc(callback func(unsafe.Pointer)) {
callbackHolder = callback
}
//export androidMain
func androidMain(app *C.struct_android_app) {
if callbackHolder != nil {
callbackHolder(unsafe.Pointer(app))
}
}

46
raylib/platform_arm.go Normal file
View file

@ -0,0 +1,46 @@
// +build !android,arm
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// Initialize Window and OpenGL Graphics
func InitWindow(width int32, height int32, title string) {
cwidth := (C.int)(width)
cheight := (C.int)(height)
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.InitWindow(cwidth, cheight, ctitle)
}
// Shows cursor
func ShowCursor() {
C.ShowCursor()
}
// Hides cursor
func HideCursor() {
C.HideCursor()
}
// Returns true if cursor is not visible
func IsCursorHidden() bool {
ret := C.IsCursorHidden()
v := bool(int(ret) == 1)
return v
}
// Enables cursor
func EnableCursor() {
C.EnableCursor()
}
// Disables cursor
func DisableCursor() {
C.DisableCursor()
}

View file

@ -0,0 +1,72 @@
// +build !android,!arm
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// Initialize Window and OpenGL Graphics
func InitWindow(width int32, height int32, title string) {
cwidth := (C.int)(width)
cheight := (C.int)(height)
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.InitWindow(cwidth, cheight, ctitle)
}
// Shows cursor
func ShowCursor() {
C.ShowCursor()
}
// Hides cursor
func HideCursor() {
C.HideCursor()
}
// Returns true if cursor is not visible
func IsCursorHidden() bool {
ret := C.IsCursorHidden()
v := bool(int(ret) == 1)
return v
}
// Enables cursor
func EnableCursor() {
C.EnableCursor()
}
// Disables cursor
func DisableCursor() {
C.DisableCursor()
}
// Check if a file have been dropped into window
func IsFileDropped() bool {
ret := C.IsFileDropped()
v := bool(int(ret) == 1)
return v
}
// Retrieve dropped files into window
func GetDroppedFiles(count *int32) []string {
ccount := (*C.int)(unsafe.Pointer(count))
ret := C.GetDroppedFiles(ccount)
tmpslice := (*[1 << 30]*C.char)(unsafe.Pointer(ret))[:*count:*count]
gostrings := make([]string, *count)
for i, s := range tmpslice {
gostrings[i] = C.GoString(s)
}
return gostrings
}
// Clear dropped files paths buffer
func ClearDroppedFiles() {
C.ClearDroppedFiles()
}

240
raylib/shaders.go Normal file
View file

@ -0,0 +1,240 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "reflect"
type VrDevice int32
// Head Mounted Display devices
const (
HmdDefaultDevice VrDevice = C.HMD_DEFAULT_DEVICE
HmdOculusRiftDk2 VrDevice = C.HMD_OCULUS_RIFT_DK2
HmdOculusRiftCv1 VrDevice = C.HMD_OCULUS_RIFT_CV1
HmdValveHtcVive VrDevice = C.HMD_VALVE_HTC_VIVE
HmdSamsungGearVr VrDevice = C.HMD_SAMSUNG_GEAR_VR
HmdGoogleCardboard VrDevice = C.HMD_GOOGLE_CARDBOARD
HmdSonyPlaystationVr VrDevice = C.HMD_SONY_PLAYSTATION_VR
HmdRazerOsvr VrDevice = C.HMD_RAZER_OSVR
HmdFoveVr VrDevice = C.HMD_FOVE_VR
)
type BlendMode int32
// Color blending modes (pre-defined)
const (
BlendAlpha BlendMode = C.BLEND_ALPHA
BlendAdditive BlendMode = C.BLEND_ADDITIVE
BlendMultiplied BlendMode = C.BLEND_MULTIPLIED
)
// Shader type (generic shader)
type Shader struct {
// Shader program id
Id uint32
// Vertex attribute location point (default-location = 0)
VertexLoc int32
// Texcoord attribute location point (default-location = 1)
TexcoordLoc int32
// Texcoord2 attribute location point (default-location = 5)
Texcoord2Loc int32
// Normal attribute location point (default-location = 2)
NormalLoc int32
// Tangent attribute location point (default-location = 4)
TangentLoc int32
// Color attibute location point (default-location = 3)
ColorLoc int32
// ModelView-Projection matrix uniform location point (vertex shader)
MvpLoc int32
// Diffuse color uniform location point (fragment shader)
ColDiffuseLoc int32
// Ambient color uniform location point (fragment shader)
ColAmbientLoc int32
// Specular color uniform location point (fragment shader)
ColSpecularLoc int32
// Map texture uniform location point (default-texture-unit = 0)
MapTexture0Loc int32
// Map texture uniform location point (default-texture-unit = 1)
MapTexture1Loc int32
// Map texture uniform location point (default-texture-unit = 2)
MapTexture2Loc int32
}
func (s *Shader) cptr() *C.Shader {
return (*C.Shader)(unsafe.Pointer(s))
}
// Returns new Shader
func NewShader(id uint32, vertexLoc, texcoordLoc, texcoord2Loc, normalLoc, tangentLoc, colorLoc, mvpLoc, colDiffuseLoc, colAmbientLoc, colSpecularLoc, mapTexture0Loc, mapTexture1Loc, mapTexture2Loc int32) Shader {
return Shader{id, vertexLoc, texcoordLoc, texcoord2Loc, normalLoc, tangentLoc, colorLoc, mvpLoc, colDiffuseLoc, colAmbientLoc, colSpecularLoc, mapTexture0Loc, mapTexture1Loc, mapTexture2Loc}
}
// Returns new Shader from pointer
func NewShaderFromPointer(ptr unsafe.Pointer) Shader {
return *(*Shader)(ptr)
}
// Load a custom shader and bind default locations
func LoadShader(vsFileName string, fsFileName string) Shader {
cvsFileName := C.CString(vsFileName)
cfsFileName := C.CString(fsFileName)
defer C.free(unsafe.Pointer(cvsFileName))
defer C.free(unsafe.Pointer(cfsFileName))
ret := C.LoadShader(cvsFileName, cfsFileName)
v := NewShaderFromPointer(unsafe.Pointer(&ret))
return v
}
// Unload a custom shader from memory
func UnloadShader(shader Shader) {
cshader := shader.cptr()
C.UnloadShader(*cshader)
}
// Get default shader
func GetDefaultShader() Shader {
ret := C.GetDefaultShader()
v := NewShaderFromPointer(unsafe.Pointer(&ret))
return v
}
// Get standard shader
func GetStandardShader() Shader {
ret := C.GetStandardShader()
v := NewShaderFromPointer(unsafe.Pointer(&ret))
return v
}
// Get default texture
func GetDefaultTexture() *Texture2D {
ret := C.GetDefaultTexture()
v := NewTexture2DFromPointer(unsafe.Pointer(&ret))
return &v
}
// Get shader uniform location
func GetShaderLocation(shader Shader, uniformName string) int32 {
cshader := shader.cptr()
cuniformName := C.CString(uniformName)
defer C.free(unsafe.Pointer(cuniformName))
ret := C.GetShaderLocation(*cshader, cuniformName)
v := (int32)(ret)
return v
}
// Set shader uniform value (float)
func SetShaderValue(shader Shader, uniformLoc int32, value []float32, size int32) {
cshader := shader.cptr()
cuniformLoc := (C.int)(uniformLoc)
cvalue := (*C.float)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&value)).Data))
csize := (C.int)(size)
C.SetShaderValue(*cshader, cuniformLoc, cvalue, csize)
}
// Set shader uniform value (int)
func SetShaderValuei(shader Shader, uniformLoc int32, value []int32, size int32) {
cshader := shader.cptr()
cuniformLoc := (C.int)(uniformLoc)
cvalue := (*C.int)(unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&value)).Data))
csize := (C.int)(size)
C.SetShaderValuei(*cshader, cuniformLoc, cvalue, csize)
}
// Set shader uniform value (matrix 4x4)
func SetShaderValueMatrix(shader Shader, uniformLoc int32, mat Matrix) {
cshader := shader.cptr()
cuniformLoc := (C.int)(uniformLoc)
cmat := mat.cptr()
C.SetShaderValueMatrix(*cshader, cuniformLoc, *cmat)
}
// Set a custom projection matrix (replaces internal projection matrix)
func SetMatrixProjection(proj Matrix) {
cproj := proj.cptr()
C.SetMatrixProjection(*cproj)
}
// Set a custom modelview matrix (replaces internal modelview matrix)
func SetMatrixModelview(view Matrix) {
cview := view.cptr()
C.SetMatrixModelview(*cview)
}
// Begin custom shader drawing
func BeginShaderMode(shader Shader) {
cshader := shader.cptr()
C.BeginShaderMode(*cshader)
}
// End custom shader drawing (use default shader)
func EndShaderMode() {
C.EndShaderMode()
}
// Begin blending mode (alpha, additive, multiplied)
func BeginBlendMode(mode BlendMode) {
cmode := (C.int)(mode)
C.BeginBlendMode(cmode)
}
// End blending mode (reset to default: alpha blending)
func EndBlendMode() {
C.EndBlendMode()
}
// Create a new light, initialize it and add to pool
func CreateLight(_type LightType, position Vector3, diffuse Color) Light {
c_type := (C.int)(_type)
cposition := position.cptr()
cdiffuse := diffuse.cptr()
ret := C.CreateLight(c_type, *cposition, *cdiffuse)
v := NewLightFromPointer(unsafe.Pointer(ret))
return v
}
// Destroy a light and take it out of the list
func DestroyLight(light Light) {
clightdata := NewLightData(light)
C.DestroyLight(clightdata.cptr())
}
// Init VR device
func InitVrDevice(vdDevice VrDevice) {
cvdDevice := (C.int)(vdDevice)
C.InitVrDevice(cvdDevice)
}
// Close VR device
func CloseVrDevice() {
C.CloseVrDevice()
}
// Detect if VR device is ready
func IsVrDeviceReady() bool {
ret := C.IsVrDeviceReady()
v := bool(int(ret) == 1)
return v
}
// Detect if VR simulator is running
func IsVrSimulator() bool {
ret := C.IsVrSimulator()
v := bool(int(ret) == 1)
return v
}
// Update VR tracking (position and orientation) and camera
func UpdateVrTracking(camera *Camera) {
ccamera := camera.cptr()
C.UpdateVrTracking(ccamera)
}
// Enable/Disable VR experience (device or simulator)
func ToggleVrMode() {
C.ToggleVrMode()
}

236
raylib/shapes.go Normal file
View file

@ -0,0 +1,236 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// Draw a pixel
func DrawPixel(posX int32, posY int32, color Color) {
cposX := (C.int)(posX)
cposY := (C.int)(posY)
ccolor := color.cptr()
C.DrawPixel(cposX, cposY, *ccolor)
}
// Draw a pixel (Vector version)
func DrawPixelV(position Vector2, color Color) {
cposition := position.cptr()
ccolor := color.cptr()
C.DrawPixelV(*cposition, *ccolor)
}
// Draw a line
func DrawLine(startPosX int32, startPosY int32, endPosX int32, endPosY int32, color Color) {
cstartPosX := (C.int)(startPosX)
cstartPosY := (C.int)(startPosY)
cendPosX := (C.int)(endPosX)
cendPosY := (C.int)(endPosY)
ccolor := color.cptr()
C.DrawLine(cstartPosX, cstartPosY, cendPosX, cendPosY, *ccolor)
}
// Draw a line (Vector version)
func DrawLineV(startPos Vector2, endPos Vector2, color Color) {
cstartPos := startPos.cptr()
cendPos := endPos.cptr()
ccolor := color.cptr()
C.DrawLineV(*cstartPos, *cendPos, *ccolor)
}
// Draw a color-filled circle
func DrawCircle(centerX int32, centerY int32, radius float32, color Color) {
ccenterX := (C.int)(centerX)
ccenterY := (C.int)(centerY)
cradius := (C.float)(radius)
ccolor := color.cptr()
C.DrawCircle(ccenterX, ccenterY, cradius, *ccolor)
}
// Draw a gradient-filled circle
func DrawCircleGradient(centerX int32, centerY int32, radius float32, color1 Color, color2 Color) {
ccenterX := (C.int)(centerX)
ccenterY := (C.int)(centerY)
cradius := (C.float)(radius)
ccolor1 := color1.cptr()
ccolor2 := color2.cptr()
C.DrawCircleGradient(ccenterX, ccenterY, cradius, *ccolor1, *ccolor2)
}
// Draw a color-filled circle (Vector version)
func DrawCircleV(center Vector2, radius float32, color Color) {
ccenter := center.cptr()
cradius := (C.float)(radius)
ccolor := color.cptr()
C.DrawCircleV(*ccenter, cradius, *ccolor)
}
// Draw circle outline
func DrawCircleLines(centerX int32, centerY int32, radius float32, color Color) {
ccenterX := (C.int)(centerX)
ccenterY := (C.int)(centerY)
cradius := (C.float)(radius)
ccolor := color.cptr()
C.DrawCircleLines(ccenterX, ccenterY, cradius, *ccolor)
}
// Draw a color-filled rectangle
func DrawRectangle(posX int32, posY int32, width int32, height int32, color Color) {
cposX := (C.int)(posX)
cposY := (C.int)(posY)
cwidth := (C.int)(width)
cheight := (C.int)(height)
ccolor := color.cptr()
C.DrawRectangle(cposX, cposY, cwidth, cheight, *ccolor)
}
// Draw a color-filled rectangle
func DrawRectangleRec(rec Rectangle, color Color) {
crec := rec.cptr()
ccolor := color.cptr()
C.DrawRectangleRec(*crec, *ccolor)
}
// Draw a gradient-filled rectangle
func DrawRectangleGradient(posX int32, posY int32, width int32, height int32, color1 Color, color2 Color) {
cposX := (C.int)(posX)
cposY := (C.int)(posY)
cwidth := (C.int)(width)
cheight := (C.int)(height)
ccolor1 := color1.cptr()
ccolor2 := color2.cptr()
C.DrawRectangleGradient(cposX, cposY, cwidth, cheight, *ccolor1, *ccolor2)
}
// Draw a color-filled rectangle (Vector version)
func DrawRectangleV(position Vector2, size Vector2, color Color) {
cposition := position.cptr()
csize := size.cptr()
ccolor := color.cptr()
C.DrawRectangleV(*cposition, *csize, *ccolor)
}
// Draw rectangle outline
func DrawRectangleLines(posX int32, posY int32, width int32, height int32, color Color) {
cposX := (C.int)(posX)
cposY := (C.int)(posY)
cwidth := (C.int)(width)
cheight := (C.int)(height)
ccolor := color.cptr()
C.DrawRectangleLines(cposX, cposY, cwidth, cheight, *ccolor)
}
// Draw a color-filled triangle
func DrawTriangle(v1 Vector2, v2 Vector2, v3 Vector2, color Color) {
cv1 := v1.cptr()
cv2 := v2.cptr()
cv3 := v3.cptr()
ccolor := color.cptr()
C.DrawTriangle(*cv1, *cv2, *cv3, *ccolor)
}
// Draw triangle outline
func DrawTriangleLines(v1 Vector2, v2 Vector2, v3 Vector2, color Color) {
cv1 := v1.cptr()
cv2 := v2.cptr()
cv3 := v3.cptr()
ccolor := color.cptr()
C.DrawTriangleLines(*cv1, *cv2, *cv3, *ccolor)
}
// Draw a regular polygon (Vector version)
func DrawPoly(center Vector2, sides int32, radius float32, rotation float32, color Color) {
ccenter := center.cptr()
csides := (C.int)(sides)
cradius := (C.float)(radius)
crotation := (C.float)(rotation)
ccolor := color.cptr()
C.DrawPoly(*ccenter, csides, cradius, crotation, *ccolor)
}
// Draw a closed polygon defined by points
func DrawPolyEx(points []Vector2, numPoints int32, color Color) {
cpoints := points[0].cptr()
cnumPoints := (C.int)(numPoints)
ccolor := color.cptr()
C.DrawPolyEx(cpoints, cnumPoints, *ccolor)
}
// Draw polygon lines
func DrawPolyExLines(points []Vector2, numPoints int32, color Color) {
cpoints := points[0].cptr()
cnumPoints := (C.int)(numPoints)
ccolor := color.cptr()
C.DrawPolyExLines(cpoints, cnumPoints, *ccolor)
}
// Check collision between two rectangles
func CheckCollisionRecs(rec1 Rectangle, rec2 Rectangle) bool {
crec1 := rec1.cptr()
crec2 := rec2.cptr()
ret := C.CheckCollisionRecs(*crec1, *crec2)
v := bool(int(ret) == 1)
return v
}
// Check collision between two circles
func CheckCollisionCircles(center1 Vector2, radius1 float32, center2 Vector2, radius2 float32) bool {
ccenter1 := center1.cptr()
cradius1 := (C.float)(radius1)
ccenter2 := center2.cptr()
cradius2 := (C.float)(radius2)
ret := C.CheckCollisionCircles(*ccenter1, cradius1, *ccenter2, cradius2)
v := bool(int(ret) == 1)
return v
}
// Check collision between circle and rectangle
func CheckCollisionCircleRec(center Vector2, radius float32, rec Rectangle) bool {
ccenter := center.cptr()
cradius := (C.float)(radius)
crec := rec.cptr()
ret := C.CheckCollisionCircleRec(*ccenter, cradius, *crec)
v := bool(int(ret) == 1)
return v
}
// Get collision rectangle for two rectangles collision
func GetCollisionRec(rec1 Rectangle, rec2 Rectangle) Rectangle {
crec1 := rec1.cptr()
crec2 := rec2.cptr()
ret := C.GetCollisionRec(*crec1, *crec2)
v := NewRectangleFromPointer(unsafe.Pointer(&ret))
return v
}
// Check if point is inside rectangle
func CheckCollisionPointRec(point Vector2, rec Rectangle) bool {
cpoint := point.cptr()
crec := rec.cptr()
ret := C.CheckCollisionPointRec(*cpoint, *crec)
v := bool(int(ret) == 1)
return v
}
// Check if point is inside circle
func CheckCollisionPointCircle(point Vector2, center Vector2, radius float32) bool {
cpoint := point.cptr()
ccenter := center.cptr()
cradius := (C.float)(radius)
ret := C.CheckCollisionPointCircle(*cpoint, *ccenter, cradius)
v := bool(int(ret) == 1)
return v
}
// Check if point is inside a triangle
func CheckCollisionPointTriangle(point Vector2, p1 Vector2, p2 Vector2, p3 Vector2) bool {
cpoint := point.cptr()
cp1 := p1.cptr()
cp2 := p2.cptr()
cp3 := p3.cptr()
ret := C.CheckCollisionPointTriangle(*cpoint, *cp1, *cp2, *cp3)
v := bool(int(ret) == 1)
return v
}

119
raylib/text.go Normal file
View file

@ -0,0 +1,119 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
// SpriteFont type, includes texture and charSet array data
type SpriteFont struct {
// Font texture
Texture Texture2D
// Base size (default chars height)
Size int32
// Number of characters
NumChars int32
// Characters values array
CharValues []int32
// Characters rectangles within the texture
CharRecs []Rectangle
// Characters offsets (on drawing)
CharOffsets []Vector2
// Characters x advance (on drawing)
CharAdvanceX []int32
}
func (s *SpriteFont) cptr() *C.SpriteFont {
return (*C.SpriteFont)(unsafe.Pointer(s))
}
// Returns new SpriteFont
func NewSpriteFont(texture Texture2D, size, numChars int32, charValues []int32, charRecs []Rectangle, charOffsets []Vector2, charAdvanceX []int32) SpriteFont {
return SpriteFont{texture, size, numChars, charValues, charRecs, charOffsets, charAdvanceX}
}
// Returns new SpriteFont from pointer
func NewSpriteFontFromPointer(ptr unsafe.Pointer) SpriteFont {
return *(*SpriteFont)(ptr)
}
// Get the default SpriteFont
func GetDefaultFont() SpriteFont {
ret := C.GetDefaultFont()
v := NewSpriteFontFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a SpriteFont image into GPU memory
func LoadSpriteFont(fileName string) SpriteFont {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadSpriteFont(cfileName)
v := NewSpriteFontFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a SpriteFont from TTF font with parameters
func LoadSpriteFontTTF(fileName string, fontSize int32, numChars int32, fontChars *int32) SpriteFont {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
cfontSize := (C.int)(fontSize)
cnumChars := (C.int)(numChars)
cfontChars := (*C.int)(unsafe.Pointer(fontChars))
ret := C.LoadSpriteFontTTF(cfileName, cfontSize, cnumChars, cfontChars)
v := NewSpriteFontFromPointer(unsafe.Pointer(&ret))
return v
}
// Unload SpriteFont from GPU memory
func UnloadSpriteFont(spriteFont SpriteFont) {
cspriteFont := spriteFont.cptr()
C.UnloadSpriteFont(*cspriteFont)
}
// Draw text (using default font)
func DrawText(text string, posX int32, posY int32, fontSize int32, color Color) {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cposX := (C.int)(posX)
cposY := (C.int)(posY)
cfontSize := (C.int)(fontSize)
ccolor := color.cptr()
C.DrawText(ctext, cposX, cposY, cfontSize, *ccolor)
}
// Draw text using SpriteFont and additional parameters
func DrawTextEx(spriteFont SpriteFont, text string, position Vector2, fontSize float32, spacing int32, tint Color) {
cspriteFont := spriteFont.cptr()
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cposition := position.cptr()
cfontSize := (C.float)(fontSize)
cspacing := (C.int)(spacing)
ctint := tint.cptr()
C.DrawTextEx(*cspriteFont, ctext, *cposition, cfontSize, cspacing, *ctint)
}
// Measure string width for default font
func MeasureText(text string, fontSize int32) int32 {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.int)(fontSize)
ret := C.MeasureText(ctext, cfontSize)
v := (int32)(ret)
return v
}
// Measure string size for SpriteFont
func MeasureTextEx(spriteFont SpriteFont, text string, fontSize float32, spacing int32) Vector2 {
cspriteFont := spriteFont.cptr()
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.float)(fontSize)
cspacing := (C.int)(spacing)
ret := C.MeasureTextEx(*cspriteFont, ctext, cfontSize, cspacing)
v := NewVector2FromPointer(unsafe.Pointer(&ret))
return v
}

522
raylib/textures.go Normal file
View file

@ -0,0 +1,522 @@
package raylib
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
type TextureFormat int32
// Texture formats
// NOTE: Support depends on OpenGL version and platform
const (
// 8 bit per pixel (no alpha)
UncompressedGrayscale TextureFormat = C.UNCOMPRESSED_GRAYSCALE
// 16 bpp (2 channels)
UncompressedGrayAlpha TextureFormat = C.UNCOMPRESSED_GRAY_ALPHA
// 16 bpp
UncompressedR5g6b5 TextureFormat = C.UNCOMPRESSED_R5G6B5
// 24 bpp
UncompressedR8g8b8 TextureFormat = C.UNCOMPRESSED_R8G8B8
// 16 bpp (1 bit alpha)
UncompressedR5g5b5a1 TextureFormat = C.UNCOMPRESSED_R5G5B5A1
// 16 bpp (4 bit alpha)
UncompressedR4g4b4a4 TextureFormat = C.UNCOMPRESSED_R4G4B4A4
// 32 bpp
UncompressedR8g8b8a8 TextureFormat = C.UNCOMPRESSED_R8G8B8A8
// 4 bpp (no alpha)
CompressedDxt1Rgb TextureFormat = C.COMPRESSED_DXT1_RGB
// 4 bpp (1 bit alpha)
CompressedDxt1Rgba TextureFormat = C.COMPRESSED_DXT1_RGBA
// 8 bpp
CompressedDxt3Rgba TextureFormat = C.COMPRESSED_DXT3_RGBA
// 8 bpp
CompressedDxt5Rgba TextureFormat = C.COMPRESSED_DXT5_RGBA
// 4 bpp
CompressedEtc1Rgb TextureFormat = C.COMPRESSED_ETC1_RGB
// 4 bpp
CompressedEtc2Rgb TextureFormat = C.COMPRESSED_ETC2_RGB
// 8 bpp
CompressedEtc2EacRgba TextureFormat = C.COMPRESSED_ETC2_EAC_RGBA
// 4 bpp
CompressedPvrtRgb TextureFormat = C.COMPRESSED_PVRT_RGB
// 4 bpp
CompressedPvrtRgba TextureFormat = C.COMPRESSED_PVRT_RGBA
// 8 bpp
CompressedAstc4x4Rgba TextureFormat = C.COMPRESSED_ASTC_4x4_RGBA
// 2 bpp
CompressedAstc8x8Rgba TextureFormat = C.COMPRESSED_ASTC_8x8_RGBA
)
type TextureFilterMode int32
// Texture parameters: filter mode
// NOTE 1: Filtering considers mipmaps if available in the texture
// NOTE 2: Filter is accordingly set for minification and magnification
const (
// No filter, just pixel aproximation
FilterPoint TextureFilterMode = C.FILTER_POINT
// Linear filtering
FilterBilinear TextureFilterMode = C.FILTER_BILINEAR
// Trilinear filtering (linear with mipmaps)
FilterTrilinear TextureFilterMode = C.FILTER_TRILINEAR
// Anisotropic filtering 4x
FilterAnisotropic4x TextureFilterMode = C.FILTER_ANISOTROPIC_4X
// Anisotropic filtering 8x
FilterAnisotropic8x TextureFilterMode = C.FILTER_ANISOTROPIC_8X
// Anisotropic filtering 16x
FilterAnisotropic16x TextureFilterMode = C.FILTER_ANISOTROPIC_16X
)
type TextureWrapMode int32
// Texture parameters: wrap mode
const (
WrapRepeat TextureWrapMode = C.WRAP_REPEAT
WrapClamp TextureWrapMode = C.WRAP_CLAMP
WrapMirror TextureWrapMode = C.WRAP_MIRROR
)
// Image type, bpp always RGBA (32bit)
// NOTE: Data stored in CPU memory (RAM)
type Image struct {
// Image raw data
Data unsafe.Pointer
// Image base width
Width int32
// Image base height
Height int32
// Mipmap levels, 1 by default
Mipmaps int32
// Data format (TextureFormat)
Format TextureFormat
}
func (i *Image) cptr() *C.Image {
return (*C.Image)(unsafe.Pointer(i))
}
// Returns new Image
func NewImage(data unsafe.Pointer, width, height, mipmaps int32, format TextureFormat) *Image {
return &Image{data, width, height, mipmaps, format}
}
// Returns new Image from pointer
func NewImageFromPointer(ptr unsafe.Pointer) *Image {
return (*Image)(ptr)
}
// Texture2D type, bpp always RGBA (32bit)
// NOTE: Data stored in GPU memory
type Texture2D struct {
// OpenGL texture id
Id uint32
// Texture base width
Width int32
// Texture base height
Height int32
// Mipmap levels, 1 by default
Mipmaps int32
// Data format (TextureFormat)
Format TextureFormat
}
func (t *Texture2D) cptr() *C.Texture2D {
return (*C.Texture2D)(unsafe.Pointer(t))
}
// Returns new Texture2D
func NewTexture2D(id uint32, width, height, mipmaps int32, format TextureFormat) Texture2D {
return Texture2D{id, width, height, mipmaps, format}
}
// Returns new Texture2D from pointer
func NewTexture2DFromPointer(ptr unsafe.Pointer) Texture2D {
return *(*Texture2D)(ptr)
}
// RenderTexture2D type, for texture rendering
type RenderTexture2D struct {
// Render texture (fbo) id
Id uint32
// Color buffer attachment texture
Texture Texture2D
// Depth buffer attachment texture
Depth Texture2D
}
func (r *RenderTexture2D) cptr() *C.RenderTexture2D {
return (*C.RenderTexture2D)(unsafe.Pointer(r))
}
// Returns new RenderTexture2D
func NewRenderTexture2D(id uint32, texture, depth Texture2D) RenderTexture2D {
return RenderTexture2D{id, texture, depth}
}
// Returns new RenderTexture2D from pointer
func NewRenderTexture2DFromPointer(ptr unsafe.Pointer) RenderTexture2D {
return *(*RenderTexture2D)(ptr)
}
// Load an image into CPU memory (RAM)
func LoadImage(fileName string) *Image {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadImage(cfileName)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Load image data from Color array data (RGBA - 32bit)
func LoadImageEx(pixels []Color, width int32, height int32) *Image {
cpixels := pixels[0].cptr()
cwidth := (C.int)(width)
cheight := (C.int)(height)
ret := C.LoadImageEx(cpixels, cwidth, cheight)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Load image data from RAW file
func LoadImageRaw(fileName string, width int32, height int32, format TextureFormat, headerSize int32) *Image {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
cwidth := (C.int)(width)
cheight := (C.int)(height)
cformat := (C.int)(format)
cheaderSize := (C.int)(headerSize)
ret := C.LoadImageRaw(cfileName, cwidth, cheight, cformat, cheaderSize)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Load an image from rRES file (raylib Resource)
func LoadImageFromRES(rresName string, resId int32) *Image {
crresName := C.CString(rresName)
defer C.free(unsafe.Pointer(crresName))
cresId := (C.int)(resId)
ret := C.LoadImageFromRES(crresName, cresId)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Load an image as texture into GPU memory
func LoadTexture(fileName string) Texture2D {
cfileName := C.CString(fileName)
defer C.free(unsafe.Pointer(cfileName))
ret := C.LoadTexture(cfileName)
v := NewTexture2DFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a texture from raw data into GPU memory
func LoadTextureEx(data unsafe.Pointer, width int32, height int32, textureFormat TextureFormat) Texture2D {
cdata := (unsafe.Pointer)(unsafe.Pointer(data))
cwidth := (C.int)(width)
cheight := (C.int)(height)
ctextureFormat := (C.int)(textureFormat)
ret := C.LoadTextureEx(cdata, cwidth, cheight, ctextureFormat)
v := NewTexture2DFromPointer(unsafe.Pointer(&ret))
return v
}
// Load an image as texture from rRES file (raylib Resource)
func LoadTextureFromRES(rresName string, resId int32) Texture2D {
crresName := C.CString(rresName)
defer C.free(unsafe.Pointer(crresName))
cresId := (C.int)(resId)
ret := C.LoadTextureFromRES(crresName, cresId)
v := NewTexture2DFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a texture from image data
func LoadTextureFromImage(image *Image) Texture2D {
cimage := image.cptr()
ret := C.LoadTextureFromImage(*cimage)
v := NewTexture2DFromPointer(unsafe.Pointer(&ret))
return v
}
// Load a texture to be used for rendering
func LoadRenderTexture(width int32, height int32) RenderTexture2D {
cwidth := (C.int)(width)
cheight := (C.int)(height)
ret := C.LoadRenderTexture(cwidth, cheight)
v := NewRenderTexture2DFromPointer(unsafe.Pointer(&ret))
return v
}
// Unload image from CPU memory (RAM)
func UnloadImage(image *Image) {
cimage := image.cptr()
C.UnloadImage(*cimage)
}
// Unload texture from GPU memory
func UnloadTexture(texture Texture2D) {
ctexture := texture.cptr()
C.UnloadTexture(*ctexture)
}
// Unload render texture from GPU memory
func UnloadRenderTexture(target RenderTexture2D) {
ctarget := target.cptr()
C.UnloadRenderTexture(*ctarget)
}
// Get pixel data from image
func GetImageData(image *Image) unsafe.Pointer {
cimage := image.cptr()
ret := C.GetImageData(*cimage)
return unsafe.Pointer(ret)
}
// Get pixel data from GPU texture and return an Image
func GetTextureData(texture Texture2D) *Image {
ctexture := texture.cptr()
ret := C.GetTextureData(*ctexture)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Update GPU texture with new data
func UpdateTexture(texture Texture2D, pixels unsafe.Pointer) {
ctexture := texture.cptr()
cpixels := (unsafe.Pointer)(unsafe.Pointer(pixels))
C.UpdateTexture(*ctexture, cpixels)
}
// Convert image to POT (power-of-two)
func ImageToPOT(image *Image, fillColor Color) {
cimage := image.cptr()
cfillColor := fillColor.cptr()
C.ImageToPOT(cimage, *cfillColor)
}
// Convert image data to desired format
func ImageFormat(image *Image, newFormat int32) {
cimage := image.cptr()
cnewFormat := (C.int)(newFormat)
C.ImageFormat(cimage, cnewFormat)
}
// Apply alpha mask to image
func ImageAlphaMask(image *Image, alphaMask *Image) {
cimage := image.cptr()
calphaMask := alphaMask.cptr()
C.ImageAlphaMask(cimage, *calphaMask)
}
// Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
func ImageDither(image *Image, rBpp int32, gBpp int32, bBpp int32, aBpp int32) {
cimage := image.cptr()
crBpp := (C.int)(rBpp)
cgBpp := (C.int)(gBpp)
cbBpp := (C.int)(bBpp)
caBpp := (C.int)(aBpp)
C.ImageDither(cimage, crBpp, cgBpp, cbBpp, caBpp)
}
// Create an image duplicate (useful for transformations)
func ImageCopy(image *Image) *Image {
cimage := image.cptr()
ret := C.ImageCopy(*cimage)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Crop an image to a defined rectangle
func ImageCrop(image *Image, crop Rectangle) {
cimage := image.cptr()
ccrop := crop.cptr()
C.ImageCrop(cimage, *ccrop)
}
// Resize an image (bilinear filtering)
func ImageResize(image *Image, newWidth int32, newHeight int32) {
cimage := image.cptr()
cnewWidth := (C.int)(newWidth)
cnewHeight := (C.int)(newHeight)
C.ImageResize(cimage, cnewWidth, cnewHeight)
}
// Resize an image (Nearest-Neighbor scaling algorithm)
func ImageResizeNN(image *Image, newWidth int32, newHeight int32) {
cimage := image.cptr()
cnewWidth := (C.int)(newWidth)
cnewHeight := (C.int)(newHeight)
C.ImageResizeNN(cimage, cnewWidth, cnewHeight)
}
// Create an image from text (default font)
func ImageText(text string, fontSize int32, color Color) *Image {
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.int)(fontSize)
ccolor := color.cptr()
ret := C.ImageText(ctext, cfontSize, *ccolor)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Create an image from text (custom sprite font)
func ImageTextEx(font SpriteFont, text string, fontSize float32, spacing int32, tint Color) *Image {
cfont := font.cptr()
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.float)(fontSize)
cspacing := (C.int)(spacing)
ctint := tint.cptr()
ret := C.ImageTextEx(*cfont, ctext, cfontSize, cspacing, *ctint)
v := NewImageFromPointer(unsafe.Pointer(&ret))
return v
}
// Draw a source image within a destination image
func ImageDraw(dst *Image, src *Image, srcRec Rectangle, dstRec Rectangle) {
cdst := dst.cptr()
csrc := src.cptr()
csrcRec := srcRec.cptr()
cdstRec := dstRec.cptr()
C.ImageDraw(cdst, *csrc, *csrcRec, *cdstRec)
}
// Draw text (default font) within an image (destination)
func ImageDrawText(dst *Image, position Vector2, text string, fontSize int32, color Color) {
cdst := dst.cptr()
cposition := position.cptr()
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.int)(fontSize)
ccolor := color.cptr()
C.ImageDrawText(cdst, *cposition, ctext, cfontSize, *ccolor)
}
// Draw text (custom sprite font) within an image (destination)
func ImageDrawTextEx(dst *Image, position Vector2, font SpriteFont, text string, fontSize float32, spacing int32, color Color) {
cdst := dst.cptr()
cposition := position.cptr()
cfont := font.cptr()
ctext := C.CString(text)
defer C.free(unsafe.Pointer(ctext))
cfontSize := (C.float)(fontSize)
cspacing := (C.int)(spacing)
ccolor := color.cptr()
C.ImageDrawTextEx(cdst, *cposition, *cfont, ctext, cfontSize, cspacing, *ccolor)
}
// Flip image vertically
func ImageFlipVertical(image *Image) {
cimage := image.cptr()
C.ImageFlipVertical(cimage)
}
// Flip image horizontally
func ImageFlipHorizontal(image *Image) {
cimage := image.cptr()
C.ImageFlipHorizontal(cimage)
}
// Modify image color: tint
func ImageColorTint(image *Image, color Color) {
cimage := image.cptr()
ccolor := color.cptr()
C.ImageColorTint(cimage, *ccolor)
}
// Modify image color: invert
func ImageColorInvert(image *Image) {
cimage := image.cptr()
C.ImageColorInvert(cimage)
}
// Modify image color: grayscale
func ImageColorGrayscale(image *Image) {
cimage := image.cptr()
C.ImageColorGrayscale(cimage)
}
// Modify image color: contrast (-100 to 100)
func ImageColorContrast(image *Image, contrast float32) {
cimage := image.cptr()
ccontrast := (C.float)(contrast)
C.ImageColorContrast(cimage, ccontrast)
}
// Modify image color: brightness (-255 to 255)
func ImageColorBrightness(image *Image, brightness int32) {
cimage := image.cptr()
cbrightness := (C.int)(brightness)
C.ImageColorBrightness(cimage, cbrightness)
}
// Generate GPU mipmaps for a texture
func GenTextureMipmaps(texture *Texture2D) {
ctexture := texture.cptr()
C.GenTextureMipmaps(ctexture)
}
// Set texture scaling filter mode
func SetTextureFilter(texture Texture2D, filterMode TextureFilterMode) {
ctexture := texture.cptr()
cfilterMode := (C.int)(filterMode)
C.SetTextureFilter(*ctexture, cfilterMode)
}
// Set texture wrapping mode
func SetTextureWrap(texture Texture2D, wrapMode TextureWrapMode) {
ctexture := texture.cptr()
cwrapMode := (C.int)(wrapMode)
C.SetTextureWrap(*ctexture, cwrapMode)
}
// Draw a Texture2D
func DrawTexture(texture Texture2D, posX int32, posY int32, tint Color) {
ctexture := texture.cptr()
cposX := (C.int)(posX)
cposY := (C.int)(posY)
ctint := tint.cptr()
C.DrawTexture(*ctexture, cposX, cposY, *ctint)
}
// Draw a Texture2D with position defined as Vector2
func DrawTextureV(texture Texture2D, position Vector2, tint Color) {
ctexture := texture.cptr()
cposition := position.cptr()
ctint := tint.cptr()
C.DrawTextureV(*ctexture, *cposition, *ctint)
}
// Draw a Texture2D with extended parameters
func DrawTextureEx(texture Texture2D, position Vector2, rotation float32, scale float32, tint Color) {
ctexture := texture.cptr()
cposition := position.cptr()
crotation := (C.float)(rotation)
cscale := (C.float)(scale)
ctint := tint.cptr()
C.DrawTextureEx(*ctexture, *cposition, crotation, cscale, *ctint)
}
// Draw a part of a texture defined by a rectangle
func DrawTextureRec(texture Texture2D, sourceRec Rectangle, position Vector2, tint Color) {
ctexture := texture.cptr()
csourceRec := sourceRec.cptr()
cposition := position.cptr()
ctint := tint.cptr()
C.DrawTextureRec(*ctexture, *csourceRec, *cposition, *ctint)
}
// Draw a part of a texture defined by a rectangle with 'pro' parameters
func DrawTexturePro(texture Texture2D, sourceRec Rectangle, destRec Rectangle, origin Vector2, rotation float32, tint Color) {
ctexture := texture.cptr()
csourceRec := sourceRec.cptr()
cdestRec := destRec.cptr()
corigin := origin.cptr()
crotation := (C.float)(rotation)
ctint := tint.cptr()
C.DrawTexturePro(*ctexture, *csourceRec, *cdestRec, *corigin, crotation, *ctint)
}