This commit is contained in:
xushiwei
2024-06-25 08:40:23 +08:00
parent e2db1cd425
commit 4d57f414f5
3 changed files with 332 additions and 103 deletions

View File

@@ -52,70 +52,8 @@ type Vector4 struct {
// Quaternion, 4 components (Vector4 alias)
type Quaternion = Vector4
// Color, 4 components, R8G8B8A8 (32bit)
// R, G, B, A uint8
type Color uint32
const (
LIGHTGRAY = Color(200 | 200<<8 | 200<<16 | 255<<24) // Light Gray
GRAY = Color(130 | 130<<8 | 130<<16 | 255<<24) // Gray
DARKGRAY = Color(80 | 80<<8 | 80<<16 | 255<<24) // Dark Gray
YELLOW = Color(253 | 249<<8 | 0<<16 | 255<<24) // Yellow
GOLD = Color(255 | 203<<8 | 0<<16 | 255<<24) // Gold
ORANGE = Color(255 | 161<<8 | 0<<16 | 255<<24) // Orange
PINK = Color(255 | 109<<8 | 194<<16 | 255<<24) // Pink
RED = Color(230 | 41<<8 | 55<<16 | 255<<24) // Red
MAROON = Color(190 | 33<<8 | 55<<16 | 255<<24) // Maroon
GREEN = Color(0 | 228<<8 | 48<<16 | 255<<24) // Green
LIME = Color(0 | 158<<8 | 47<<16 | 255<<24) // Lime
DARKGREEN = Color(0 | 117<<8 | 44<<16 | 255<<24) // Dark Green
SKYBLUE = Color(102 | 191<<8 | 255<<16 | 255<<24) // Sky Blue
BLUE = Color(0 | 121<<8 | 241<<16 | 255<<24) // Blue
DARKBLUE = Color(0 | 82<<8 | 172<<16 | 255<<24) // Dark Blue
PURPLE = Color(200 | 122<<8 | 255<<16 | 255<<24) // Purple
VIOLET = Color(135 | 60<<8 | 190<<16 | 255<<24) // Violet
DARKPURPLE = Color(112 | 31<<8 | 126<<16 | 255<<24) // Dark Purple
BEIGE = Color(211 | 176<<8 | 131<<16 | 255<<24) // Beige
BROWN = Color(127 | 106<<8 | 79<<16 | 255<<24) // Brown
DARKBROWN = Color(76 | 63<<8 | 47<<16 | 255<<24) // Dark Brown
WHITE = Color(255 | 255<<8 | 255<<16 | 255<<24) // White
BLACK = Color(0 | 0<<8 | 0<<16 | 255<<24) // Black
BLANK = Color(0 | 0<<8 | 0<<16 | 0<<24) // Blank (Transparent)
MAGENTA = Color(255 | 0<<8 | 255<<16 | 255<<24) // Magenta
RAYWHITE = Color(245 | 245<<8 | 245<<16 | 255<<24) // My own White (raylib logo)
)
// Image, pixel data stored in CPU memory (RAM)
type Image struct {
Data c.Pointer // Image raw data
Width c.Int // Image base width
Height c.Int // Image base height
Mipmaps c.Int // Mipmap levels, 1 by default
Format c.Int // Data format (PixelFormat type)
}
// Camera, defines position/orientation in 3d space
type Camera3D struct {
Position Vector3 // Camera position
Target Vector3 // Camera target it looks-at
Up Vector3 // Camera up vector (rotation over its axis)
Fovy float32 // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
Projection c.Int // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
}
type Camera = Camera3D // Camera type fallback, defaults to Camera3D
// Camera2D, defines position/orientation in 2d space
type Camera2D struct {
Offset Vector2 // Camera offset (displacement from target)
Target Vector2 // Camera target (rotation and zoom origin)
Rotation float32 // Camera rotation in degrees
Zoom float32 // Camera zoom (scaling), should be 1.0f by default
}
// -----------------------------------------------------------------------------
// Window-related functions
//go:linkname InitWindow C.InitWindow
func InitWindow(width, height c.Int, title *c.Char)
@@ -270,6 +208,7 @@ func EnableEventWaiting()
func DisableEventWaiting()
// -----------------------------------------------------------------------------
// Cursor-related functions
//go:linkname ShowCursor C.ShowCursor
func ShowCursor()
@@ -290,47 +229,60 @@ func DisableCursor()
func IsCursorOnScreen() bool
// -----------------------------------------------------------------------------
// Set background color (framebuffer clear color)
//
//go:linkname ClearBackground C.ClearBackground
func ClearBackground(color Color)
//go:linkname BeginDrawing C.BeginDrawing
func BeginDrawing()
//go:linkname EndDrawing C.EndDrawing
func EndDrawing()
//go:linkname BeginMode2D C.BeginMode2D
func BeginMode2D(camera Camera2D)
//go:linkname EndMode2D C.EndMode2D
func EndMode2D()
//go:linkname BeginMode3D C.BeginMode3D
func BeginMode3D(camera Camera3D)
//go:linkname EndMode3D C.EndMode3D
func EndMode3D()
//-go:linkname BeginTextureMode C.BeginTextureMode
//func BeginTextureMode(target RenderTexture2D)
//go:linkname EndTextureMode C.EndTextureMode
func EndTextureMode()
//go:linkname BeginScissorMode C.BeginScissorMode
func BeginScissorMode(x, y, width, height c.Int)
//go:linkname EndScissorMode C.EndScissorMode
func EndScissorMode()
// Shader management functions
// -----------------------------------------------------------------------------
// Draw a color-filled rectangle
//
//go:linkname DrawRectangle C.DrawRectangle
func DrawRectangle(posX, posY, width, height c.Int, color Color)
// Screen-space-related functions
// -----------------------------------------------------------------------------
// Timing-related functions
// Set target FPS (maximum)
//
//go:linkname SetTargetFPS C.SetTargetFPS
func SetTargetFPS(fps c.Int)
// Returns current FPS
//
//go:linkname GetFPS C.GetFPS
func GetFPS() c.Int
// Returns time in seconds for last frame drawn (delta time)
//
//go:linkname GetFrameTime C.GetFrameTime
func GetFrameTime() c.Float
// Returns elapsed time in seconds since InitWindow()
//
//go:linkname GetTime C.GetTime
func GetTime() c.Double
// -----------------------------------------------------------------------------
// Custom frame control functions
// NOTE: Those functions are intended for advance users that want full control over the frame processing
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timing + PollInputEvents()
// To avoid that behaviour and control frame processes manually, enable in config.h: SUPPORT_CUSTOM_FRAME_CONTROL
// -----------------------------------------------------------------------------
// Random values generation functions
// -----------------------------------------------------------------------------
// Misc. functions
// -----------------------------------------------------------------------------
// Input-related functions: keyboard
// -----------------------------------------------------------------------------
// Input-related functions: gamepads
// -----------------------------------------------------------------------------
// Input-related functions: mouse
// -----------------------------------------------------------------------------
// Input-related functions: touch
// -----------------------------------------------------------------------------
// Gestures and Touch Handling Functions (Module: rgestures)
// -----------------------------------------------------------------------------

210
c/raylib/shape.go Normal file
View File

@@ -0,0 +1,210 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package raylib
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
// -----------------------------------------------------------------------------
// Color, 4 components, R8G8B8A8 (32bit)
// R, G, B, A uint8
type Color uint32
const (
LIGHTGRAY = Color(200 | 200<<8 | 200<<16 | 255<<24) // Light Gray
GRAY = Color(130 | 130<<8 | 130<<16 | 255<<24) // Gray
DARKGRAY = Color(80 | 80<<8 | 80<<16 | 255<<24) // Dark Gray
YELLOW = Color(253 | 249<<8 | 0<<16 | 255<<24) // Yellow
GOLD = Color(255 | 203<<8 | 0<<16 | 255<<24) // Gold
ORANGE = Color(255 | 161<<8 | 0<<16 | 255<<24) // Orange
PINK = Color(255 | 109<<8 | 194<<16 | 255<<24) // Pink
RED = Color(230 | 41<<8 | 55<<16 | 255<<24) // Red
MAROON = Color(190 | 33<<8 | 55<<16 | 255<<24) // Maroon
GREEN = Color(0 | 228<<8 | 48<<16 | 255<<24) // Green
LIME = Color(0 | 158<<8 | 47<<16 | 255<<24) // Lime
DARKGREEN = Color(0 | 117<<8 | 44<<16 | 255<<24) // Dark Green
SKYBLUE = Color(102 | 191<<8 | 255<<16 | 255<<24) // Sky Blue
BLUE = Color(0 | 121<<8 | 241<<16 | 255<<24) // Blue
DARKBLUE = Color(0 | 82<<8 | 172<<16 | 255<<24) // Dark Blue
PURPLE = Color(200 | 122<<8 | 255<<16 | 255<<24) // Purple
VIOLET = Color(135 | 60<<8 | 190<<16 | 255<<24) // Violet
DARKPURPLE = Color(112 | 31<<8 | 126<<16 | 255<<24) // Dark Purple
BEIGE = Color(211 | 176<<8 | 131<<16 | 255<<24) // Beige
BROWN = Color(127 | 106<<8 | 79<<16 | 255<<24) // Brown
DARKBROWN = Color(76 | 63<<8 | 47<<16 | 255<<24) // Dark Brown
WHITE = Color(255 | 255<<8 | 255<<16 | 255<<24) // White
BLACK = Color(0 | 0<<8 | 0<<16 | 255<<24) // Black
BLANK = Color(0 | 0<<8 | 0<<16 | 0<<24) // Blank (Transparent)
MAGENTA = Color(255 | 0<<8 | 255<<16 | 255<<24) // Magenta
RAYWHITE = Color(245 | 245<<8 | 245<<16 | 255<<24) // My own White (raylib logo)
)
// Image, pixel data stored in CPU memory (RAM)
type Image struct {
Data c.Pointer // Image raw data
Width c.Int // Image base width
Height c.Int // Image base height
Mipmaps c.Int // Mipmap levels, 1 by default
Format c.Int // Data format (PixelFormat type)
}
// Camera, defines position/orientation in 3d space
type Camera3D struct {
Position Vector3 // Camera position
Target Vector3 // Camera target it looks-at
Up Vector3 // Camera up vector (rotation over its axis)
Fovy float32 // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic
Projection c.Int // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
}
type Camera = Camera3D // Camera type fallback, defaults to Camera3D
// Camera2D, defines position/orientation in 2d space
type Camera2D struct {
Offset Vector2 // Camera offset (displacement from target)
Target Vector2 // Camera target (rotation and zoom origin)
Rotation float32 // Camera rotation in degrees
Zoom float32 // Camera zoom (scaling), should be 1.0f by default
}
// Shader
type Shader struct {
Id c.Uint // Shader program id
Locs *c.Int // Shader locations array (RL_MAX_SHADER_LOCATIONS)
}
// -----------------------------------------------------------------------------
// Drawing-related functions
// Set background color (framebuffer clear color)
//
//go:linkname ClearBackground C.ClearBackground
func ClearBackground(color Color)
// Begin drawing (call before drawing anything)
//
//go:linkname BeginDrawing C.BeginDrawing
func BeginDrawing()
// End drawing and swap buffers (call after drawing)
//
//go:linkname EndDrawing C.EndDrawing
func EndDrawing()
// Begin 2D mode with custom camera (2D)
//
//go:linkname BeginMode2D C.BeginMode2D
func BeginMode2D(camera Camera2D)
// End mode (2D)
//
//go:linkname EndMode2D C.EndMode2D
func EndMode2D()
// Begin 3D mode with custom camera (3D)
//
//go:linkname BeginMode3D C.BeginMode3D
func BeginMode3D(camera Camera3D)
// End mode (3D)
//
//go:linkname EndMode3D C.EndMode3D
func EndMode3D()
// Begin drawing to render texture
//-go:linkname BeginTextureMode C.BeginTextureMode
//func BeginTextureMode(target RenderTexture2D)
// End drawing to render texture
//
//go:linkname EndTextureMode C.EndTextureMode
func EndTextureMode()
// Begin custom shader drawing
//
//go:linkname BeginShaderMode C.BeginShaderMode
func BeginShaderMode(shader Shader)
// End custom shader drawing (use default shader)
//
//go:linkname EndShaderMode C.EndShaderMode
func EndShaderMode()
// Color blending modes (pre-defined)
type BlendMode c.Int
const (
BLEND_ALPHA BlendMode = iota // Blend textures considering alpha (default)
BLEND_ADDITIVE // Blend textures adding colors
BLEND_MULTIPLIED // Blend textures multiplying colors
BLEND_ADD_COLORS // Blend textures adding colors (alternative)
BLEND_SUBTRACT_COLORS // Blend textures subtracting colors (alternative)
BLEND_ALPHA_PREMULTIPLY // Blend premultiplied textures considering alpha
BLEND_CUSTOM // Blend textures using custom src/dst factors (use rlSetBlendFactors())
BLEND_CUSTOM_SEPARATE // Blend textures using custom rgb/alpha separate src/dst factors (use rlSetBlendFactorsSeparate())
)
// Begin blending mode (alpha, additive, multiplied, subtract, custom)
//
//go:linkname BeginBlendMode C.BeginBlendMode
func BeginBlendMode(mode BlendMode)
// End blending mode (reset to default: alpha blending)
//
//go:linkname EndBlendMode C.EndBlendMode
func EndBlendMode()
// Begin scissor mode (define screen area for following drawing)
//
//go:linkname BeginScissorMode C.BeginScissorMode
func BeginScissorMode(x, y, width, height c.Int)
// End scissor mode
//
//go:linkname EndScissorMode C.EndScissorMode
func EndScissorMode()
// -----------------------------------------------------------------------------
// VR stereo config functions for VR simulator
// -----------------------------------------------------------------------------
// Camera System Functions (Module: rcamera)
// Update camera position for selected mode
//
//go:linkname UpdateCamera C.UpdateCamera
func UpdateCamera(camera *Camera, mode c.Int)
// Update camera movement/rotation
//
//go:linkname UpdateCameraPro C.UpdateCameraPro
func UpdateCameraPro(camera *Camera, movement, rotation Vector3, zoom float32)
// -----------------------------------------------------------------------------
// Draw a color-filled rectangle
//
//go:linkname DrawRectangle C.DrawRectangle
func DrawRectangle(posX, posY, width, height c.Int, color Color)
// -----------------------------------------------------------------------------

67
c/raylib/utils.go Normal file
View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package raylib
import (
_ "unsafe"
"github.com/goplus/llgo/c"
)
// -----------------------------------------------------------------------------
// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...)
//
//go:linkname TraceLog C.TraceLog
func TraceLog(logLevel int, text *c.Char, __llgo_va_list ...any)
// Set the current threshold (minimum) log level
//
//go:linkname SetTraceLogLevel C.SetTraceLogLevel
func SetTraceLogLevel(logLevel int)
// -----------------------------------------------------------------------------
// Set custom callbacks
// -----------------------------------------------------------------------------
// Files management functions
// -----------------------------------------------------------------------------
// File system functions
// Check if file exists
//
//go:linkname FileExists C.FileExists
func FileExists(fileName *c.Char) bool
// Check if a directory path exists
//
//go:linkname DirectoryExists C.DirectoryExists
func DirectoryExists(dirPath *c.Char) bool
// Check file extension (including point: .png, .wav)
//
//go:linkname IsFileExtension C.IsFileExtension
func IsFileExtension(fileName *c.Char, ext *c.Char) bool
// -----------------------------------------------------------------------------
// Compression/Encoding functionality
// -----------------------------------------------------------------------------
// Automation events functionality
// -----------------------------------------------------------------------------