Move all constants and types to raylib.go
This commit is contained in:
parent
f71025719c
commit
135a4637a6
12 changed files with 916 additions and 910 deletions
|
@ -12,100 +12,30 @@ import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
|
||||||
// Wave type, defines audio wave data
|
// cptr returns C pointer
|
||||||
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 {
|
func (w *Wave) cptr() *C.Wave {
|
||||||
return (*C.Wave)(unsafe.Pointer(w))
|
return (*C.Wave)(unsafe.Pointer(w))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWave - Returns new Wave
|
|
||||||
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave {
|
|
||||||
d := unsafe.Pointer(&data[0])
|
|
||||||
return Wave{sampleCount, sampleRate, sampleSize, channels, d}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newWaveFromPointer - Returns new Wave from pointer
|
// newWaveFromPointer - Returns new Wave from pointer
|
||||||
func newWaveFromPointer(ptr unsafe.Pointer) Wave {
|
func newWaveFromPointer(ptr unsafe.Pointer) Wave {
|
||||||
return *(*Wave)(ptr)
|
return *(*Wave)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sound source type
|
|
||||||
type Sound struct {
|
|
||||||
// Audio source id
|
|
||||||
Source uint32
|
|
||||||
// Audio buffer id
|
|
||||||
Buffer uint32
|
|
||||||
// Audio format specifier
|
|
||||||
Format int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sound) cptr() *C.Sound {
|
func (s *Sound) cptr() *C.Sound {
|
||||||
return (*C.Sound)(unsafe.Pointer(s))
|
return (*C.Sound)(unsafe.Pointer(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSound - Returns new Sound
|
|
||||||
func NewSound(source, buffer uint32, format int32) Sound {
|
|
||||||
return Sound{source, buffer, format}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newSoundFromPointer - Returns new Sound from pointer
|
// newSoundFromPointer - Returns new Sound from pointer
|
||||||
func newSoundFromPointer(ptr unsafe.Pointer) Sound {
|
func newSoundFromPointer(ptr unsafe.Pointer) Sound {
|
||||||
return *(*Sound)(ptr)
|
return *(*Sound)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Music type (file streaming from memory)
|
// cptr returns C pointer
|
||||||
// NOTE: Anything longer than ~10 seconds should be streamed
|
|
||||||
type Music struct {
|
|
||||||
CtxType uint32
|
|
||||||
_ [4]byte
|
|
||||||
ctxOgg unsafe.Pointer
|
|
||||||
ctxFlac unsafe.Pointer
|
|
||||||
ctxXm unsafe.Pointer
|
|
||||||
ctxMod unsafe.Pointer
|
|
||||||
Stream AudioStream
|
|
||||||
LoopCount int32
|
|
||||||
TotalSamples uint32
|
|
||||||
SamplesLeft uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// AudioStream 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
|
|
||||||
// Audio format specifier
|
|
||||||
Format int32
|
|
||||||
// Audio source id
|
|
||||||
Source uint32
|
|
||||||
// Audio buffers (double buffering)
|
|
||||||
Buffers [2]uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AudioStream) cptr() *C.AudioStream {
|
func (a *AudioStream) cptr() *C.AudioStream {
|
||||||
return (*C.AudioStream)(unsafe.Pointer(a))
|
return (*C.AudioStream)(unsafe.Pointer(a))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAudioStream - 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}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newAudioStreamFromPointer - Returns new AudioStream from pointer
|
// newAudioStreamFromPointer - Returns new AudioStream from pointer
|
||||||
func newAudioStreamFromPointer(ptr unsafe.Pointer) AudioStream {
|
func newAudioStreamFromPointer(ptr unsafe.Pointer) AudioStream {
|
||||||
return *(*AudioStream)(ptr)
|
return *(*AudioStream)(ptr)
|
||||||
|
|
|
@ -7,18 +7,6 @@ package raylib
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// CameraMode type
|
|
||||||
type CameraMode int32
|
|
||||||
|
|
||||||
// Camera system modes
|
|
||||||
const (
|
|
||||||
CameraCustom CameraMode = iota
|
|
||||||
CameraFree
|
|
||||||
CameraOrbital
|
|
||||||
CameraFirstPerson
|
|
||||||
CameraThirdPerson
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetCameraMode - Set camera mode (multiple camera modes available)
|
// SetCameraMode - Set camera mode (multiple camera modes available)
|
||||||
func SetCameraMode(camera Camera, mode CameraMode) {
|
func SetCameraMode(camera Camera, mode CameraMode) {
|
||||||
ccamera := camera.cptr()
|
ccamera := camera.cptr()
|
||||||
|
|
375
raylib/core.go
375
raylib/core.go
|
@ -7,448 +7,89 @@ package raylib
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Some basic Defines
|
// cptr returns C pointer
|
||||||
const (
|
|
||||||
Pi = 3.1415927
|
|
||||||
Deg2rad = 0.017453292
|
|
||||||
Rad2deg = 57.295776
|
|
||||||
|
|
||||||
// Raylib Config Flags
|
|
||||||
|
|
||||||
// Set to show raylib logo at startup
|
|
||||||
FlagShowLogo = 1
|
|
||||||
// Set to run program in fullscreen
|
|
||||||
FlagFullscreenMode = 2
|
|
||||||
// Set to allow resizable window
|
|
||||||
FlagWindowResizable = 4
|
|
||||||
// Set to show window decoration (frame and buttons)
|
|
||||||
FlagWindowDecorated = 8
|
|
||||||
// Set to allow transparent window
|
|
||||||
FlagWindowTransparent = 16
|
|
||||||
// Set to try enabling MSAA 4X
|
|
||||||
FlagMsaa4xHint = 32
|
|
||||||
// Set to try enabling V-Sync on GPU
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
// Some Basic Colors
|
|
||||||
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
|
||||||
var (
|
|
||||||
// Light Gray
|
|
||||||
LightGray = NewColor(200, 200, 200, 255)
|
|
||||||
// Gray
|
|
||||||
Gray = NewColor(130, 130, 130, 255)
|
|
||||||
// Dark Gray
|
|
||||||
DarkGray = NewColor(80, 80, 80, 255)
|
|
||||||
// Yellow
|
|
||||||
Yellow = NewColor(253, 249, 0, 255)
|
|
||||||
// Gold
|
|
||||||
Gold = NewColor(255, 203, 0, 255)
|
|
||||||
// Orange
|
|
||||||
Orange = NewColor(255, 161, 0, 255)
|
|
||||||
// Pink
|
|
||||||
Pink = NewColor(255, 109, 194, 255)
|
|
||||||
// Red
|
|
||||||
Red = NewColor(230, 41, 55, 255)
|
|
||||||
// Maroon
|
|
||||||
Maroon = NewColor(190, 33, 55, 255)
|
|
||||||
// Green
|
|
||||||
Green = NewColor(0, 228, 48, 255)
|
|
||||||
// Lime
|
|
||||||
Lime = NewColor(0, 158, 47, 255)
|
|
||||||
// Dark Green
|
|
||||||
DarkGreen = NewColor(0, 117, 44, 255)
|
|
||||||
// Sky Blue
|
|
||||||
SkyBlue = NewColor(102, 191, 255, 255)
|
|
||||||
// Blue
|
|
||||||
Blue = NewColor(0, 121, 241, 255)
|
|
||||||
// Dark Blue
|
|
||||||
DarkBlue = NewColor(0, 82, 172, 255)
|
|
||||||
// Purple
|
|
||||||
Purple = NewColor(200, 122, 255, 255)
|
|
||||||
// Violet
|
|
||||||
Violet = NewColor(135, 60, 190, 255)
|
|
||||||
// Dark Purple
|
|
||||||
DarkPurple = NewColor(112, 31, 126, 255)
|
|
||||||
// Beige
|
|
||||||
Beige = NewColor(211, 176, 131, 255)
|
|
||||||
// Brown
|
|
||||||
Brown = NewColor(127, 106, 79, 255)
|
|
||||||
// Dark Brown
|
|
||||||
DarkBrown = NewColor(76, 63, 47, 255)
|
|
||||||
// White
|
|
||||||
White = NewColor(255, 255, 255, 255)
|
|
||||||
// Black
|
|
||||||
Black = NewColor(0, 0, 0, 255)
|
|
||||||
// Blank (Transparent)
|
|
||||||
Blank = NewColor(0, 0, 0, 0)
|
|
||||||
// Magenta
|
|
||||||
Magenta = NewColor(255, 0, 255, 255)
|
|
||||||
// Ray White (RayLib Logo White)
|
|
||||||
RayWhite = NewColor(245, 245, 245, 255)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Vector2 type
|
|
||||||
type Vector2 struct {
|
|
||||||
X float32
|
|
||||||
Y float32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Vector2) cptr() *C.Vector2 {
|
func (v *Vector2) cptr() *C.Vector2 {
|
||||||
return (*C.Vector2)(unsafe.Pointer(v))
|
return (*C.Vector2)(unsafe.Pointer(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVector2 - Returns new Vector2
|
|
||||||
func NewVector2(x, y float32) Vector2 {
|
|
||||||
return Vector2{x, y}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newVector2FromPointer - Returns new Vector2 from pointer
|
// newVector2FromPointer - Returns new Vector2 from pointer
|
||||||
func newVector2FromPointer(ptr unsafe.Pointer) Vector2 {
|
func newVector2FromPointer(ptr unsafe.Pointer) Vector2 {
|
||||||
return *(*Vector2)(ptr)
|
return *(*Vector2)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector3 type
|
// cptr returns C pointer
|
||||||
type Vector3 struct {
|
|
||||||
X float32
|
|
||||||
Y float32
|
|
||||||
Z float32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *Vector3) cptr() *C.Vector3 {
|
func (v *Vector3) cptr() *C.Vector3 {
|
||||||
return (*C.Vector3)(unsafe.Pointer(v))
|
return (*C.Vector3)(unsafe.Pointer(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVector3 - Returns new Vector3
|
|
||||||
func NewVector3(X, Y, Z float32) Vector3 {
|
|
||||||
return Vector3{X, Y, Z}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newVector3FromPointer - Returns new Vector3 from pointer
|
// newVector3FromPointer - Returns new Vector3 from pointer
|
||||||
func newVector3FromPointer(ptr unsafe.Pointer) Vector3 {
|
func newVector3FromPointer(ptr unsafe.Pointer) Vector3 {
|
||||||
return *(*Vector3)(ptr)
|
return *(*Vector3)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix type (OpenGL style 4x4 - right handed, column major)
|
// cptr returns C pointer
|
||||||
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 {
|
func (m *Matrix) cptr() *C.Matrix {
|
||||||
return (*C.Matrix)(unsafe.Pointer(m))
|
return (*C.Matrix)(unsafe.Pointer(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMatrix - 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}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newMatrixFromPointer - Returns new Matrix from pointer
|
// newMatrixFromPointer - Returns new Matrix from pointer
|
||||||
func newMatrixFromPointer(ptr unsafe.Pointer) Matrix {
|
func newMatrixFromPointer(ptr unsafe.Pointer) Matrix {
|
||||||
return *(*Matrix)(ptr)
|
return *(*Matrix)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mat2 type (used for polygon shape rotation matrix)
|
// cptr returns C pointer
|
||||||
type Mat2 struct {
|
|
||||||
M00 float32
|
|
||||||
M01 float32
|
|
||||||
M10 float32
|
|
||||||
M11 float32
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMat2 - Returns new Mat2
|
|
||||||
func NewMat2(m0, m1, m10, m11 float32) Mat2 {
|
|
||||||
return Mat2{m0, m1, m10, m11}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quaternion type
|
|
||||||
type Quaternion struct {
|
|
||||||
X float32
|
|
||||||
Y float32
|
|
||||||
Z float32
|
|
||||||
W float32
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewQuaternion - 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 {
|
func (color *Color) cptr() *C.Color {
|
||||||
return (*C.Color)(unsafe.Pointer(color))
|
return (*C.Color)(unsafe.Pointer(color))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewColor - Returns new Color
|
|
||||||
func NewColor(r, g, b, a uint8) Color {
|
|
||||||
return Color{r, g, b, a}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newColorFromPointer - Returns new Color from pointer
|
// newColorFromPointer - Returns new Color from pointer
|
||||||
func newColorFromPointer(ptr unsafe.Pointer) Color {
|
func newColorFromPointer(ptr unsafe.Pointer) Color {
|
||||||
return *(*Color)(ptr)
|
return *(*Color)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rectangle type
|
// cptr returns C pointer
|
||||||
type Rectangle struct {
|
|
||||||
X int32
|
|
||||||
Y int32
|
|
||||||
Width int32
|
|
||||||
Height int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Rectangle) cptr() *C.Rectangle {
|
func (r *Rectangle) cptr() *C.Rectangle {
|
||||||
return (*C.Rectangle)(unsafe.Pointer(r))
|
return (*C.Rectangle)(unsafe.Pointer(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRectangle - Returns new Rectangle
|
|
||||||
func NewRectangle(x, y, width, height int32) Rectangle {
|
|
||||||
return Rectangle{x, y, width, height}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newRectangleFromPointer - Returns new Rectangle from pointer
|
// newRectangleFromPointer - Returns new Rectangle from pointer
|
||||||
func newRectangleFromPointer(ptr unsafe.Pointer) Rectangle {
|
func newRectangleFromPointer(ptr unsafe.Pointer) Rectangle {
|
||||||
return *(*Rectangle)(ptr)
|
return *(*Rectangle)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera type, defines a camera position/orientation in 3d space
|
// cptr returns C pointer
|
||||||
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 {
|
func (c *Camera) cptr() *C.Camera {
|
||||||
return (*C.Camera)(unsafe.Pointer(c))
|
return (*C.Camera)(unsafe.Pointer(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCamera - Returns new Camera
|
|
||||||
func NewCamera(pos, target, up Vector3, fovy float32) Camera {
|
|
||||||
return Camera{pos, target, up, fovy}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCameraFromPointer - Returns new Camera from pointer
|
// newCameraFromPointer - Returns new Camera from pointer
|
||||||
func newCameraFromPointer(ptr unsafe.Pointer) Camera {
|
func newCameraFromPointer(ptr unsafe.Pointer) Camera {
|
||||||
return *(*Camera)(ptr)
|
return *(*Camera)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera2D type, defines a 2d camera
|
// cptr returns C pointer
|
||||||
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 {
|
func (c *Camera2D) cptr() *C.Camera2D {
|
||||||
return (*C.Camera2D)(unsafe.Pointer(c))
|
return (*C.Camera2D)(unsafe.Pointer(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCamera2D - Returns new Camera2D
|
|
||||||
func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D {
|
|
||||||
return Camera2D{offset, target, rotation, zoom}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCamera2DFromPointer - Returns new Camera2D from pointer
|
// newCamera2DFromPointer - Returns new Camera2D from pointer
|
||||||
func newCamera2DFromPointer(ptr unsafe.Pointer) Camera2D {
|
func newCamera2DFromPointer(ptr unsafe.Pointer) Camera2D {
|
||||||
return *(*Camera2D)(ptr)
|
return *(*Camera2D)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoundingBox type
|
// cptr returns C pointer
|
||||||
type BoundingBox struct {
|
|
||||||
// Minimum vertex box-corner
|
|
||||||
Min Vector3
|
|
||||||
// Maximum vertex box-corner
|
|
||||||
Max Vector3
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BoundingBox) cptr() *C.BoundingBox {
|
func (b *BoundingBox) cptr() *C.BoundingBox {
|
||||||
return (*C.BoundingBox)(unsafe.Pointer(b))
|
return (*C.BoundingBox)(unsafe.Pointer(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBoundingBox - Returns new BoundingBox
|
|
||||||
func NewBoundingBox(min, max Vector3) BoundingBox {
|
|
||||||
return BoundingBox{min, max}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newBoundingBoxFromPointer - Returns new BoundingBox from pointer
|
// newBoundingBoxFromPointer - Returns new BoundingBox from pointer
|
||||||
func newBoundingBoxFromPointer(ptr unsafe.Pointer) BoundingBox {
|
func newBoundingBoxFromPointer(ptr unsafe.Pointer) BoundingBox {
|
||||||
return *(*BoundingBox)(ptr)
|
return *(*BoundingBox)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset file
|
|
||||||
type Asset interface {
|
|
||||||
io.ReadSeeker
|
|
||||||
io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloseWindow - Close Window and Terminate Context
|
// CloseWindow - Close Window and Terminate Context
|
||||||
func CloseWindow() {
|
func CloseWindow() {
|
||||||
C.CloseWindow()
|
C.CloseWindow()
|
||||||
|
|
|
@ -6,25 +6,6 @@ package raylib
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
// Gestures type
|
|
||||||
type Gestures int32
|
|
||||||
|
|
||||||
// Gestures types
|
|
||||||
// NOTE: It could be used as flags to enable only some gestures
|
|
||||||
const (
|
|
||||||
GestureNone Gestures = 0
|
|
||||||
GestureTap Gestures = 1
|
|
||||||
GestureDoubletap Gestures = 2
|
|
||||||
GestureHold Gestures = 4
|
|
||||||
GestureDrag Gestures = 8
|
|
||||||
GestureSwipeRight Gestures = 16
|
|
||||||
GestureSwipeLeft Gestures = 32
|
|
||||||
GestureSwipeUp Gestures = 64
|
|
||||||
GestureSwipeDown Gestures = 128
|
|
||||||
GesturePinchIn Gestures = 256
|
|
||||||
GesturePinchOut Gestures = 512
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetGesturesEnabled - Enable a set of gestures using flags
|
// SetGesturesEnabled - Enable a set of gestures using flags
|
||||||
func SetGesturesEnabled(gestureFlags uint32) {
|
func SetGesturesEnabled(gestureFlags uint32) {
|
||||||
cgestureFlags := (C.uint)(gestureFlags)
|
cgestureFlags := (C.uint)(gestureFlags)
|
||||||
|
|
156
raylib/models.go
156
raylib/models.go
|
@ -7,189 +7,41 @@ package raylib
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
// Shader location point type
|
// cptr returns C pointer
|
||||||
const (
|
|
||||||
LocVertexPosition = iota
|
|
||||||
LocVertexTexcoord01
|
|
||||||
LocVertexTexcoord02
|
|
||||||
LocVertexNormal
|
|
||||||
LocVertexTangent
|
|
||||||
LocVertexColor
|
|
||||||
LocMatrixMvp
|
|
||||||
LocMatrixModel
|
|
||||||
LocMatrixView
|
|
||||||
LocMatrixProjection
|
|
||||||
LocVectorView
|
|
||||||
LocColorDiffuse
|
|
||||||
LocColorSpecular
|
|
||||||
LocColorAmbient
|
|
||||||
LocMapAlbedo
|
|
||||||
LocMapMetalness
|
|
||||||
LocMapNormal
|
|
||||||
LocMapRoughness
|
|
||||||
LocMapOccusion
|
|
||||||
LocMapEmission
|
|
||||||
LocMapHeight
|
|
||||||
LocMapCubemap
|
|
||||||
LocMapIrradiance
|
|
||||||
LocMapPrefilter
|
|
||||||
LocMapBrdf
|
|
||||||
)
|
|
||||||
|
|
||||||
// Material map type
|
|
||||||
const (
|
|
||||||
// MapDiffuse
|
|
||||||
MapAlbedo = iota
|
|
||||||
MapMetalness
|
|
||||||
MapNormal
|
|
||||||
MapRoughness
|
|
||||||
MapOcclusion
|
|
||||||
MapEmission
|
|
||||||
MapHeight
|
|
||||||
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MapCubemap
|
|
||||||
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MapIrradiance
|
|
||||||
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
|
||||||
MapPrefilter
|
|
||||||
MapBrdf
|
|
||||||
)
|
|
||||||
|
|
||||||
// Material map type
|
|
||||||
const (
|
|
||||||
MapDiffuse = MapAlbedo
|
|
||||||
MapSpecular = MapMetalness
|
|
||||||
LocMapDiffuse = LocMapAlbedo
|
|
||||||
LocMapSpecular = LocMapMetalness
|
|
||||||
)
|
|
||||||
|
|
||||||
// Shader and material limits
|
|
||||||
const (
|
|
||||||
// Maximum number of predefined locations stored in shader struct
|
|
||||||
MaxShaderLocations = 32
|
|
||||||
// Maximum number of texture maps stored in shader struct
|
|
||||||
MaxMaterialMaps = 12
|
|
||||||
)
|
|
||||||
|
|
||||||
// Mesh - 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 {
|
func (m *Mesh) cptr() *C.Mesh {
|
||||||
return (*C.Mesh)(unsafe.Pointer(m))
|
return (*C.Mesh)(unsafe.Pointer(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMesh - 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}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newMeshFromPointer - Returns new Mesh from pointer
|
// newMeshFromPointer - Returns new Mesh from pointer
|
||||||
func newMeshFromPointer(ptr unsafe.Pointer) Mesh {
|
func newMeshFromPointer(ptr unsafe.Pointer) Mesh {
|
||||||
return *(*Mesh)(ptr)
|
return *(*Mesh)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Material type
|
// cptr returns C pointer
|
||||||
type Material struct {
|
|
||||||
// Shader
|
|
||||||
Shader Shader
|
|
||||||
// Maps
|
|
||||||
Maps [MaxMaterialMaps]MaterialMap
|
|
||||||
// Padding
|
|
||||||
_ [4]byte
|
|
||||||
// Generic parameters (if required)
|
|
||||||
Params *[]float32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Material) cptr() *C.Material {
|
func (m *Material) cptr() *C.Material {
|
||||||
return (*C.Material)(unsafe.Pointer(m))
|
return (*C.Material)(unsafe.Pointer(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMaterial - Returns new Material
|
|
||||||
func NewMaterial(shader Shader, maps [MaxMaterialMaps]MaterialMap, params *[]float32) Material {
|
|
||||||
return Material{shader, maps, [4]byte{}, params}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newMaterialFromPointer - Returns new Material from pointer
|
// newMaterialFromPointer - Returns new Material from pointer
|
||||||
func newMaterialFromPointer(ptr unsafe.Pointer) Material {
|
func newMaterialFromPointer(ptr unsafe.Pointer) Material {
|
||||||
return *(*Material)(ptr)
|
return *(*Material)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaterialMap type
|
// cptr returns C pointer
|
||||||
type MaterialMap struct {
|
|
||||||
// Texture
|
|
||||||
Texture Texture2D
|
|
||||||
// Color
|
|
||||||
Color Color
|
|
||||||
// Value
|
|
||||||
Value float32
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 {
|
func (m *Model) cptr() *C.Model {
|
||||||
return (*C.Model)(unsafe.Pointer(m))
|
return (*C.Model)(unsafe.Pointer(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewModel - Returns new Model
|
|
||||||
func NewModel(mesh Mesh, transform Matrix, material Material) Model {
|
|
||||||
return Model{mesh, transform, material, [4]byte{}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newModelFromPointer - Returns new Model from pointer
|
// newModelFromPointer - Returns new Model from pointer
|
||||||
func newModelFromPointer(ptr unsafe.Pointer) Model {
|
func newModelFromPointer(ptr unsafe.Pointer) Model {
|
||||||
return *(*Model)(ptr)
|
return *(*Model)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ray type (useful for raycast)
|
// cptr returns C pointer
|
||||||
type Ray struct {
|
|
||||||
// Ray position (origin)
|
|
||||||
Position Vector3
|
|
||||||
// Ray direction
|
|
||||||
Direction Vector3
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Ray) cptr() *C.Ray {
|
func (r *Ray) cptr() *C.Ray {
|
||||||
return (*C.Ray)(unsafe.Pointer(r))
|
return (*C.Ray)(unsafe.Pointer(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRay - Returns new Ray
|
|
||||||
func NewRay(position, direction Vector3) Ray {
|
|
||||||
return Ray{position, direction}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newRayFromPointer - Returns new Ray from pointer
|
// newRayFromPointer - Returns new Ray from pointer
|
||||||
func newRayFromPointer(ptr unsafe.Pointer) Ray {
|
func newRayFromPointer(ptr unsafe.Pointer) Ray {
|
||||||
return *(*Ray)(ptr)
|
return *(*Ray)(ptr)
|
||||||
|
|
895
raylib/raylib.go
895
raylib/raylib.go
|
@ -36,10 +36,905 @@ Example:
|
||||||
package raylib
|
package raylib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Make sure the main goroutine is bound to the main thread.
|
// Make sure the main goroutine is bound to the main thread.
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewWave - Returns new Wave
|
||||||
|
func NewWave(sampleCount, sampleRate, sampleSize, channels uint32, data []byte) Wave {
|
||||||
|
d := unsafe.Pointer(&data[0])
|
||||||
|
return Wave{sampleCount, sampleRate, sampleSize, channels, d}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sound source type
|
||||||
|
type Sound struct {
|
||||||
|
// Audio source id
|
||||||
|
Source uint32
|
||||||
|
// Audio buffer id
|
||||||
|
Buffer uint32
|
||||||
|
// Audio format specifier
|
||||||
|
Format int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSound - Returns new Sound
|
||||||
|
func NewSound(source, buffer uint32, format int32) Sound {
|
||||||
|
return Sound{source, buffer, format}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Music type (file streaming from memory)
|
||||||
|
// NOTE: Anything longer than ~10 seconds should be streamed
|
||||||
|
type Music struct {
|
||||||
|
CtxType uint32
|
||||||
|
_ [4]byte
|
||||||
|
ctxOgg unsafe.Pointer
|
||||||
|
ctxFlac unsafe.Pointer
|
||||||
|
ctxXm unsafe.Pointer
|
||||||
|
ctxMod unsafe.Pointer
|
||||||
|
Stream AudioStream
|
||||||
|
LoopCount int32
|
||||||
|
TotalSamples uint32
|
||||||
|
SamplesLeft uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// AudioStream 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
|
||||||
|
// Audio format specifier
|
||||||
|
Format int32
|
||||||
|
// Audio source id
|
||||||
|
Source uint32
|
||||||
|
// Audio buffers (double buffering)
|
||||||
|
Buffers [2]uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAudioStream - 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}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CameraMode type
|
||||||
|
type CameraMode int32
|
||||||
|
|
||||||
|
// Camera system modes
|
||||||
|
const (
|
||||||
|
CameraCustom CameraMode = iota
|
||||||
|
CameraFree
|
||||||
|
CameraOrbital
|
||||||
|
CameraFirstPerson
|
||||||
|
CameraThirdPerson
|
||||||
|
)
|
||||||
|
|
||||||
|
// Some basic Defines
|
||||||
|
const (
|
||||||
|
Pi = 3.1415927
|
||||||
|
Deg2rad = 0.017453292
|
||||||
|
Rad2deg = 57.295776
|
||||||
|
|
||||||
|
// Raylib Config Flags
|
||||||
|
|
||||||
|
// Set to show raylib logo at startup
|
||||||
|
FlagShowLogo = 1
|
||||||
|
// Set to run program in fullscreen
|
||||||
|
FlagFullscreenMode = 2
|
||||||
|
// Set to allow resizable window
|
||||||
|
FlagWindowResizable = 4
|
||||||
|
// Set to show window decoration (frame and buttons)
|
||||||
|
FlagWindowDecorated = 8
|
||||||
|
// Set to allow transparent window
|
||||||
|
FlagWindowTransparent = 16
|
||||||
|
// Set to try enabling MSAA 4X
|
||||||
|
FlagMsaa4xHint = 32
|
||||||
|
// Set to try enabling V-Sync on GPU
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
// Some Basic Colors
|
||||||
|
// NOTE: Custom raylib color palette for amazing visuals on WHITE background
|
||||||
|
var (
|
||||||
|
// Light Gray
|
||||||
|
LightGray = NewColor(200, 200, 200, 255)
|
||||||
|
// Gray
|
||||||
|
Gray = NewColor(130, 130, 130, 255)
|
||||||
|
// Dark Gray
|
||||||
|
DarkGray = NewColor(80, 80, 80, 255)
|
||||||
|
// Yellow
|
||||||
|
Yellow = NewColor(253, 249, 0, 255)
|
||||||
|
// Gold
|
||||||
|
Gold = NewColor(255, 203, 0, 255)
|
||||||
|
// Orange
|
||||||
|
Orange = NewColor(255, 161, 0, 255)
|
||||||
|
// Pink
|
||||||
|
Pink = NewColor(255, 109, 194, 255)
|
||||||
|
// Red
|
||||||
|
Red = NewColor(230, 41, 55, 255)
|
||||||
|
// Maroon
|
||||||
|
Maroon = NewColor(190, 33, 55, 255)
|
||||||
|
// Green
|
||||||
|
Green = NewColor(0, 228, 48, 255)
|
||||||
|
// Lime
|
||||||
|
Lime = NewColor(0, 158, 47, 255)
|
||||||
|
// Dark Green
|
||||||
|
DarkGreen = NewColor(0, 117, 44, 255)
|
||||||
|
// Sky Blue
|
||||||
|
SkyBlue = NewColor(102, 191, 255, 255)
|
||||||
|
// Blue
|
||||||
|
Blue = NewColor(0, 121, 241, 255)
|
||||||
|
// Dark Blue
|
||||||
|
DarkBlue = NewColor(0, 82, 172, 255)
|
||||||
|
// Purple
|
||||||
|
Purple = NewColor(200, 122, 255, 255)
|
||||||
|
// Violet
|
||||||
|
Violet = NewColor(135, 60, 190, 255)
|
||||||
|
// Dark Purple
|
||||||
|
DarkPurple = NewColor(112, 31, 126, 255)
|
||||||
|
// Beige
|
||||||
|
Beige = NewColor(211, 176, 131, 255)
|
||||||
|
// Brown
|
||||||
|
Brown = NewColor(127, 106, 79, 255)
|
||||||
|
// Dark Brown
|
||||||
|
DarkBrown = NewColor(76, 63, 47, 255)
|
||||||
|
// White
|
||||||
|
White = NewColor(255, 255, 255, 255)
|
||||||
|
// Black
|
||||||
|
Black = NewColor(0, 0, 0, 255)
|
||||||
|
// Blank (Transparent)
|
||||||
|
Blank = NewColor(0, 0, 0, 0)
|
||||||
|
// Magenta
|
||||||
|
Magenta = NewColor(255, 0, 255, 255)
|
||||||
|
// Ray White (RayLib Logo White)
|
||||||
|
RayWhite = NewColor(245, 245, 245, 255)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Vector2 type
|
||||||
|
type Vector2 struct {
|
||||||
|
X float32
|
||||||
|
Y float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewVector2 - Returns new Vector2
|
||||||
|
func NewVector2(x, y float32) Vector2 {
|
||||||
|
return Vector2{x, y}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vector3 type
|
||||||
|
type Vector3 struct {
|
||||||
|
X float32
|
||||||
|
Y float32
|
||||||
|
Z float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewVector3 - Returns new Vector3
|
||||||
|
func NewVector3(X, Y, Z float32) Vector3 {
|
||||||
|
return Vector3{X, Y, Z}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMatrix - 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}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mat2 type (used for polygon shape rotation matrix)
|
||||||
|
type Mat2 struct {
|
||||||
|
M00 float32
|
||||||
|
M01 float32
|
||||||
|
M10 float32
|
||||||
|
M11 float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMat2 - Returns new Mat2
|
||||||
|
func NewMat2(m0, m1, m10, m11 float32) Mat2 {
|
||||||
|
return Mat2{m0, m1, m10, m11}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quaternion type
|
||||||
|
type Quaternion struct {
|
||||||
|
X float32
|
||||||
|
Y float32
|
||||||
|
Z float32
|
||||||
|
W float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewQuaternion - 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewColor - Returns new Color
|
||||||
|
func NewColor(r, g, b, a uint8) Color {
|
||||||
|
return Color{r, g, b, a}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rectangle type
|
||||||
|
type Rectangle struct {
|
||||||
|
X int32
|
||||||
|
Y int32
|
||||||
|
Width int32
|
||||||
|
Height int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRectangle - Returns new Rectangle
|
||||||
|
func NewRectangle(x, y, width, height int32) Rectangle {
|
||||||
|
return Rectangle{x, y, width, height}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCamera - Returns new Camera
|
||||||
|
func NewCamera(pos, target, up Vector3, fovy float32) Camera {
|
||||||
|
return Camera{pos, target, up, fovy}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCamera2D - Returns new Camera2D
|
||||||
|
func NewCamera2D(offset, target Vector2, rotation, zoom float32) Camera2D {
|
||||||
|
return Camera2D{offset, target, rotation, zoom}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoundingBox type
|
||||||
|
type BoundingBox struct {
|
||||||
|
// Minimum vertex box-corner
|
||||||
|
Min Vector3
|
||||||
|
// Maximum vertex box-corner
|
||||||
|
Max Vector3
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBoundingBox - Returns new BoundingBox
|
||||||
|
func NewBoundingBox(min, max Vector3) BoundingBox {
|
||||||
|
return BoundingBox{min, max}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asset file
|
||||||
|
type Asset interface {
|
||||||
|
io.ReadSeeker
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestures type
|
||||||
|
type Gestures int32
|
||||||
|
|
||||||
|
// Gestures types
|
||||||
|
// NOTE: It could be used as flags to enable only some gestures
|
||||||
|
const (
|
||||||
|
GestureNone Gestures = 0
|
||||||
|
GestureTap Gestures = 1
|
||||||
|
GestureDoubletap Gestures = 2
|
||||||
|
GestureHold Gestures = 4
|
||||||
|
GestureDrag Gestures = 8
|
||||||
|
GestureSwipeRight Gestures = 16
|
||||||
|
GestureSwipeLeft Gestures = 32
|
||||||
|
GestureSwipeUp Gestures = 64
|
||||||
|
GestureSwipeDown Gestures = 128
|
||||||
|
GesturePinchIn Gestures = 256
|
||||||
|
GesturePinchOut Gestures = 512
|
||||||
|
)
|
||||||
|
|
||||||
|
// Shader location point type
|
||||||
|
const (
|
||||||
|
LocVertexPosition = iota
|
||||||
|
LocVertexTexcoord01
|
||||||
|
LocVertexTexcoord02
|
||||||
|
LocVertexNormal
|
||||||
|
LocVertexTangent
|
||||||
|
LocVertexColor
|
||||||
|
LocMatrixMvp
|
||||||
|
LocMatrixModel
|
||||||
|
LocMatrixView
|
||||||
|
LocMatrixProjection
|
||||||
|
LocVectorView
|
||||||
|
LocColorDiffuse
|
||||||
|
LocColorSpecular
|
||||||
|
LocColorAmbient
|
||||||
|
LocMapAlbedo
|
||||||
|
LocMapMetalness
|
||||||
|
LocMapNormal
|
||||||
|
LocMapRoughness
|
||||||
|
LocMapOccusion
|
||||||
|
LocMapEmission
|
||||||
|
LocMapHeight
|
||||||
|
LocMapCubemap
|
||||||
|
LocMapIrradiance
|
||||||
|
LocMapPrefilter
|
||||||
|
LocMapBrdf
|
||||||
|
)
|
||||||
|
|
||||||
|
// Material map type
|
||||||
|
const (
|
||||||
|
// MapDiffuse
|
||||||
|
MapAlbedo = iota
|
||||||
|
MapMetalness
|
||||||
|
MapNormal
|
||||||
|
MapRoughness
|
||||||
|
MapOcclusion
|
||||||
|
MapEmission
|
||||||
|
MapHeight
|
||||||
|
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MapCubemap
|
||||||
|
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MapIrradiance
|
||||||
|
// NOTE: Uses GL_TEXTURE_CUBE_MAP
|
||||||
|
MapPrefilter
|
||||||
|
MapBrdf
|
||||||
|
)
|
||||||
|
|
||||||
|
// Material map type
|
||||||
|
const (
|
||||||
|
MapDiffuse = MapAlbedo
|
||||||
|
MapSpecular = MapMetalness
|
||||||
|
LocMapDiffuse = LocMapAlbedo
|
||||||
|
LocMapSpecular = LocMapMetalness
|
||||||
|
)
|
||||||
|
|
||||||
|
// Shader and material limits
|
||||||
|
const (
|
||||||
|
// Maximum number of predefined locations stored in shader struct
|
||||||
|
MaxShaderLocations = 32
|
||||||
|
// Maximum number of texture maps stored in shader struct
|
||||||
|
MaxMaterialMaps = 12
|
||||||
|
)
|
||||||
|
|
||||||
|
// Mesh - 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMesh - 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}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Material type
|
||||||
|
type Material struct {
|
||||||
|
// Shader
|
||||||
|
Shader Shader
|
||||||
|
// Maps
|
||||||
|
Maps [MaxMaterialMaps]MaterialMap
|
||||||
|
// Padding
|
||||||
|
_ [4]byte
|
||||||
|
// Generic parameters (if required)
|
||||||
|
Params *[]float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMaterial - Returns new Material
|
||||||
|
func NewMaterial(shader Shader, maps [MaxMaterialMaps]MaterialMap, params *[]float32) Material {
|
||||||
|
return Material{shader, maps, [4]byte{}, params}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaterialMap type
|
||||||
|
type MaterialMap struct {
|
||||||
|
// Texture
|
||||||
|
Texture Texture2D
|
||||||
|
// Color
|
||||||
|
Color Color
|
||||||
|
// Value
|
||||||
|
Value float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewModel - Returns new Model
|
||||||
|
func NewModel(mesh Mesh, transform Matrix, material Material) Model {
|
||||||
|
return Model{mesh, transform, material, [4]byte{}}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ray type (useful for raycast)
|
||||||
|
type Ray struct {
|
||||||
|
// Ray position (origin)
|
||||||
|
Position Vector3
|
||||||
|
// Ray direction
|
||||||
|
Direction Vector3
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRay - Returns new Ray
|
||||||
|
func NewRay(position, direction Vector3) Ray {
|
||||||
|
return Ray{position, direction}
|
||||||
|
}
|
||||||
|
|
||||||
|
// VrDevice type
|
||||||
|
type VrDevice int32
|
||||||
|
|
||||||
|
// Head Mounted Display devices
|
||||||
|
const (
|
||||||
|
HmdDefaultDevice VrDevice = iota
|
||||||
|
HmdOculusRiftDk2
|
||||||
|
HmdOculusRiftCv1
|
||||||
|
HmdOculusGo
|
||||||
|
HmdValveHtcVive
|
||||||
|
HmdSonyPsvr
|
||||||
|
)
|
||||||
|
|
||||||
|
// VrDeviceInfo - Head-Mounted-Display device parameters
|
||||||
|
type VrDeviceInfo struct {
|
||||||
|
// HMD horizontal resolution in pixels
|
||||||
|
hResolution int
|
||||||
|
// HMD vertical resolution in pixels
|
||||||
|
vResolution int
|
||||||
|
// HMD horizontal size in meters
|
||||||
|
hScreenSize float32
|
||||||
|
// HMD vertical size in meters
|
||||||
|
vScreenSize float32
|
||||||
|
// HMD screen center in meters
|
||||||
|
vScreenCenter float32
|
||||||
|
// HMD distance between eye and display in meters
|
||||||
|
eyeToScreenDistance float32
|
||||||
|
// HMD lens separation distance in meters
|
||||||
|
lensSeparationDistance float32
|
||||||
|
// HMD IPD (distance between pupils) in meters
|
||||||
|
interpupillaryDistance float32
|
||||||
|
// HMD lens distortion constant parameters
|
||||||
|
lensDistortionValues [4]float32
|
||||||
|
// HMD chromatic aberration correction parameters
|
||||||
|
chromaAbCorrection [4]float32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewVrDeviceInfo - Returns new VrDeviceInfo
|
||||||
|
func NewVrDeviceInfo(hResolution, vResolution int, hScreenSize, vScreenSize, vScreenCenter, eyeToScreenDistance,
|
||||||
|
lensSeparationDistance, interpupillaryDistance float32, lensDistortionValues, chromaAbCorrection [4]float32) VrDeviceInfo {
|
||||||
|
|
||||||
|
return VrDeviceInfo{hResolution, vResolution, hScreenSize, vScreenSize, vScreenCenter, eyeToScreenDistance,
|
||||||
|
lensSeparationDistance, interpupillaryDistance, lensDistortionValues, chromaAbCorrection}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlendMode type
|
||||||
|
type BlendMode int32
|
||||||
|
|
||||||
|
// Color blending modes (pre-defined)
|
||||||
|
const (
|
||||||
|
BlendAlpha BlendMode = iota
|
||||||
|
BlendAdditive
|
||||||
|
BlendMultiplied
|
||||||
|
)
|
||||||
|
|
||||||
|
// Shader type (generic shader)
|
||||||
|
type Shader struct {
|
||||||
|
// Shader program id
|
||||||
|
ID uint32
|
||||||
|
// Shader locations array
|
||||||
|
Locs [MaxShaderLocations]int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewShader - Returns new Shader
|
||||||
|
func NewShader(id uint32, locs [MaxShaderLocations]int32) Shader {
|
||||||
|
return Shader{id, locs}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CharInfo - SpriteFont character info
|
||||||
|
type CharInfo struct {
|
||||||
|
// Character value (Unicode)
|
||||||
|
Value int32
|
||||||
|
// Character rectangle in sprite font
|
||||||
|
Rec Rectangle
|
||||||
|
// Character offset X when drawing
|
||||||
|
OffsetX int32
|
||||||
|
// Character offset Y when drawing
|
||||||
|
OffsetY int32
|
||||||
|
// Character advance position X
|
||||||
|
AdvanceX int32
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCharInfo - Returns new SpriteFont
|
||||||
|
func NewCharInfo(value int32, rec Rectangle, offsetX, offsetY, advanceX int32) CharInfo {
|
||||||
|
return CharInfo{value, rec, offsetX, offsetY, advanceX}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpriteFont type, includes texture and charSet array data
|
||||||
|
type SpriteFont struct {
|
||||||
|
// Font texture
|
||||||
|
Texture Texture2D
|
||||||
|
// Base size (default chars height)
|
||||||
|
BaseSize int32
|
||||||
|
// Number of characters
|
||||||
|
CharsCount int32
|
||||||
|
// Characters info data
|
||||||
|
Chars *CharInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSpriteFont - Returns new SpriteFont
|
||||||
|
func NewSpriteFont(texture Texture2D, baseSize, charsCount int32, chars *CharInfo) SpriteFont {
|
||||||
|
return SpriteFont{texture, baseSize, charsCount, chars}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TextureFormat - Texture format
|
||||||
|
type TextureFormat int32
|
||||||
|
|
||||||
|
// Texture formats
|
||||||
|
// NOTE: Support depends on OpenGL version and platform
|
||||||
|
const (
|
||||||
|
// 8 bit per pixel (no alpha)
|
||||||
|
UncompressedGrayscale TextureFormat = iota + 1
|
||||||
|
// 16 bpp (2 channels)
|
||||||
|
UncompressedGrayAlpha
|
||||||
|
// 16 bpp
|
||||||
|
UncompressedR5g6b5
|
||||||
|
// 24 bpp
|
||||||
|
UncompressedR8g8b8
|
||||||
|
// 16 bpp (1 bit alpha)
|
||||||
|
UncompressedR5g5b5a1
|
||||||
|
// 16 bpp (4 bit alpha)
|
||||||
|
UncompressedR4g4b4a4
|
||||||
|
// 32 bpp
|
||||||
|
UncompressedR8g8b8a8
|
||||||
|
// 4 bpp (no alpha)
|
||||||
|
CompressedDxt1Rgb
|
||||||
|
// 4 bpp (1 bit alpha)
|
||||||
|
CompressedDxt1Rgba
|
||||||
|
// 8 bpp
|
||||||
|
CompressedDxt3Rgba
|
||||||
|
// 8 bpp
|
||||||
|
CompressedDxt5Rgba
|
||||||
|
// 4 bpp
|
||||||
|
CompressedEtc1Rgb
|
||||||
|
// 4 bpp
|
||||||
|
CompressedEtc2Rgb
|
||||||
|
// 8 bpp
|
||||||
|
CompressedEtc2EacRgba
|
||||||
|
// 4 bpp
|
||||||
|
CompressedPvrtRgb
|
||||||
|
// 4 bpp
|
||||||
|
CompressedPvrtRgba
|
||||||
|
// 8 bpp
|
||||||
|
CompressedAstc4x4Rgba
|
||||||
|
// 2 bpp
|
||||||
|
CompressedAstc8x8Rgba
|
||||||
|
)
|
||||||
|
|
||||||
|
// TextureFilterMode - Texture filter mode
|
||||||
|
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 = iota
|
||||||
|
// Linear filtering
|
||||||
|
FilterBilinear
|
||||||
|
// Trilinear filtering (linear with mipmaps)
|
||||||
|
FilterTrilinear
|
||||||
|
// Anisotropic filtering 4x
|
||||||
|
FilterAnisotropic4x
|
||||||
|
// Anisotropic filtering 8x
|
||||||
|
FilterAnisotropic8x
|
||||||
|
// Anisotropic filtering 16x
|
||||||
|
FilterAnisotropic16x
|
||||||
|
)
|
||||||
|
|
||||||
|
// TextureWrapMode - Texture wrap mode
|
||||||
|
type TextureWrapMode int32
|
||||||
|
|
||||||
|
// Texture parameters: wrap mode
|
||||||
|
const (
|
||||||
|
WrapRepeat TextureWrapMode = iota
|
||||||
|
WrapClamp
|
||||||
|
WrapMirror
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToImage converts a Image to Go image.Image
|
||||||
|
func (i *Image) ToImage() image.Image {
|
||||||
|
img := image.NewRGBA(image.Rect(0, 0, int(i.Width), int(i.Height)))
|
||||||
|
|
||||||
|
// Get pixel data from image (RGBA 32bit)
|
||||||
|
pixels := GetImageData(i)
|
||||||
|
|
||||||
|
img.Pix = pixels
|
||||||
|
|
||||||
|
return img
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImage - Returns new Image
|
||||||
|
func NewImage(data []byte, width, height, mipmaps int32, format TextureFormat) *Image {
|
||||||
|
d := unsafe.Pointer(&data[0])
|
||||||
|
return &Image{d, width, height, mipmaps, format}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImageFromImage - Returns new Image from Go image.Image
|
||||||
|
func NewImageFromImage(img image.Image) *Image {
|
||||||
|
size := img.Bounds().Size()
|
||||||
|
pixels := make([]Color, size.X*size.Y)
|
||||||
|
|
||||||
|
for y := 0; y < size.Y; y++ {
|
||||||
|
for x := 0; x < size.X; x++ {
|
||||||
|
color := img.At(x, y)
|
||||||
|
r, g, b, a := color.RGBA()
|
||||||
|
pixels[x+y*size.Y] = NewColor(uint8(r), uint8(g), uint8(b), uint8(a))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return LoadImageEx(pixels, int32(size.X), int32(size.Y))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTexture2D - Returns new Texture2D
|
||||||
|
func NewTexture2D(id uint32, width, height, mipmaps int32, format TextureFormat) Texture2D {
|
||||||
|
return Texture2D{id, width, height, mipmaps, format}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRenderTexture2D - Returns new RenderTexture2D
|
||||||
|
func NewRenderTexture2D(id uint32, texture, depth Texture2D) RenderTexture2D {
|
||||||
|
return RenderTexture2D{id, texture, depth}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log message types
|
||||||
|
const (
|
||||||
|
LogInfo = iota
|
||||||
|
LogWarning
|
||||||
|
LogError
|
||||||
|
LogDebug
|
||||||
|
)
|
||||||
|
|
|
@ -8,87 +8,21 @@ import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
|
||||||
// VrDevice type
|
// cptr returns C pointer
|
||||||
type VrDevice int32
|
|
||||||
|
|
||||||
// Head Mounted Display devices
|
|
||||||
const (
|
|
||||||
HmdDefaultDevice VrDevice = iota
|
|
||||||
HmdOculusRiftDk2
|
|
||||||
HmdOculusRiftCv1
|
|
||||||
HmdOculusGo
|
|
||||||
HmdValveHtcVive
|
|
||||||
HmdSonyPsvr
|
|
||||||
)
|
|
||||||
|
|
||||||
// VrDeviceInfo - Head-Mounted-Display device parameters
|
|
||||||
type VrDeviceInfo struct {
|
|
||||||
// HMD horizontal resolution in pixels
|
|
||||||
hResolution int
|
|
||||||
// HMD vertical resolution in pixels
|
|
||||||
vResolution int
|
|
||||||
// HMD horizontal size in meters
|
|
||||||
hScreenSize float32
|
|
||||||
// HMD vertical size in meters
|
|
||||||
vScreenSize float32
|
|
||||||
// HMD screen center in meters
|
|
||||||
vScreenCenter float32
|
|
||||||
// HMD distance between eye and display in meters
|
|
||||||
eyeToScreenDistance float32
|
|
||||||
// HMD lens separation distance in meters
|
|
||||||
lensSeparationDistance float32
|
|
||||||
// HMD IPD (distance between pupils) in meters
|
|
||||||
interpupillaryDistance float32
|
|
||||||
// HMD lens distortion constant parameters
|
|
||||||
lensDistortionValues [4]float32
|
|
||||||
// HMD chromatic aberration correction parameters
|
|
||||||
chromaAbCorrection [4]float32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *VrDeviceInfo) cptr() *C.VrDeviceInfo {
|
func (v *VrDeviceInfo) cptr() *C.VrDeviceInfo {
|
||||||
return (*C.VrDeviceInfo)(unsafe.Pointer(v))
|
return (*C.VrDeviceInfo)(unsafe.Pointer(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewVrDeviceInfo - Returns new VrDeviceInfo
|
|
||||||
func NewVrDeviceInfo(hResolution, vResolution int, hScreenSize, vScreenSize, vScreenCenter, eyeToScreenDistance,
|
|
||||||
lensSeparationDistance, interpupillaryDistance float32, lensDistortionValues, chromaAbCorrection [4]float32) VrDeviceInfo {
|
|
||||||
|
|
||||||
return VrDeviceInfo{hResolution, vResolution, hScreenSize, vScreenSize, vScreenCenter, eyeToScreenDistance,
|
|
||||||
lensSeparationDistance, interpupillaryDistance, lensDistortionValues, chromaAbCorrection}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newVrDeviceInfoFromPointer - Returns new VrDeviceInfo from pointer
|
// newVrDeviceInfoFromPointer - Returns new VrDeviceInfo from pointer
|
||||||
func newVrDeviceInfoFromPointer(ptr unsafe.Pointer) VrDeviceInfo {
|
func newVrDeviceInfoFromPointer(ptr unsafe.Pointer) VrDeviceInfo {
|
||||||
return *(*VrDeviceInfo)(ptr)
|
return *(*VrDeviceInfo)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlendMode type
|
// cptr returns C pointer
|
||||||
type BlendMode int32
|
|
||||||
|
|
||||||
// Color blending modes (pre-defined)
|
|
||||||
const (
|
|
||||||
BlendAlpha BlendMode = iota
|
|
||||||
BlendAdditive
|
|
||||||
BlendMultiplied
|
|
||||||
)
|
|
||||||
|
|
||||||
// Shader type (generic shader)
|
|
||||||
type Shader struct {
|
|
||||||
// Shader program id
|
|
||||||
ID uint32
|
|
||||||
// Shader locations array
|
|
||||||
Locs [MaxShaderLocations]int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Shader) cptr() *C.Shader {
|
func (s *Shader) cptr() *C.Shader {
|
||||||
return (*C.Shader)(unsafe.Pointer(s))
|
return (*C.Shader)(unsafe.Pointer(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewShader - Returns new Shader
|
|
||||||
func NewShader(id uint32, locs [MaxShaderLocations]int32) Shader {
|
|
||||||
return Shader{id, locs}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newShaderFromPointer - Returns new Shader from pointer
|
// newShaderFromPointer - Returns new Shader from pointer
|
||||||
func newShaderFromPointer(ptr unsafe.Pointer) Shader {
|
func newShaderFromPointer(ptr unsafe.Pointer) Shader {
|
||||||
return *(*Shader)(ptr)
|
return *(*Shader)(ptr)
|
||||||
|
|
|
@ -7,55 +7,21 @@ package raylib
|
||||||
import "C"
|
import "C"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
// CharInfo - SpriteFont character info
|
// cptr returns C pointer
|
||||||
type CharInfo struct {
|
|
||||||
// Character value (Unicode)
|
|
||||||
Value int32
|
|
||||||
// Character rectangle in sprite font
|
|
||||||
Rec Rectangle
|
|
||||||
// Character offset X when drawing
|
|
||||||
OffsetX int32
|
|
||||||
// Character offset Y when drawing
|
|
||||||
OffsetY int32
|
|
||||||
// Character advance position X
|
|
||||||
AdvanceX int32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *CharInfo) cptr() *C.CharInfo {
|
func (c *CharInfo) cptr() *C.CharInfo {
|
||||||
return (*C.CharInfo)(unsafe.Pointer(c))
|
return (*C.CharInfo)(unsafe.Pointer(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCharInfo - Returns new SpriteFont
|
|
||||||
func NewCharInfo(value int32, rec Rectangle, offsetX, offsetY, advanceX int32) CharInfo {
|
|
||||||
return CharInfo{value, rec, offsetX, offsetY, advanceX}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newCharInfoFromPointer - Returns new SpriteFont from pointer
|
// newCharInfoFromPointer - Returns new SpriteFont from pointer
|
||||||
func newCharInfoFromPointer(ptr unsafe.Pointer) CharInfo {
|
func newCharInfoFromPointer(ptr unsafe.Pointer) CharInfo {
|
||||||
return *(*CharInfo)(ptr)
|
return *(*CharInfo)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpriteFont type, includes texture and charSet array data
|
// cptr returns C pointer
|
||||||
type SpriteFont struct {
|
|
||||||
// Font texture
|
|
||||||
Texture Texture2D
|
|
||||||
// Base size (default chars height)
|
|
||||||
BaseSize int32
|
|
||||||
// Number of characters
|
|
||||||
CharsCount int32
|
|
||||||
// Characters info data
|
|
||||||
Chars *CharInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SpriteFont) cptr() *C.SpriteFont {
|
func (s *SpriteFont) cptr() *C.SpriteFont {
|
||||||
return (*C.SpriteFont)(unsafe.Pointer(s))
|
return (*C.SpriteFont)(unsafe.Pointer(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSpriteFont - Returns new SpriteFont
|
|
||||||
func NewSpriteFont(texture Texture2D, baseSize, charsCount int32, chars *CharInfo) SpriteFont {
|
|
||||||
return SpriteFont{texture, baseSize, charsCount, chars}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newSpriteFontFromPointer - Returns new SpriteFont from pointer
|
// newSpriteFontFromPointer - Returns new SpriteFont from pointer
|
||||||
func newSpriteFontFromPointer(ptr unsafe.Pointer) SpriteFont {
|
func newSpriteFontFromPointer(ptr unsafe.Pointer) SpriteFont {
|
||||||
return *(*SpriteFont)(ptr)
|
return *(*SpriteFont)(ptr)
|
||||||
|
|
|
@ -7,191 +7,34 @@ package raylib
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TextureFormat - Texture format
|
// cptr returns C pointer
|
||||||
type TextureFormat int32
|
|
||||||
|
|
||||||
// Texture formats
|
|
||||||
// NOTE: Support depends on OpenGL version and platform
|
|
||||||
const (
|
|
||||||
// 8 bit per pixel (no alpha)
|
|
||||||
UncompressedGrayscale TextureFormat = iota + 1
|
|
||||||
// 16 bpp (2 channels)
|
|
||||||
UncompressedGrayAlpha
|
|
||||||
// 16 bpp
|
|
||||||
UncompressedR5g6b5
|
|
||||||
// 24 bpp
|
|
||||||
UncompressedR8g8b8
|
|
||||||
// 16 bpp (1 bit alpha)
|
|
||||||
UncompressedR5g5b5a1
|
|
||||||
// 16 bpp (4 bit alpha)
|
|
||||||
UncompressedR4g4b4a4
|
|
||||||
// 32 bpp
|
|
||||||
UncompressedR8g8b8a8
|
|
||||||
// 4 bpp (no alpha)
|
|
||||||
CompressedDxt1Rgb
|
|
||||||
// 4 bpp (1 bit alpha)
|
|
||||||
CompressedDxt1Rgba
|
|
||||||
// 8 bpp
|
|
||||||
CompressedDxt3Rgba
|
|
||||||
// 8 bpp
|
|
||||||
CompressedDxt5Rgba
|
|
||||||
// 4 bpp
|
|
||||||
CompressedEtc1Rgb
|
|
||||||
// 4 bpp
|
|
||||||
CompressedEtc2Rgb
|
|
||||||
// 8 bpp
|
|
||||||
CompressedEtc2EacRgba
|
|
||||||
// 4 bpp
|
|
||||||
CompressedPvrtRgb
|
|
||||||
// 4 bpp
|
|
||||||
CompressedPvrtRgba
|
|
||||||
// 8 bpp
|
|
||||||
CompressedAstc4x4Rgba
|
|
||||||
// 2 bpp
|
|
||||||
CompressedAstc8x8Rgba
|
|
||||||
)
|
|
||||||
|
|
||||||
// TextureFilterMode - Texture filter mode
|
|
||||||
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 = iota
|
|
||||||
// Linear filtering
|
|
||||||
FilterBilinear
|
|
||||||
// Trilinear filtering (linear with mipmaps)
|
|
||||||
FilterTrilinear
|
|
||||||
// Anisotropic filtering 4x
|
|
||||||
FilterAnisotropic4x
|
|
||||||
// Anisotropic filtering 8x
|
|
||||||
FilterAnisotropic8x
|
|
||||||
// Anisotropic filtering 16x
|
|
||||||
FilterAnisotropic16x
|
|
||||||
)
|
|
||||||
|
|
||||||
// TextureWrapMode - Texture wrap mode
|
|
||||||
type TextureWrapMode int32
|
|
||||||
|
|
||||||
// Texture parameters: wrap mode
|
|
||||||
const (
|
|
||||||
WrapRepeat TextureWrapMode = iota
|
|
||||||
WrapClamp
|
|
||||||
WrapMirror
|
|
||||||
)
|
|
||||||
|
|
||||||
// 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 {
|
func (i *Image) cptr() *C.Image {
|
||||||
return (*C.Image)(unsafe.Pointer(i))
|
return (*C.Image)(unsafe.Pointer(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToImage converts a Image to Go image.Image
|
|
||||||
func (i *Image) ToImage() image.Image {
|
|
||||||
img := image.NewRGBA(image.Rect(0, 0, int(i.Width), int(i.Height)))
|
|
||||||
|
|
||||||
// Get pixel data from image (RGBA 32bit)
|
|
||||||
pixels := GetImageData(i)
|
|
||||||
|
|
||||||
img.Pix = pixels
|
|
||||||
|
|
||||||
return img
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewImage - Returns new Image
|
|
||||||
func NewImage(data []byte, width, height, mipmaps int32, format TextureFormat) *Image {
|
|
||||||
d := unsafe.Pointer(&data[0])
|
|
||||||
return &Image{d, width, height, mipmaps, format}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newImageFromPointer - Returns new Image from pointer
|
// newImageFromPointer - Returns new Image from pointer
|
||||||
func newImageFromPointer(ptr unsafe.Pointer) *Image {
|
func newImageFromPointer(ptr unsafe.Pointer) *Image {
|
||||||
return (*Image)(ptr)
|
return (*Image)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage - Returns new Image from Go image.Image
|
// cptr returns C pointer
|
||||||
func NewImageFromImage(img image.Image) *Image {
|
|
||||||
size := img.Bounds().Size()
|
|
||||||
pixels := make([]Color, size.X*size.Y)
|
|
||||||
|
|
||||||
for y := 0; y < size.Y; y++ {
|
|
||||||
for x := 0; x < size.X; x++ {
|
|
||||||
color := img.At(x, y)
|
|
||||||
r, g, b, a := color.RGBA()
|
|
||||||
pixels[x+y*size.Y] = NewColor(uint8(r), uint8(g), uint8(b), uint8(a))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return LoadImageEx(pixels, int32(size.X), int32(size.Y))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 {
|
func (t *Texture2D) cptr() *C.Texture2D {
|
||||||
return (*C.Texture2D)(unsafe.Pointer(t))
|
return (*C.Texture2D)(unsafe.Pointer(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTexture2D - Returns new Texture2D
|
|
||||||
func NewTexture2D(id uint32, width, height, mipmaps int32, format TextureFormat) Texture2D {
|
|
||||||
return Texture2D{id, width, height, mipmaps, format}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newTexture2DFromPointer - Returns new Texture2D from pointer
|
// newTexture2DFromPointer - Returns new Texture2D from pointer
|
||||||
func newTexture2DFromPointer(ptr unsafe.Pointer) Texture2D {
|
func newTexture2DFromPointer(ptr unsafe.Pointer) Texture2D {
|
||||||
return *(*Texture2D)(ptr)
|
return *(*Texture2D)(ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderTexture2D type, for texture rendering
|
// cptr returns C pointer
|
||||||
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 {
|
func (r *RenderTexture2D) cptr() *C.RenderTexture2D {
|
||||||
return (*C.RenderTexture2D)(unsafe.Pointer(r))
|
return (*C.RenderTexture2D)(unsafe.Pointer(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRenderTexture2D - Returns new RenderTexture2D
|
|
||||||
func NewRenderTexture2D(id uint32, texture, depth Texture2D) RenderTexture2D {
|
|
||||||
return RenderTexture2D{id, texture, depth}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newRenderTexture2DFromPointer - Returns new RenderTexture2D from pointer
|
// newRenderTexture2DFromPointer - Returns new RenderTexture2D from pointer
|
||||||
func newRenderTexture2DFromPointer(ptr unsafe.Pointer) RenderTexture2D {
|
func newRenderTexture2DFromPointer(ptr unsafe.Pointer) RenderTexture2D {
|
||||||
return *(*RenderTexture2D)(ptr)
|
return *(*RenderTexture2D)(ptr)
|
||||||
|
|
|
@ -7,14 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Log message types
|
|
||||||
const (
|
|
||||||
LogInfo = iota
|
|
||||||
LogWarning
|
|
||||||
LogError
|
|
||||||
LogDebug
|
|
||||||
)
|
|
||||||
|
|
||||||
var traceDebugMsgs = false
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
// SetDebug - Set debug messages
|
// SetDebug - Set debug messages
|
||||||
|
|
|
@ -20,14 +20,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Log message types
|
|
||||||
const (
|
|
||||||
LogInfo = iota
|
|
||||||
LogError
|
|
||||||
LogWarning
|
|
||||||
LogDebug
|
|
||||||
)
|
|
||||||
|
|
||||||
var traceDebugMsgs = false
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
// SetDebug - Set debug messages
|
// SetDebug - Set debug messages
|
||||||
|
|
|
@ -7,14 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Log message types
|
|
||||||
const (
|
|
||||||
LogInfo = iota
|
|
||||||
LogError
|
|
||||||
LogWarning
|
|
||||||
LogDebug
|
|
||||||
)
|
|
||||||
|
|
||||||
var traceDebugMsgs = false
|
var traceDebugMsgs = false
|
||||||
|
|
||||||
// SetDebug - Set debug messages
|
// SetDebug - Set debug messages
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue