Compare commits
No commits in common. "master" and "2.1-dev" have entirely different histories.
23
.appveyor.yml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
version: "{build}"
|
||||||
|
|
||||||
|
clone_depth: 1
|
||||||
|
|
||||||
|
clone_folder: c:\gopath\src\github.com\gen2brain\raylib-go
|
||||||
|
|
||||||
|
environment:
|
||||||
|
GOPATH: c:\gopath
|
||||||
|
MSYS_PATH: c:\msys64
|
||||||
|
CGO_ENABLED: 1
|
||||||
|
CGO_CFLAGS: -g -O2 -Ic:\msys64\mingw32\include
|
||||||
|
GOARCH: 386
|
||||||
|
CC: i686-w64-mingw32-gcc
|
||||||
|
|
||||||
|
install:
|
||||||
|
- echo %GOPATH%
|
||||||
|
- echo %MSYS_PATH%
|
||||||
|
- set PATH=%GOPATH%\bin;c:\go\bin;%MSYS_PATH%\usr\bin;%MSYS_PATH%\mingw32\bin;%PATH%
|
||||||
|
- go version
|
||||||
|
- go env
|
||||||
|
|
||||||
|
build_script:
|
||||||
|
- bash -lc "cd /c/gopath/src/github.com/gen2brain/raylib-go && go get -t ./... && make"
|
4
.gitignore
vendored
|
@ -1,4 +0,0 @@
|
||||||
# IDE folders
|
|
||||||
.idea
|
|
||||||
.vsc
|
|
||||||
.vs
|
|
17
.travis.yml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
language: go
|
||||||
|
|
||||||
|
os:
|
||||||
|
- linux
|
||||||
|
#- osx
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.9.x
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
|
||||||
|
sudo apt-get update -y;
|
||||||
|
sudo apt-get install libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev -y;
|
||||||
|
fi
|
||||||
|
|
||||||
|
install:
|
||||||
|
- go get -t ./...
|
11
Makefile
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
PACKAGES= raylib raygui raymath easings physics rres
|
||||||
|
|
||||||
|
GO?= go
|
||||||
|
|
||||||
|
all: packages
|
||||||
|
|
||||||
|
packages:
|
||||||
|
@for pkg in ${PACKAGES}; do \
|
||||||
|
echo "Building package github.com/gen2brain/raylib-go/$$pkg..."; \
|
||||||
|
${GO} build github.com/gen2brain/raylib-go/$$pkg || exit 1; \
|
||||||
|
done
|
106
README.md
|
@ -1,92 +1,78 @@
|
||||||

|

|
||||||
## raylib-go
|
## raylib-go
|
||||||
[](https://git.terah.dev/UnrealXR/raylib-go/actions)
|
[](https://travis-ci.org/gen2brain/raylib-go)
|
||||||
[](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/raylib)
|
[](https://ci.appveyor.com/project/gen2brain/raylib-go)
|
||||||
[](https://goreportcard.com/report/git.terah.dev/UnrealXR/raylib-go/raylib)
|
[](https://godoc.org/github.com/gen2brain/raylib-go/raylib)
|
||||||
[](https://git.terah.dev/UnrealXR/raylib-go/src/branch/master/examples)
|
[](https://goreportcard.com/report/github.com/gen2brain/raylib-go)
|
||||||
|
[](https://github.com/gen2brain/raylib-go/tree/master/examples)
|
||||||
|
|
||||||
Golang bindings for [raylib](http://www.raylib.com/), a simple and easy-to-use library to enjoy videogames programming.
|
Golang bindings for [raylib](http://www.raylib.com/), a simple and easy-to-use library to learn videogames programming.
|
||||||
|
|
||||||
This is a fork of [gen2brain's `raylib-go` bindings](https://github.com/gen2brain/raylib-go) to add [DRM leasing](https://wayland.app/protocols/drm-lease-v1) support.
|

|
||||||
|
|
||||||
raylib C source code is included and compiled together with bindings. Note that the first build can take a few minutes.
|
|
||||||
|
|
||||||
It is also possible to use raylib-go without cgo (Windows only; see requirements below).
|
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
##### Ubuntu
|
##### Ubuntu
|
||||||
|
|
||||||
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev libwayland-dev libxkbcommon-dev
|
###### X11
|
||||||
|
|
||||||
|
apt-get install libgl1-mesa-dev libxi-dev libxcursor-dev libxrandr-dev libxinerama-dev
|
||||||
|
|
||||||
|
###### Wayland
|
||||||
|
|
||||||
|
apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev
|
||||||
|
|
||||||
##### Fedora
|
##### Fedora
|
||||||
|
|
||||||
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel wayland-devel libxkbcommon-devel
|
###### X11
|
||||||
|
|
||||||
|
dnf install mesa-libGL-devel libXi-devel libXcursor-devel libXrandr-devel libXinerama-devel
|
||||||
|
|
||||||
|
###### Wayland
|
||||||
|
|
||||||
|
dnf install mesa-libGL-devel wayland-devel libxkbcommon-devel
|
||||||
|
|
||||||
##### macOS
|
##### macOS
|
||||||
|
|
||||||
On macOS, you need Xcode or Command Line Tools for Xcode (if you have `brew` installed, you already have this).
|
On macOS you need Xcode or Command Line Tools for Xcode.
|
||||||
|
|
||||||
##### Windows
|
##### Windows
|
||||||
|
|
||||||
###### cgo
|
|
||||||
|
|
||||||
On Windows you need C compiler, like [Mingw-w64](https://mingw-w64.org) or [TDM-GCC](http://tdm-gcc.tdragon.net/).
|
On Windows you need C compiler, like [Mingw-w64](https://mingw-w64.org) or [TDM-GCC](http://tdm-gcc.tdragon.net/).
|
||||||
You can also build binary in [MSYS2](https://msys2.github.io/) shell.
|
You can also build binary in [MSYS2](https://msys2.github.io/) shell.
|
||||||
|
|
||||||
To remove console window, build with `-ldflags "-H=windowsgui"`.
|
|
||||||
|
|
||||||
###### purego (without cgo, i.e. CGO_ENABLED=0)
|
|
||||||
|
|
||||||
Download the raylib.dll from the assets on the [releases page](https://github.com/raysan5/raylib/releases). It is contained in the `raylib-*_win64_msvc*.zip`.
|
|
||||||
Put the raylib.dll into the root folder of your project or copy it into `C:\Windows\System32` for a system-wide installation.
|
|
||||||
|
|
||||||
It is also possible to build the DLL yourself. You can find more info at [raylib's wiki](https://github.com/raysan5/raylib/wiki/Working-on-Windows).
|
|
||||||
|
|
||||||
##### Android
|
##### Android
|
||||||
|
|
||||||
[Android example](https://git.terah.dev/UnrealXR/raylib-go/tree/master/examples/others/android/example).
|
[Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example).
|
||||||
|
|
||||||
##### Wasm
|
##### Raspberry Pi
|
||||||
|
|
||||||
For web bindings, refer to [Raylib-Go-Wasm](https://github.com/BrownNPC/Raylib-Go-Wasm); it should be largely compatible with this repository.
|
|
||||||
|
|
||||||
|
[RPi example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/rpi/basic_window).
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
go get -v -u git.terah.dev/UnrealXR/raylib-go/raylib
|
go get -v -u github.com/gen2brain/raylib-go/raylib
|
||||||
|
|
||||||
### Build tags
|
### Build tags
|
||||||
|
|
||||||
* `drm` - build for Linux native [DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager) mode, including Raspberry Pi 4 and other devices (PLATFORM_DRM)
|
|
||||||
* `drm_disable_input` - disables keyboard input capabilities for the DRM backend. Requires the `drm` build tag as a prerequisite
|
|
||||||
* `drm_leasing` - enables Wayland DRM leasing capabilties. Requires the `drm` build tag as a prerequisite
|
|
||||||
* `sdl` - build for [SDL](https://github.com/libsdl-org/SDL) backend (PLATFORM_DESKTOP_SDL)
|
|
||||||
* `sdl3` - build for [SDL3](https://github.com/libsdl-org/SDL) backend (PLATFORM_DESKTOP_SDL3)
|
|
||||||
* `rgfw` - build for [RGFW](https://github.com/ColleagueRiley/RGFW) backend (PLATFORM_DESKTOP_RGFW)
|
|
||||||
* `noaudio` - disables audio functions
|
* `noaudio` - disables audio functions
|
||||||
* `opengl43` - uses OpenGL 4.3 backend
|
|
||||||
* `opengl21` - uses OpenGL 2.1 backend (default is 3.3 on desktop)
|
* `opengl21` - uses OpenGL 2.1 backend (default is 3.3 on desktop)
|
||||||
* `opengl11` - uses OpenGL 1.1 backend (pseudo OpenGL 1.1 style)
|
* `opengl11` - uses OpenGL 1.1 backend (pseudo OpenGL 1.1 style)
|
||||||
* `es2` - uses OpenGL ES 2.0 backend (can be used to link against [Google's ANGLE](https://github.com/google/angle))
|
* `wayland` - builds against Wayland libraries
|
||||||
* `es3` - experimental support for OpenGL ES 3.0
|
|
||||||
* `x11` - force X11 compatibility mode on Wayland (PLATFORM_DESKTOP/GLFW)
|
|
||||||
* `wayland` - force Wayland only mode (PLATFORM_DESKTOP/GLFW)
|
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
Documentation on [GoDoc](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/raylib). Also check raylib [cheatsheet](http://www.raylib.com/cheatsheet/cheatsheet.html). If you have problems or need assistance there is an active community in the #raylib-go channel of the [Raylib Discord Server](https://discord.gg/raylib) that can help.
|
Documentation on [GoDoc](https://godoc.org/github.com/gen2brain/raylib-go/raylib). Also check raylib [cheatsheet](http://www.raylib.com/cheatsheet/cheatsheet.html).
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
import "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||||
defer rl.CloseWindow()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
|
@ -94,41 +80,19 @@ func main() {
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Check more [examples](https://git.terah.dev/UnrealXR/raylib-go/tree/master/examples) organized by raylib modules.
|
Check more [examples](https://github.com/gen2brain/raylib-go/tree/master/examples) organized by raylib modules.
|
||||||
|
|
||||||
### Cross-compile (Linux)
|
|
||||||
|
|
||||||
To cross-compile for Windows install [MinGW](https://www.mingw-w64.org/) toolchain.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -ldflags "-s -w"
|
|
||||||
$ file basic_window.exe
|
|
||||||
basic_window.exe: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows, 11 sections
|
|
||||||
|
|
||||||
$ CGO_ENABLED=1 CC=i686-w64-mingw32-gcc GOOS=windows GOARCH=386 go build -ldflags "-s -w"
|
|
||||||
$ file basic_window.exe
|
|
||||||
basic_window.exe: PE32 executable (console) Intel 80386 (stripped to external PDB), for MS Windows, 9 sections
|
|
||||||
```
|
|
||||||
|
|
||||||
To cross-compile for macOS install [OSXCross](https://github.com/tpoechtrager/osxcross) toolchain.
|
|
||||||
|
|
||||||
```
|
|
||||||
$ CGO_ENABLED=1 CC=x86_64-apple-darwin21.1-clang GOOS=darwin GOARCH=amd64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=10.15'"
|
|
||||||
$ file basic_window
|
|
||||||
basic_window: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>
|
|
||||||
|
|
||||||
$ CGO_ENABLED=1 CC=aarch64-apple-darwin21.1-clang GOOS=darwin GOARCH=arm64 go build -ldflags "-linkmode external -s -w '-extldflags=-mmacosx-version-min=12.0.0'"
|
|
||||||
$ file basic_window
|
|
||||||
basic_window: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
|
|
||||||
```
|
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
raylib-go is licensed under an unmodified zlib/libpng license. View [LICENSE](https://git.terah.dev/UnrealXR/raylib-go/blob/master/LICENSE).
|
raylib-go is licensed under an unmodified zlib/libpng license. View [LICENSE](https://github.com/gen2brain/raylib-go/blob/master/LICENSE).
|
||||||
|
|
Before Width: | Height: | Size: 1 KiB |
|
@ -1,7 +1,7 @@
|
||||||
## easings [](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/easings)
|
## easings [](https://godoc.org/github.com/gen2brain/raylib-go/easings)
|
||||||
|
|
||||||
Useful easing functions for values animation.
|
Useful easing functions for values animation.
|
||||||
|
|
||||||
A port of Robert Penner's [easing equations](http://robertpenner.com/easing/).
|
A port of Robert Penner's [easing equations](http://robertpenner.com/easing/).
|
||||||
|
|
||||||

|

|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
module git.terah.dev/UnrealXR/raylib-go/easings
|
|
||||||
|
|
||||||
go 1.21
|
|
|
@ -1,155 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [audio] example - Mixed audio processing
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.2, last time updated with raylib 4.2
|
|
||||||
*
|
|
||||||
* Example contributed by hkc (@hatkidchan) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 hkc (@hatkidchan)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
var exponent float32 = 1.0 // Audio exponentiation value
|
|
||||||
var averageVolume [400]float32 // Average volume history
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [audio] example - processing mixed output")
|
|
||||||
|
|
||||||
rl.InitAudioDevice() // Initialize audio device
|
|
||||||
rl.AttachAudioMixedProcessor(ProcessAudio)
|
|
||||||
|
|
||||||
music := rl.LoadMusicStream("country.mp3")
|
|
||||||
sound := rl.LoadSound("coin.wav")
|
|
||||||
|
|
||||||
rl.PlayMusicStream(music)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
rl.UpdateMusicStream(music) // Update music buffer with new stream data
|
|
||||||
|
|
||||||
// Modify processing variables
|
|
||||||
if rl.IsKeyPressed(rl.KeyLeft) {
|
|
||||||
exponent -= 0.05
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyRight) {
|
|
||||||
exponent += 0.05
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyDown) {
|
|
||||||
exponent -= 0.25
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyUp) {
|
|
||||||
exponent += 0.25
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure that exponent stays between 0.5 and 3
|
|
||||||
exponent = clamp(exponent, 0.5, 3)
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
rl.PlaySound(sound)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.DrawText("MUSIC SHOULD BE PLAYING!", 255, 150, 20, rl.LightGray)
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("EXPONENT = %.2f", exponent), 215, 180, 20, rl.LightGray)
|
|
||||||
|
|
||||||
rl.DrawRectangle(199, 199, 402, 34, rl.LightGray)
|
|
||||||
for i := int32(0); i < 400; i++ {
|
|
||||||
rl.DrawLine(201+i, 232-int32(averageVolume[i]*32), 201+i, 232, rl.Maroon)
|
|
||||||
}
|
|
||||||
rl.DrawRectangleLines(199, 199, 402, 34, rl.Gray)
|
|
||||||
|
|
||||||
rl.DrawText("PRESS SPACE TO PLAY OTHER SOUND", 200, 250, 20, rl.LightGray)
|
|
||||||
rl.DrawText("USE LEFT AND RIGHT ARROWS TO ALTER DISTORTION", 140, 280, 20, rl.LightGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
rl.UnloadMusicStream(music) // Unload music stream buffers from RAM
|
|
||||||
rl.DetachAudioMixedProcessor(ProcessAudio) // Disconnect audio processor
|
|
||||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessAudio is the audio processing function
|
|
||||||
func ProcessAudio(buffer []float32, frames int) {
|
|
||||||
var average float32 // Temporary average volume
|
|
||||||
maxFrame := frames / 2
|
|
||||||
|
|
||||||
// Each frame has 2 samples (left and right),
|
|
||||||
// so we should loop `frames / 2` times
|
|
||||||
for frame := 0; frame < maxFrame; frame++ {
|
|
||||||
left := &buffer[frame*2+0] // Left channel
|
|
||||||
right := &buffer[frame*2+1] // Right channel
|
|
||||||
|
|
||||||
// Modify left and right channel samples with exponent
|
|
||||||
*left = pow(abs(*left), exponent) * sgn(*left)
|
|
||||||
*right = pow(abs(*right), exponent) * sgn(*right)
|
|
||||||
|
|
||||||
// Accumulating average volume
|
|
||||||
average += abs(*left) / float32(maxFrame)
|
|
||||||
average += abs(*right) / float32(maxFrame)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shift average volume history buffer to the left
|
|
||||||
for i := 0; i < 399; i++ {
|
|
||||||
averageVolume[i] = averageVolume[i+1]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the new average value
|
|
||||||
averageVolume[399] = average
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions to make the code shorter
|
|
||||||
// (using less type conversions)
|
|
||||||
// (Golang: Please make the `math` package generic! This is ridiculous :-)
|
|
||||||
func abs(value float32) float32 {
|
|
||||||
return float32(math.Abs(float64(value)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func pow(value, exponent float32) float32 {
|
|
||||||
return float32(math.Pow(float64(value), float64(exponent)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func sgn(value float32) float32 {
|
|
||||||
if value < 0 {
|
|
||||||
return -1
|
|
||||||
} else if value > 0 {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
func clamp(value, min, max float32) float32 {
|
|
||||||
if value < min {
|
|
||||||
return min
|
|
||||||
}
|
|
||||||
if value > max {
|
|
||||||
return max
|
|
||||||
}
|
|
||||||
return value
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxCircles = 64
|
const maxCircles = 64
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
||||||
rl.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
|
@ -1,69 +1,71 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nSamples = 44000 * 10
|
maxSamples = 22050
|
||||||
sampleRate = 6000
|
maxSamplesPerUpdate = 4096
|
||||||
bufferSize = nSamples
|
|
||||||
frequency = 440
|
|
||||||
targetFPS = 240
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||||
position := rl.NewVector2(0, 0)
|
|
||||||
|
|
||||||
rl.SetAudioStreamBufferSizeDefault(bufferSize)
|
|
||||||
|
|
||||||
rl.InitAudioDevice()
|
rl.InitAudioDevice()
|
||||||
|
|
||||||
// Init raw audio stream (sample rate: <nSamples>, sample size: 32bit-float, channels: 1-mono)
|
// Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono)
|
||||||
stream := rl.LoadAudioStream(nSamples, 32, 1)
|
stream := rl.InitAudioStream(22050, 32, 1)
|
||||||
|
|
||||||
//// Create sine wave to play
|
//// Fill audio stream with some samples (sine wave)
|
||||||
data := make([]float32, nSamples)
|
data := make([]float32, maxSamples)
|
||||||
|
|
||||||
for i := 0; i < nSamples; i++ {
|
for i := 0; i < maxSamples; i++ {
|
||||||
t := float32(i) / float32(nSamples)
|
data[i] = float32(math.Sin(float64((2*rl.Pi*float32(i))/2) * rl.Deg2rad))
|
||||||
data[i] = float32(math.Sin(float64((2 * rl.Pi * frequency * t))))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The buffer can only be updated when it has been processed. Time between buffer processing and next load and causes clipping
|
// NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop
|
||||||
|
// for that reason, there is a clip everytime audio stream is looped
|
||||||
rl.PlayAudioStream(stream)
|
rl.PlayAudioStream(stream)
|
||||||
|
|
||||||
startTime := time.Now()
|
totalSamples := int32(maxSamples)
|
||||||
rl.SetTargetFPS(targetFPS)
|
samplesLeft := int32(totalSamples)
|
||||||
|
|
||||||
|
position := rl.NewVector2(0, 0)
|
||||||
|
|
||||||
|
rl.SetTargetFPS(30)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Refill audio stream if buffer is processed
|
// Refill audio stream if required
|
||||||
if rl.IsAudioStreamProcessed(stream) {
|
if rl.IsAudioBufferProcessed(stream) {
|
||||||
elapsedTime := time.Since(startTime).Seconds()
|
numSamples := int32(0)
|
||||||
currentSampleIndex := int(math.Mod(elapsedTime*float64(sampleRate), float64(nSamples)))
|
if samplesLeft >= maxSamplesPerUpdate {
|
||||||
nextSampleIndex := currentSampleIndex + bufferSize
|
numSamples = maxSamplesPerUpdate
|
||||||
|
|
||||||
if nextSampleIndex > nSamples {
|
|
||||||
nextSampleIndex = bufferSize - (nSamples - currentSampleIndex)
|
|
||||||
rl.UpdateAudioStream(stream, append(data[currentSampleIndex:], data[:nextSampleIndex]...))
|
|
||||||
} else {
|
} else {
|
||||||
rl.UpdateAudioStream(stream, data[currentSampleIndex:nextSampleIndex])
|
numSamples = samplesLeft
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.UpdateAudioStream(stream, data[totalSamples-samplesLeft:], numSamples)
|
||||||
|
|
||||||
|
samplesLeft -= numSamples
|
||||||
|
|
||||||
|
// Reset samples feeding (loop audio)
|
||||||
|
if samplesLeft <= 0 {
|
||||||
|
samplesLeft = totalSamples
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
rl.DrawText(fmt.Sprintf("%d Hz SINE WAVE SHOULD BE PLAYING!", frequency), 200, 140, 20, rl.LightGray)
|
rl.DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, rl.LightGray)
|
||||||
|
|
||||||
// NOTE: Draw a part of the sine wave (only screen width)
|
// NOTE: Draw a part of the sine wave (only screen width)
|
||||||
for i := 0; i < int(rl.GetScreenWidth()); i++ {
|
for i := 0; i < int(rl.GetScreenWidth()); i++ {
|
||||||
position.X = float32(i)
|
position.X = float32(i)
|
||||||
position.Y = 250 + 10*data[i*nSamples/int(20*rl.GetScreenWidth())]
|
position.Y = 250 + 50*data[i]
|
||||||
|
|
||||||
rl.DrawPixelV(position, rl.Red)
|
rl.DrawPixelV(position, rl.Red)
|
||||||
}
|
}
|
||||||
|
@ -71,7 +73,7 @@ func main() {
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.UnloadAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
rl.CloseAudioStream(stream) // Close raw audio stream and delete buffers from RAM
|
||||||
|
|
||||||
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
rl.CloseAudioDevice() // Close audio device (music streaming is automatically stopped)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [audio] example - Playing sound multiple times
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.6
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 Jeffery Myers (@JeffM2501)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
maxSounds = 10
|
|
||||||
)
|
|
||||||
|
|
||||||
var soundArray [maxSounds]rl.Sound
|
|
||||||
var currentSound int32
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [audio] example - playing sound multiple times")
|
|
||||||
|
|
||||||
// Initialize audio device
|
|
||||||
rl.InitAudioDevice()
|
|
||||||
|
|
||||||
// Load WAV audio file into the first slot as the 'source' sound
|
|
||||||
// this sound owns the sample data
|
|
||||||
soundArray[0] = rl.LoadSound("sound.wav")
|
|
||||||
|
|
||||||
for i := 1; i < maxSounds; i++ {
|
|
||||||
// Load an alias of the sound into slots 1-9.
|
|
||||||
// These do not own the sound data, but can be played
|
|
||||||
soundArray[i] = rl.LoadSoundAlias(soundArray[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
rl.PlaySound(soundArray[currentSound]) // play the next open sound slot
|
|
||||||
currentSound++ // increment the sound slot
|
|
||||||
if currentSound >= maxSounds { // if the sound slot is out of bounds, go back to 0
|
|
||||||
currentSound = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: a better way would be to look at the list for the first sound that is not playing and use that slot
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.DrawText("Press SPACE to PLAY a WAV sound!", 200, 180, 20, rl.LightGray)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadSound(soundArray[0]) // Unload source sound data
|
|
||||||
rl.CloseAudioDevice() // Close audio device
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -38,17 +38,19 @@ func main() {
|
||||||
|
|
||||||
camera := rl.Camera2D{}
|
camera := rl.Camera2D{}
|
||||||
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
camera.Target = rl.NewVector2(float32(player.X+20), float32(player.Y+20))
|
||||||
camera.Offset = rl.NewVector2(float32(screenWidth/2), float32(screenHeight/2))
|
camera.Offset = rl.NewVector2(0, 0)
|
||||||
camera.Rotation = 0.0
|
camera.Rotation = 0.0
|
||||||
camera.Zoom = 1.0
|
camera.Zoom = 1.0
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(30)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if rl.IsKeyDown(rl.KeyRight) {
|
if rl.IsKeyDown(rl.KeyRight) {
|
||||||
player.X += 2 // Player movement
|
player.X += 2 // Player movement
|
||||||
|
camera.Offset.X -= 2 // Camera displacement with player movement
|
||||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
} else if rl.IsKeyDown(rl.KeyLeft) {
|
||||||
player.X -= 2 // Player movement
|
player.X -= 2 // Player movement
|
||||||
|
camera.Offset.X += 2 // Camera displacement with player movement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Camera target follows player
|
// Camera target follows player
|
||||||
|
|
|
@ -1,101 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - 2d camera mouse zoom
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.2, last time updated with raylib 4.2
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022 Jeffery Myers (@JeffM2501)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera mouse zoom")
|
|
||||||
|
|
||||||
var camera rl.Camera2D
|
|
||||||
camera.Zoom = 1.0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Translate based on mouse right click
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
|
||||||
delta := rl.GetMouseDelta()
|
|
||||||
delta = rl.Vector2Scale(delta, -1.0/camera.Zoom)
|
|
||||||
|
|
||||||
camera.Target = rl.Vector2Add(camera.Target, delta)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zoom based on mouse wheel
|
|
||||||
wheel := rl.GetMouseWheelMove()
|
|
||||||
if wheel != 0 {
|
|
||||||
// Get the world point that is under the mouse
|
|
||||||
mouseWorldPos := rl.GetScreenToWorld2D(rl.GetMousePosition(), camera)
|
|
||||||
|
|
||||||
// Set the offset to where the mouse is
|
|
||||||
camera.Offset = rl.GetMousePosition()
|
|
||||||
|
|
||||||
// Set the target to match, so that the camera maps the world space point
|
|
||||||
// under the cursor to the screen space point under the cursor at any zoom
|
|
||||||
camera.Target = mouseWorldPos
|
|
||||||
|
|
||||||
// Zoom increment
|
|
||||||
const zoomIncrement float32 = 0.125
|
|
||||||
|
|
||||||
camera.Zoom += (wheel * zoomIncrement)
|
|
||||||
if camera.Zoom < zoomIncrement {
|
|
||||||
camera.Zoom = zoomIncrement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
|
|
||||||
rl.BeginMode2D(camera)
|
|
||||||
|
|
||||||
// Draw the 3d grid, rotated 90 degrees and centered around 0,0
|
|
||||||
// just so we have something in the XY plane
|
|
||||||
rl.PushMatrix()
|
|
||||||
rl.Translatef(0, 25*50, 0)
|
|
||||||
rl.Rotatef(90, 1, 0, 0)
|
|
||||||
rl.DrawGrid(100, 50)
|
|
||||||
rl.PopMatrix()
|
|
||||||
|
|
||||||
// Draw a reference circle
|
|
||||||
rl.DrawCircle(100, 100, 50, rl.Yellow)
|
|
||||||
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.DrawText("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, rl.White)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
|
@ -1,261 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
gravity = 400
|
|
||||||
playerJumpSpeed = 350.0
|
|
||||||
playerHORSpeed = 200.0
|
|
||||||
)
|
|
||||||
|
|
||||||
type Player struct {
|
|
||||||
position rl.Vector2
|
|
||||||
speed float32
|
|
||||||
canJump bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type EnvironmentItem struct {
|
|
||||||
rect rl.Rectangle
|
|
||||||
blocking bool
|
|
||||||
color rl.Color
|
|
||||||
}
|
|
||||||
|
|
||||||
type cameraUpdater func(*rl.Camera2D, *Player, []EnvironmentItem, float32)
|
|
||||||
|
|
||||||
// These 3 variables are used only for camera 4,
|
|
||||||
// but they need to be declared on module level
|
|
||||||
// for camera 4 to work (static in C)
|
|
||||||
var eveningOut = false
|
|
||||||
var evenOutSpeed float32 = 700
|
|
||||||
var evenOutTarget float32 = 0
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera platformer")
|
|
||||||
|
|
||||||
player := Player{
|
|
||||||
position: rl.NewVector2(400, 280),
|
|
||||||
speed: 0,
|
|
||||||
canJump: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
envItems := []EnvironmentItem{
|
|
||||||
{rect: rl.Rectangle{Width: 1000, Height: 400}, blocking: false, color: rl.LightGray},
|
|
||||||
{rect: rl.Rectangle{Y: 400, Width: 1000, Height: 200}, blocking: true, color: rl.Gray},
|
|
||||||
{rect: rl.Rectangle{X: 300, Y: 200, Width: 400, Height: 10}, blocking: true, color: rl.Gray},
|
|
||||||
{rect: rl.Rectangle{X: 250, Y: 300, Width: 100, Height: 10}, blocking: true, color: rl.Gray},
|
|
||||||
{rect: rl.Rectangle{X: 650, Y: 300, Width: 100, Height: 10}, blocking: true, color: rl.Gray},
|
|
||||||
}
|
|
||||||
|
|
||||||
camera := rl.Camera2D{
|
|
||||||
Offset: rl.Vector2{X: screenWidth / 2, Y: screenHeight / 2},
|
|
||||||
Target: player.position,
|
|
||||||
Rotation: 0,
|
|
||||||
Zoom: 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraUpdaters := []cameraUpdater{
|
|
||||||
updateCameraCenter,
|
|
||||||
updateCameraCenterInsideMap,
|
|
||||||
updateCameraCenterSmoothFollow,
|
|
||||||
updateCameraEvenOutOnLanding,
|
|
||||||
updateCameraPlayerBoundsPush,
|
|
||||||
}
|
|
||||||
cameraDescriptions := []string{
|
|
||||||
"1. Follow player center",
|
|
||||||
"2. Follow player center, but clamp to map edges",
|
|
||||||
"3. Follow player center; smoothed",
|
|
||||||
"4. Follow player center horizontally; update player center vertically after landing",
|
|
||||||
"5. Player push camera on getting too close to screen edge",
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraOption := 0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
deltaTime := rl.GetFrameTime()
|
|
||||||
|
|
||||||
updatePlayer(&player, envItems, deltaTime)
|
|
||||||
|
|
||||||
camera.Zoom += rl.GetMouseWheelMove() * 0.05
|
|
||||||
|
|
||||||
camera.Zoom = clamp(camera.Zoom, 0.25, 3)
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyC) {
|
|
||||||
cameraOption = (cameraOption + 1) % len(cameraUpdaters)
|
|
||||||
}
|
|
||||||
// Call update camera function by its pointer
|
|
||||||
cameraUpdaters[cameraOption](&camera, &player, envItems, deltaTime)
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode2D(camera)
|
|
||||||
|
|
||||||
for _, item := range envItems {
|
|
||||||
rl.DrawRectangleRec(item.rect, item.color)
|
|
||||||
}
|
|
||||||
|
|
||||||
playerRect := rl.Rectangle{
|
|
||||||
X: player.position.X - 20,
|
|
||||||
Y: player.position.Y - 40,
|
|
||||||
Width: 40,
|
|
||||||
Height: 40,
|
|
||||||
}
|
|
||||||
rl.DrawRectangleRec(playerRect, rl.Red)
|
|
||||||
rl.DrawCircleV(player.position, 5, rl.Gold)
|
|
||||||
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.DrawText("Controls:", 20, 20, 10, rl.Black)
|
|
||||||
rl.DrawText(" - Right/Left to move", 40, 40, 10, rl.DarkGray)
|
|
||||||
rl.DrawText(" - Space to jump", 40, 60, 10, rl.DarkGray)
|
|
||||||
rl.DrawText(" - Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, rl.DarkGray)
|
|
||||||
rl.DrawText(" - C to change camera mode", 20, 100, 10, rl.Black)
|
|
||||||
rl.DrawText("Current Camera Mode:", 20, 120, 10, rl.DarkGray)
|
|
||||||
rl.DrawText(cameraDescriptions[cameraOption], 40, 140, 10, rl.DarkGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
||||||
|
|
||||||
func updatePlayer(player *Player, envItems []EnvironmentItem, delta float32) {
|
|
||||||
if rl.IsKeyDown(rl.KeyLeft) {
|
|
||||||
player.position.X -= playerHORSpeed * delta
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyRight) {
|
|
||||||
player.position.X += playerHORSpeed * delta
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeySpace) && player.canJump {
|
|
||||||
player.speed = -playerJumpSpeed
|
|
||||||
player.canJump = false
|
|
||||||
}
|
|
||||||
|
|
||||||
hitObstacle := false
|
|
||||||
for _, item := range envItems {
|
|
||||||
if item.blocking &&
|
|
||||||
item.rect.X <= player.position.X && item.rect.X+item.rect.Width >= player.position.X &&
|
|
||||||
item.rect.Y >= player.position.Y && item.rect.Y <= player.position.Y+player.speed*delta {
|
|
||||||
hitObstacle = true
|
|
||||||
player.speed = 0
|
|
||||||
player.position.Y = item.rect.Y
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hitObstacle {
|
|
||||||
player.position.Y += player.speed * delta
|
|
||||||
player.speed += gravity * delta
|
|
||||||
player.canJump = false
|
|
||||||
} else {
|
|
||||||
player.canJump = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateCameraCenter(camera *rl.Camera2D, player *Player, _ []EnvironmentItem, _ float32) {
|
|
||||||
camera.Offset = rl.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
|
|
||||||
camera.Target = player.position
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateCameraCenterInsideMap(camera *rl.Camera2D, player *Player, envItems []EnvironmentItem, _ float32) {
|
|
||||||
camera.Offset = rl.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
|
|
||||||
camera.Target = player.position
|
|
||||||
|
|
||||||
var minX, minY, maxX, maxY float32 = 1000, 1000, -1000, -10000
|
|
||||||
|
|
||||||
for _, item := range envItems {
|
|
||||||
minX = min(item.rect.X, minX)
|
|
||||||
maxX = max(item.rect.X+item.rect.Width, maxX)
|
|
||||||
minY = min(item.rect.Y, minY)
|
|
||||||
maxY = max(item.rect.Y+item.rect.Height, maxY)
|
|
||||||
}
|
|
||||||
|
|
||||||
maxV := rl.GetWorldToScreen2D(rl.Vector2{X: maxX, Y: maxY}, *camera)
|
|
||||||
minV := rl.GetWorldToScreen2D(rl.Vector2{X: minX, Y: minY}, *camera)
|
|
||||||
|
|
||||||
if maxV.X < screenWidth {
|
|
||||||
camera.Offset.X = screenWidth - (maxV.X - screenWidth/2)
|
|
||||||
}
|
|
||||||
if maxV.Y < screenHeight {
|
|
||||||
camera.Offset.Y = screenHeight - (maxV.Y - screenHeight/2)
|
|
||||||
}
|
|
||||||
if minV.X > 0 {
|
|
||||||
camera.Offset.X = screenWidth/2 - minV.X
|
|
||||||
}
|
|
||||||
if minV.Y > 0 {
|
|
||||||
camera.Offset.Y = screenHeight/2 - minV.Y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateCameraCenterSmoothFollow(camera *rl.Camera2D, player *Player, _ []EnvironmentItem, delta float32) {
|
|
||||||
var minSpeed, minEffectLength, fractionSpeed float32 = 30.0, 10.0, 0.8
|
|
||||||
|
|
||||||
camera.Offset = rl.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
|
|
||||||
diff := rl.Vector2Subtract(player.position, camera.Target)
|
|
||||||
length := rl.Vector2Length(diff)
|
|
||||||
|
|
||||||
if length > minEffectLength {
|
|
||||||
speed := max(fractionSpeed*length, minSpeed)
|
|
||||||
camera.Target = rl.Vector2Add(camera.Target, rl.Vector2Scale(diff, speed*delta/length))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateCameraEvenOutOnLanding(camera *rl.Camera2D, player *Player, _ []EnvironmentItem, delta float32) {
|
|
||||||
camera.Offset = rl.Vector2{X: screenWidth / 2, Y: screenHeight / 2}
|
|
||||||
camera.Target.X = player.position.X
|
|
||||||
|
|
||||||
if eveningOut {
|
|
||||||
if evenOutTarget > camera.Target.Y {
|
|
||||||
camera.Target.Y += evenOutSpeed * delta
|
|
||||||
if camera.Target.Y > evenOutTarget {
|
|
||||||
camera.Target.Y = evenOutTarget
|
|
||||||
eveningOut = false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
camera.Target.Y -= evenOutSpeed * delta
|
|
||||||
if camera.Target.Y < evenOutTarget {
|
|
||||||
camera.Target.Y = evenOutTarget
|
|
||||||
eveningOut = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if player.canJump && player.speed == 0 && player.position.Y != camera.Target.Y {
|
|
||||||
eveningOut = true
|
|
||||||
evenOutTarget = player.position.Y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateCameraPlayerBoundsPush(camera *rl.Camera2D, player *Player, _ []EnvironmentItem, _ float32) {
|
|
||||||
bbox := rl.Vector2{X: 0.2, Y: 0.2}
|
|
||||||
|
|
||||||
bboxWorldMin := rl.GetScreenToWorld2D(rl.Vector2{X: (1 - bbox.X) * 0.5 * screenWidth, Y: (1 - bbox.Y) * 0.5 * screenHeight}, *camera)
|
|
||||||
bboxWorldMax := rl.GetScreenToWorld2D(rl.Vector2{X: (1 + bbox.X) * 0.5 * screenWidth, Y: (1 + bbox.Y) * 0.5 * screenHeight}, *camera)
|
|
||||||
camera.Offset = rl.Vector2{X: (1 - bbox.X) * 0.5 * screenWidth, Y: (1 - bbox.Y) * 0.5 * screenHeight}
|
|
||||||
|
|
||||||
if player.position.X < bboxWorldMin.X {
|
|
||||||
camera.Target.X = player.position.X
|
|
||||||
}
|
|
||||||
if player.position.Y < bboxWorldMin.Y {
|
|
||||||
camera.Target.Y = player.position.Y
|
|
||||||
}
|
|
||||||
if player.position.X > bboxWorldMax.X {
|
|
||||||
camera.Target.X = bboxWorldMin.X + (player.position.X - bboxWorldMax.X)
|
|
||||||
}
|
|
||||||
if player.position.Y > bboxWorldMax.Y {
|
|
||||||
camera.Target.Y = bboxWorldMin.Y + (player.position.Y - bboxWorldMax.Y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func clamp(zoom float32, min float32, max float32) float32 {
|
|
||||||
if zoom < min {
|
|
||||||
return min
|
|
||||||
}
|
|
||||||
if zoom > max {
|
|
||||||
return max
|
|
||||||
}
|
|
||||||
return zoom
|
|
||||||
}
|
|
|
@ -1,128 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
screenW = int32(800)
|
|
||||||
screenH = int32(440)
|
|
||||||
playerSize = float32(40)
|
|
||||||
cam1, cam2 rl.Camera2D
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
rl.InitWindow(screenW, screenH, "raylib [core] example - 2d camera split screen")
|
|
||||||
|
|
||||||
player1 := rl.NewRectangle(200, 200, playerSize, playerSize)
|
|
||||||
player2 := rl.NewRectangle(250, 200, playerSize, playerSize)
|
|
||||||
|
|
||||||
cam1.Target = rl.NewVector2(player1.X, player1.Y)
|
|
||||||
cam1.Offset = rl.NewVector2(200, 200)
|
|
||||||
cam1.Rotation = 0
|
|
||||||
cam1.Zoom = 1
|
|
||||||
|
|
||||||
cam2 = cam1
|
|
||||||
cam2.Target = rl.NewVector2(player2.X, player2.Y)
|
|
||||||
|
|
||||||
screenCam1 := rl.LoadRenderTexture(screenW/2, screenH)
|
|
||||||
screenCam2 := rl.LoadRenderTexture(screenW/2, screenH)
|
|
||||||
|
|
||||||
splitScreenRec := rl.NewRectangle(0, 0, float32(screenCam1.Texture.Width), -float32(screenCam1.Texture.Height))
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyS) {
|
|
||||||
player1.Y += 3
|
|
||||||
} else if rl.IsKeyDown(rl.KeyW) {
|
|
||||||
player1.Y -= 3
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyD) {
|
|
||||||
player1.X += 3
|
|
||||||
} else if rl.IsKeyDown(rl.KeyA) {
|
|
||||||
player1.X -= 3
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyUp) {
|
|
||||||
player2.Y -= 3
|
|
||||||
} else if rl.IsKeyDown(rl.KeyDown) {
|
|
||||||
player2.Y += 3
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyRight) {
|
|
||||||
player2.X += 3
|
|
||||||
} else if rl.IsKeyDown(rl.KeyLeft) {
|
|
||||||
player2.X -= 3
|
|
||||||
}
|
|
||||||
|
|
||||||
cam1.Target = rl.NewVector2(player1.X, player1.Y)
|
|
||||||
cam2.Target = rl.NewVector2(player2.X, player2.Y)
|
|
||||||
|
|
||||||
rl.BeginTextureMode(screenCam1)
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode2D(cam1)
|
|
||||||
|
|
||||||
for i := 0; i < int(screenW/int32(playerSize))+1; i++ {
|
|
||||||
rl.DrawLineV(rl.NewVector2(playerSize*float32(i), 0), rl.NewVector2(playerSize*float32(i), float32(screenH)), rl.LightGray)
|
|
||||||
}
|
|
||||||
for i := 0; i < int(screenH/int32(playerSize))+1; i++ {
|
|
||||||
rl.DrawLineV(rl.NewVector2(0, playerSize*float32(i)), rl.NewVector2(float32(screenW), playerSize*float32(i)), rl.LightGray)
|
|
||||||
}
|
|
||||||
for i := 0; i < int(screenW/int32(playerSize)); i++ {
|
|
||||||
for j := 0; j < int(screenH/int32(playerSize)); j++ {
|
|
||||||
rl.DrawText("["+fmt.Sprint(i)+","+fmt.Sprint(j)+"]", 10+int32(playerSize*float32(i)), 15+int32(playerSize*float32(j)), 10, rl.LightGray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangleRec(player1, rl.Red)
|
|
||||||
rl.DrawRectangleRec(player2, rl.Blue)
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.DrawRectangle(0, 0, screenW/2, 30, rl.Fade(rl.RayWhite, 0.6))
|
|
||||||
rl.DrawText("PLAYER 1 WASD KEYS", 10, 10, 10, rl.Maroon)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
rl.BeginTextureMode(screenCam2)
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode2D(cam2)
|
|
||||||
|
|
||||||
for i := 0; i < int(screenW/int32(playerSize))+1; i++ {
|
|
||||||
rl.DrawLineV(rl.NewVector2(playerSize*float32(i), 0), rl.NewVector2(playerSize*float32(i), float32(screenH)), rl.LightGray)
|
|
||||||
}
|
|
||||||
for i := 0; i < int(screenH/int32(playerSize))+1; i++ {
|
|
||||||
rl.DrawLineV(rl.NewVector2(0, playerSize*float32(i)), rl.NewVector2(float32(screenW), playerSize*float32(i)), rl.LightGray)
|
|
||||||
}
|
|
||||||
for i := 0; i < int(screenW/int32(playerSize)); i++ {
|
|
||||||
for j := 0; j < int(screenH/int32(playerSize)); j++ {
|
|
||||||
rl.DrawText("["+fmt.Sprint(i)+","+fmt.Sprint(j)+"]", 10+int32(playerSize*float32(i)), 15+int32(playerSize*float32(j)), 10, rl.LightGray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangleRec(player1, rl.Red)
|
|
||||||
rl.DrawRectangleRec(player2, rl.Blue)
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.DrawRectangle(0, 0, screenW/2, 30, rl.Fade(rl.RayWhite, 0.6))
|
|
||||||
rl.DrawText("PLAYER 2 ARROW KEYS", 10, 10, 10, rl.Maroon)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
|
|
||||||
rl.DrawTextureRec(screenCam1.Texture, splitScreenRec, rl.NewVector2(0, 0), rl.White)
|
|
||||||
rl.DrawTextureRec(screenCam2.Texture, splitScreenRec, rl.NewVector2(float32(screenW/2), 0), rl.White)
|
|
||||||
rl.DrawRectangle((screenW/2)-2, 0, 4, screenH, rl.LightGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadRenderTexture(screenCam1)
|
|
||||||
rl.UnloadRenderTexture(screenCam2)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,216 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const colorCount = 23
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
const screenWidth, screenHeight int32 = 800, 450
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raypaint")
|
|
||||||
|
|
||||||
// Colors to choose from
|
|
||||||
var colors = [colorCount]rl.Color{
|
|
||||||
rl.RayWhite, rl.Yellow, rl.Gold, rl.Orange, rl.Pink, rl.Red, rl.Maroon, rl.Green, rl.Lime, rl.DarkGreen,
|
|
||||||
rl.SkyBlue, rl.Blue, rl.DarkBlue, rl.Purple, rl.Violet, rl.DarkPurple, rl.Beige, rl.Brown, rl.DarkBrown,
|
|
||||||
rl.LightGray, rl.Gray, rl.DarkGray, rl.Black,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define colorsRecs data (for every rectangle)
|
|
||||||
var colorRecs = [colorCount]rl.Rectangle{}
|
|
||||||
|
|
||||||
for i := 0; i < colorCount; i++ {
|
|
||||||
colorRecs[i].X = float32(10 + 30*i + 2*i)
|
|
||||||
colorRecs[i].Y = 10
|
|
||||||
colorRecs[i].Width = 30
|
|
||||||
colorRecs[i].Height = 30
|
|
||||||
}
|
|
||||||
|
|
||||||
colorSelected := 0
|
|
||||||
colorSelectedPrev := colorSelected
|
|
||||||
colorMouseHover := 0
|
|
||||||
brushSize := 20
|
|
||||||
|
|
||||||
var btnSaveRec = rl.Rectangle{750, 10, 40, 30}
|
|
||||||
btnSaveMouseHover := false
|
|
||||||
showSaveMessage := false
|
|
||||||
saveMessageCounter := 0
|
|
||||||
|
|
||||||
checkSaveHover := func() rl.Color {
|
|
||||||
if btnSaveMouseHover {
|
|
||||||
return rl.Red
|
|
||||||
}
|
|
||||||
return rl.Black
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a RenderTexture2D to use as a canvas
|
|
||||||
var target rl.RenderTexture2D = rl.LoadRenderTexture(screenWidth, screenHeight)
|
|
||||||
|
|
||||||
// Clear render texture before entering the game loop
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
rl.ClearBackground(colors[0])
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(120)
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
mousePos := rl.GetMousePosition()
|
|
||||||
|
|
||||||
// Move between colors with keys
|
|
||||||
if rl.IsKeyPressed(rl.KeyRight) {
|
|
||||||
colorSelected++
|
|
||||||
} else if rl.IsKeyPressed(rl.KeyLeft) {
|
|
||||||
colorSelected--
|
|
||||||
}
|
|
||||||
|
|
||||||
if colorSelected >= colorCount {
|
|
||||||
colorSelected = colorCount - 1
|
|
||||||
} else if colorSelected < 0 {
|
|
||||||
colorSelected = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Choose color with mouse
|
|
||||||
for i := 0; i < colorCount; i++ {
|
|
||||||
if rl.CheckCollisionPointRec(mousePos, colorRecs[i]) {
|
|
||||||
colorMouseHover = i
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
colorMouseHover = -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if colorMouseHover >= 0 && rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
|
||||||
colorSelected = colorMouseHover
|
|
||||||
colorSelectedPrev = colorSelected
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change brush size
|
|
||||||
brushSize += int(rl.GetMouseWheelMove() * 5)
|
|
||||||
if brushSize < 2 {
|
|
||||||
brushSize = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
if brushSize > 50 {
|
|
||||||
brushSize = 50
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyC) {
|
|
||||||
// Clear render texture to clear color
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
rl.ClearBackground(colors[0])
|
|
||||||
rl.EndTextureMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseLeftButton) || rl.GetGestureDetected() == rl.GestureDrag {
|
|
||||||
// Clear render texture to clear color
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
|
|
||||||
if mousePos.Y > 50 {
|
|
||||||
rl.DrawCircle(int32(mousePos.X), int32(mousePos.Y), float32(brushSize), colors[colorSelected])
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndTextureMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
|
||||||
colorSelected = 0
|
|
||||||
|
|
||||||
// Erase circle from render texture
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
|
|
||||||
if mousePos.Y > 50 {
|
|
||||||
rl.DrawCircle(int32(mousePos.X), int32(mousePos.Y), float32(brushSize), colors[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndTextureMode()
|
|
||||||
} else {
|
|
||||||
colorSelected = colorSelectedPrev
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.CheckCollisionPointRec(mousePos, btnSaveRec) {
|
|
||||||
btnSaveMouseHover = true
|
|
||||||
} else {
|
|
||||||
btnSaveMouseHover = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if btnSaveMouseHover && rl.IsMouseButtonReleased(rl.MouseLeftButton) || rl.IsKeyPressed(rl.KeyS) {
|
|
||||||
image := rl.LoadImageFromTexture(target.Texture)
|
|
||||||
rl.ImageFlipVertical(*&image)
|
|
||||||
rl.ExportImage(*image, "export.png")
|
|
||||||
rl.UnloadImage(image)
|
|
||||||
showSaveMessage = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if showSaveMessage {
|
|
||||||
// On saving, show a full screen message for 2 seconds
|
|
||||||
saveMessageCounter++
|
|
||||||
if saveMessageCounter > 240 {
|
|
||||||
showSaveMessage = false
|
|
||||||
saveMessageCounter = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
// NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
|
|
||||||
rl.DrawTextureRec(target.Texture, rl.Rectangle{0, 0, float32(target.Texture.Width), float32(-target.Texture.Height)}, rl.Vector2{0, 0}, rl.White)
|
|
||||||
|
|
||||||
if mousePos.Y > 50 {
|
|
||||||
if rl.IsMouseButtonDown(rl.MouseRightButton) {
|
|
||||||
rl.DrawCircleLines(int32(mousePos.X), int32(mousePos.Y), float32(brushSize), rl.Gray)
|
|
||||||
} else {
|
|
||||||
rl.DrawCircle(rl.GetMouseX(), rl.GetMouseY(), float32(brushSize), colors[colorSelected])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw top panel
|
|
||||||
rl.DrawRectangle(0, 0, int32(rl.GetScreenWidth()), 50, rl.RayWhite)
|
|
||||||
rl.DrawLine(0, 50, int32(rl.GetScreenWidth()), 50, rl.LightGray)
|
|
||||||
|
|
||||||
// Draw color selection rectangles
|
|
||||||
for i := 0; i < colorCount; i++ {
|
|
||||||
rl.DrawRectangleRec(colorRecs[i], colors[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangleLines(10, 10, 30, 30, rl.LightGray)
|
|
||||||
|
|
||||||
if colorMouseHover >= 0 {
|
|
||||||
rl.DrawRectangleRec(colorRecs[colorMouseHover], rl.Fade(rl.White, 0.0))
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangleLinesEx(rl.Rectangle{
|
|
||||||
colorRecs[colorSelected].X - 2, colorRecs[colorSelected].Y - 2, colorRecs[colorSelected].Width + 4, colorRecs[colorSelected].Height + 4,
|
|
||||||
}, 2, rl.Black)
|
|
||||||
|
|
||||||
// Draw save image button
|
|
||||||
rl.DrawRectangleLinesEx(btnSaveRec, 2, checkSaveHover())
|
|
||||||
rl.DrawText("SAVE!", 755, 20, 10, checkSaveHover())
|
|
||||||
|
|
||||||
if showSaveMessage {
|
|
||||||
rl.DrawRectangle(0, 0, int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()), rl.Fade(rl.RayWhite, 0.8))
|
|
||||||
rl.DrawRectangle(0, 150, int32(rl.GetScreenWidth()), 80, rl.Black)
|
|
||||||
rl.DrawText("IMAGE SAVED: export.png", 150, 180, 20, rl.RayWhite)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.UnloadRenderTexture(target)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,43 +1,22 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxColumns = 20
|
maxColumns = 20
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
False = 0
|
|
||||||
True = 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var camModes = map[rl.CameraMode]string{
|
|
||||||
rl.CameraFree: "FREE",
|
|
||||||
rl.CameraOrbital: "ORBITAL",
|
|
||||||
rl.CameraFirstPerson: "FIRST PERSON",
|
|
||||||
rl.CameraThirdPerson: "THIRD PERSON",
|
|
||||||
}
|
|
||||||
|
|
||||||
var camProjections = map[rl.CameraProjection]string{
|
|
||||||
rl.CameraPerspective: "PERSPECTIVE",
|
|
||||||
rl.CameraOrthographic: "ORTHOGRAPHIC",
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person")
|
rl.InitWindow(800, 450, "raylib [core] example - 3d camera first person")
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (position, target, up vector)
|
|
||||||
camera := rl.Camera3D{}
|
camera := rl.Camera3D{}
|
||||||
camera.Position = rl.NewVector3(0.0, 2.0, 4.0) // Camera position
|
camera.Position = rl.NewVector3(4.0, 2.0, 4.0)
|
||||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
camera.Target = rl.NewVector3(0.0, 1.8, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 60.0 // Camera field-of-view Y
|
camera.Fovy = 60.0
|
||||||
camera.Projection = rl.CameraPerspective // Camera projection type
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cameraMode := rl.CameraFirstPerson
|
|
||||||
|
|
||||||
// Generates some random columns
|
// Generates some random columns
|
||||||
heights := make([]float32, maxColumns)
|
heights := make([]float32, maxColumns)
|
||||||
|
@ -45,81 +24,17 @@ func main() {
|
||||||
colors := make([]rl.Color, maxColumns)
|
colors := make([]rl.Color, maxColumns)
|
||||||
|
|
||||||
for i := 0; i < maxColumns; i++ {
|
for i := 0; i < maxColumns; i++ {
|
||||||
heights[i] = rndF(1, 12)
|
heights[i] = float32(rl.GetRandomValue(1, 12))
|
||||||
positions[i] = rl.NewVector3(rndF(-15, 15), heights[i]/2, rndF(-15, 15))
|
positions[i] = rl.NewVector3(float32(rl.GetRandomValue(-15, 15)), heights[i]/2, float32(rl.GetRandomValue(-15, 15)))
|
||||||
colors[i] = rl.NewColor(rndU(20, 255), rndU(10, 55), 30, 255)
|
colors[i] = rl.NewColor(uint8(rl.GetRandomValue(20, 255)), uint8(rl.GetRandomValue(10, 55)), 30, 255)
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.DisableCursor() // Limit cursor to relative movement inside the window
|
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set a first person camera mode
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
// Main game loop
|
rl.SetTargetFPS(60)
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Switch camera mode
|
|
||||||
if rl.IsKeyPressed(rl.KeyOne) {
|
|
||||||
cameraMode = rl.CameraFree
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Reset roll
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyTwo) {
|
|
||||||
cameraMode = rl.CameraFirstPerson
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Reset roll
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyThree) {
|
|
||||||
cameraMode = rl.CameraThirdPerson
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Reset roll
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyFour) {
|
|
||||||
cameraMode = rl.CameraOrbital
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Reset roll
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch camera projection
|
for !rl.WindowShouldClose() {
|
||||||
if rl.IsKeyPressed(rl.KeyP) {
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
cameraMode = rl.CameraThirdPerson
|
|
||||||
if camera.Projection == rl.CameraPerspective {
|
|
||||||
// Create isometric view
|
|
||||||
// Note: The target distance is related to the render distance in the orthographic projection
|
|
||||||
camera.Position = rl.NewVector3(0.0, 2.0, -100.0)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Projection = rl.CameraOrthographic
|
|
||||||
camera.Fovy = 20.0 // near plane width in CAMERA_ORTHOGRAPHIC
|
|
||||||
rl.CameraYaw(&camera, -135*rl.Deg2rad, True)
|
|
||||||
rl.CameraPitch(&camera, -45*rl.Deg2rad, True, True, False)
|
|
||||||
} else if camera.Projection == rl.CameraOrthographic {
|
|
||||||
// Reset to default view
|
|
||||||
camera.Position = rl.NewVector3(0.0, 2.0, 10.0)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Projection = rl.CameraPerspective
|
|
||||||
camera.Fovy = 60.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update camera computes movement internally depending on the camera mode.
|
|
||||||
// Some default standard keyboard/mouse inputs are hardcoded to simplify use.
|
|
||||||
// For advance camera controls, it's recommended to compute camera movement manually.
|
|
||||||
rl.UpdateCamera(&camera, cameraMode) // Update camera
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Camera PRO usage example (EXPERIMENTAL)
|
|
||||||
// This new camera function allows custom movement/rotation values to be directly provided
|
|
||||||
// as input parameters, with this approach, rcamera module is internally independent of raylib inputs
|
|
||||||
UpdateCameraPro(&camera,
|
|
||||||
(Vector3){
|
|
||||||
(IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward
|
|
||||||
(IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f,
|
|
||||||
(IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left
|
|
||||||
(IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f,
|
|
||||||
0.0f // Move up-down
|
|
||||||
},
|
|
||||||
(Vector3){
|
|
||||||
GetMouseDelta().x*0.05f, // Rotation: yaw
|
|
||||||
GetMouseDelta().y*0.05f, // Rotation: pitch
|
|
||||||
0.0f // Rotation: roll
|
|
||||||
},
|
|
||||||
GetMouseWheelMove()*2.0f); // Move to target (zoom)
|
|
||||||
*/
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
|
@ -138,57 +53,17 @@ func main() {
|
||||||
rl.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, rl.Maroon)
|
rl.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, rl.Maroon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw player cube
|
|
||||||
if cameraMode == rl.CameraThirdPerson {
|
|
||||||
rl.DrawCube(camera.Target, 0.5, 0.5, 0.5, rl.Purple)
|
|
||||||
rl.DrawCubeWires(camera.Target, 0.5, 0.5, 0.5, rl.DarkPurple)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
rl.EndMode3D()
|
||||||
|
|
||||||
// Draw info boxes
|
rl.DrawRectangle(10, 10, 220, 70, rl.Fade(rl.SkyBlue, 0.5))
|
||||||
rl.DrawRectangle(5, 5, 330, 100, rl.Fade(rl.SkyBlue, 0.5))
|
rl.DrawRectangleLines(10, 10, 220, 70, rl.Blue)
|
||||||
rl.DrawRectangleLines(5, 5, 330, 100, rl.Blue)
|
|
||||||
|
|
||||||
rl.DrawText("Camera controls:", 15, 15, 10, rl.Black)
|
rl.DrawText("First person camera default controls:", 20, 20, 10, rl.Black)
|
||||||
rl.DrawText("- Move keys: W, A, S, D, Space, Left-Ctrl", 15, 30, 10, rl.Black)
|
rl.DrawText("- Move with keys: W, A, S, D", 40, 40, 10, rl.DarkGray)
|
||||||
rl.DrawText("- Look around: arrow keys or mouse", 15, 45, 10, rl.Black)
|
rl.DrawText("- Mouse move to look around", 40, 60, 10, rl.DarkGray)
|
||||||
rl.DrawText("- Camera mode keys: 1,2,3,4", 15, 60, 10, rl.Black)
|
|
||||||
rl.DrawText("- Zoom keys: num-plus, num-minus or mouse scroll", 15, 75, 10, rl.Black)
|
|
||||||
rl.DrawText("- Camera projection key: P", 15, 90, 10, rl.Black)
|
|
||||||
|
|
||||||
rl.DrawRectangle(600, 5, 195, 100, rl.Fade(rl.SkyBlue, 0.5))
|
|
||||||
rl.DrawRectangleLines(600, 5, 195, 100, rl.Blue)
|
|
||||||
|
|
||||||
rl.DrawText("Camera status:", 610, 15, 10, rl.Black)
|
|
||||||
rl.DrawText(s2T("Mode:", camModes[cameraMode]), 610, 30, 10, rl.Black)
|
|
||||||
rl.DrawText(s2T("Projection:", camProjections[camera.Projection]), 610, 45, 10, rl.Black)
|
|
||||||
rl.DrawText(s2T("Position:", v2T(camera.Position)), 610, 60, 10, rl.Black)
|
|
||||||
rl.DrawText(s2T("Target:", v2T(camera.Target)), 610, 75, 10, rl.Black)
|
|
||||||
rl.DrawText(s2T("Up:", v2T(camera.Up)), 610, 90, 10, rl.Black)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// rndU generates a random uint8 value between min and max
|
|
||||||
func rndU(min, max int32) uint8 {
|
|
||||||
return uint8(rl.GetRandomValue(min, max))
|
|
||||||
}
|
|
||||||
|
|
||||||
// rndF generates a random float32 value between min and max
|
|
||||||
func rndF(min, max int32) float32 {
|
|
||||||
return float32(rl.GetRandomValue(min, max))
|
|
||||||
}
|
|
||||||
|
|
||||||
// s2t generates a Status item string from a name and value
|
|
||||||
func s2T(name, value string) string {
|
|
||||||
return fmt.Sprintf(" - %s %s", name, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// v2T generates a string from a rl.Vector3
|
|
||||||
func v2T(v rl.Vector3) string {
|
|
||||||
return fmt.Sprintf("%6.3f, %6.3f, %6.3f", v.X, v.Y, v.Z)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -12,14 +12,16 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Projection = rl.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
rl.UpdateCamera(&camera, rl.CameraFree) // Update camera with free camera mode
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyZ) {
|
if rl.IsKeyDown(rl.KeyZ) {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
@ -44,6 +46,8 @@ func main() {
|
||||||
rl.DrawText("Free camera default controls:", 20, 20, 10, rl.Black)
|
rl.DrawText("Free camera default controls:", 20, 20, 10, rl.Black)
|
||||||
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DarkGray)
|
rl.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DarkGray)
|
||||||
rl.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DarkGray)
|
rl.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DarkGray)
|
||||||
|
rl.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, rl.DarkGray)
|
||||||
|
rl.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, rl.DarkGray)
|
||||||
rl.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, rl.DarkGray)
|
rl.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, rl.DarkGray)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
|
|
|
@ -1,127 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
screenW = int32(800)
|
|
||||||
screenH = int32(450)
|
|
||||||
cam1, cam2 rl.Camera3D
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
rl.InitWindow(screenW, screenH, "raylib [core] example - 3d camera split screen")
|
|
||||||
|
|
||||||
// Setup player 1 camera and screen
|
|
||||||
cam1.Fovy = 45
|
|
||||||
cam1.Up.Y = 1
|
|
||||||
cam1.Target.Y = 1
|
|
||||||
cam1.Position.Z = -3
|
|
||||||
cam1.Position.Y = 1
|
|
||||||
|
|
||||||
// Setup player two camera and screen
|
|
||||||
cam2.Fovy = 45
|
|
||||||
cam2.Up.Y = 1
|
|
||||||
cam2.Target.Y = 3
|
|
||||||
cam2.Position.X = -3
|
|
||||||
cam2.Position.Y = 3
|
|
||||||
|
|
||||||
screenCam1 := rl.LoadRenderTexture(screenW/2, screenH)
|
|
||||||
screenCam2 := rl.LoadRenderTexture(screenW/2, screenH)
|
|
||||||
|
|
||||||
splitScreenRec := rl.NewRectangle(0, 0, float32(screenCam1.Texture.Width), -float32(screenCam1.Texture.Height))
|
|
||||||
|
|
||||||
count := float32(5)
|
|
||||||
spacing := float32(4)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
// If anyone moves this frame, how far will they move based on the time
|
|
||||||
// since the last frame this moves things at 10 world units per second,
|
|
||||||
// regardless of the actual FPS
|
|
||||||
frameOffset := 10 * rl.GetFrameTime()
|
|
||||||
|
|
||||||
// Move Player1 forward and backwards (no turning)
|
|
||||||
if rl.IsKeyDown(rl.KeyW) {
|
|
||||||
cam1.Position.Z += frameOffset
|
|
||||||
cam1.Target.Z += frameOffset
|
|
||||||
} else if rl.IsKeyDown(rl.KeyS) {
|
|
||||||
cam1.Position.Z -= frameOffset
|
|
||||||
cam1.Target.Z -= frameOffset
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move Player2 forward and backwards (no turning)
|
|
||||||
if rl.IsKeyDown(rl.KeyUp) {
|
|
||||||
cam2.Position.X += frameOffset
|
|
||||||
cam2.Target.X += frameOffset
|
|
||||||
} else if rl.IsKeyDown(rl.KeyDown) {
|
|
||||||
cam2.Position.X -= frameOffset
|
|
||||||
cam2.Target.X -= frameOffset
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw Player1 view to the render texture
|
|
||||||
rl.BeginTextureMode(screenCam1)
|
|
||||||
rl.ClearBackground(rl.SkyBlue)
|
|
||||||
rl.BeginMode3D(cam1)
|
|
||||||
|
|
||||||
rl.DrawPlane(rl.Vector3Zero(), rl.NewVector2(50, 50), rl.Beige)
|
|
||||||
|
|
||||||
for x := -count * spacing; x <= count*spacing; x += spacing {
|
|
||||||
for z := -count * spacing; z <= count*spacing; z += spacing {
|
|
||||||
rl.DrawCube(rl.NewVector3(x-0.5, 1.5, z), 1, 1, 1, rl.Lime)
|
|
||||||
rl.DrawCube(rl.NewVector3(x-0.5, 0.5, z), 0.25, 1, 0.25, rl.Brown)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawCube(cam1.Position, 1, 1, 1, rl.Red)
|
|
||||||
rl.DrawCube(cam2.Position, 1, 1, 1, rl.Blue)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawRectangle(0, 0, screenW/2, 40, rl.Fade(rl.RayWhite, 0.8))
|
|
||||||
rl.DrawText("PLAYER1: W/S to move", 10, 10, 20, rl.Maroon)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
|
||||||
rl.BeginTextureMode(screenCam2)
|
|
||||||
rl.ClearBackground(rl.SkyBlue)
|
|
||||||
rl.BeginMode3D(cam2)
|
|
||||||
|
|
||||||
rl.DrawPlane(rl.Vector3Zero(), rl.NewVector2(50, 50), rl.Beige)
|
|
||||||
|
|
||||||
for x := -count * spacing; x <= count*spacing; x += spacing {
|
|
||||||
for z := -count * spacing; z <= count*spacing; z += spacing {
|
|
||||||
rl.DrawCube(rl.NewVector3(x, 1.5, z), 1, 1, 1, rl.Lime)
|
|
||||||
rl.DrawCube(rl.NewVector3(x, 0.5, z), 0.25, 1, 0.25, rl.Brown)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawCube(cam1.Position, 1, 1, 1, rl.Red)
|
|
||||||
rl.DrawCube(cam2.Position, 1, 1, 1, rl.Blue)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawRectangle(0, 0, screenW/2, 40, rl.Fade(rl.RayWhite, 0.8))
|
|
||||||
rl.DrawText("PLAYER2: UP/DOWN to move", 10, 10, 20, rl.Maroon)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
|
|
||||||
rl.DrawTextureRec(screenCam1.Texture, splitScreenRec, rl.NewVector2(0, 0), rl.White)
|
|
||||||
rl.DrawTextureRec(screenCam2.Texture, splitScreenRec, rl.NewVector2(float32(screenW/2), 0), rl.White)
|
|
||||||
rl.DrawRectangle((screenW/2)-2, 0, 4, screenH, rl.LightGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadRenderTexture(screenCam1)
|
|
||||||
rl.UnloadRenderTexture(screenCam2)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -12,7 +12,7 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Projection = rl.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -15,30 +15,29 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Projection = rl.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
cubePosition := rl.NewVector3(0.0, 1.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
cubeSize := rl.NewVector3(2.0, 2.0, 2.0)
|
cubeSize := rl.NewVector3(2.0, 2.0, 2.0)
|
||||||
|
|
||||||
var ray rl.Ray
|
var ray rl.Ray
|
||||||
var collision rl.RayCollision
|
|
||||||
|
collision := false
|
||||||
|
|
||||||
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
rl.UpdateCamera(&camera, rl.CameraFree) // Update camera with free camera mode
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||||
if !collision.Hit {
|
|
||||||
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
||||||
|
|
||||||
// Check collision between ray and box
|
// Check collision between ray and box
|
||||||
min := rl.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
min := rl.NewVector3(cubePosition.X-cubeSize.X/2, cubePosition.Y-cubeSize.Y/2, cubePosition.Z-cubeSize.Z/2)
|
||||||
max := rl.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
max := rl.NewVector3(cubePosition.X+cubeSize.X/2, cubePosition.Y+cubeSize.Y/2, cubePosition.Z+cubeSize.Z/2)
|
||||||
collision = rl.GetRayCollisionBox(ray, rl.NewBoundingBox(min, max))
|
collision = rl.CheckCollisionRayBox(ray, rl.NewBoundingBox(min, max))
|
||||||
} else {
|
|
||||||
collision.Hit = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
@ -47,7 +46,7 @@ func main() {
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
if collision.Hit {
|
if collision {
|
||||||
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Red)
|
rl.DrawCube(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Red)
|
||||||
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Maroon)
|
rl.DrawCubeWires(cubePosition, cubeSize.X, cubeSize.Y, cubeSize.Z, rl.Maroon)
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ func main() {
|
||||||
|
|
||||||
rl.DrawText("Try selecting the box with mouse!", 240, 10, 20, rl.DarkGray)
|
rl.DrawText("Try selecting the box with mouse!", 240, 10, 20, rl.DarkGray)
|
||||||
|
|
||||||
if collision.Hit {
|
if collision {
|
||||||
rl.DrawText("BOX SELECTED", (screenWidth-rl.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, rl.Green)
|
rl.DrawText("BOX SELECTED", (screenWidth-rl.MeasureText("BOX SELECTED", 30))/2, int32(float32(screenHeight)*0.1), 30, rl.Green)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "git.terah.dev/UnrealXR/raylib-go/raylib"
|
import "github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const screenW = int32(1280)
|
|
||||||
const screenH = int32(720)
|
|
||||||
|
|
||||||
type gameScreen int
|
|
||||||
|
|
||||||
const (
|
|
||||||
LOGO = iota
|
|
||||||
TITLE
|
|
||||||
GAMEPLAY
|
|
||||||
ENDING
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
rl.InitWindow(screenW, screenH, "raylib [core] example - basic screen manager")
|
|
||||||
|
|
||||||
var currentScreen gameScreen
|
|
||||||
currentScreen = LOGO
|
|
||||||
frames := 0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
switch currentScreen {
|
|
||||||
case LOGO:
|
|
||||||
frames++
|
|
||||||
if frames > 240 {
|
|
||||||
currentScreen = TITLE
|
|
||||||
}
|
|
||||||
case TITLE:
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
|
||||||
currentScreen = GAMEPLAY
|
|
||||||
}
|
|
||||||
case GAMEPLAY:
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
|
||||||
currentScreen = ENDING
|
|
||||||
}
|
|
||||||
case ENDING:
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
|
||||||
currentScreen = LOGO
|
|
||||||
frames = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
rec := rl.NewRectangle(0, 0, float32(screenW), float32(screenH))
|
|
||||||
switch currentScreen {
|
|
||||||
case LOGO:
|
|
||||||
txt := "YOUR LOGO GOES HERE"
|
|
||||||
txtlen := rl.MeasureText(txt, 50)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-3, screenH/2-50+3, 50, rl.Magenta)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-1, screenH/2-50+1, 50, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2-50, 50, rl.White)
|
|
||||||
txt = "this message disappears in " + fmt.Sprint(240-frames) + " frames"
|
|
||||||
txtlen = rl.MeasureText(txt, 30)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-3, screenH/2+3, 30, rl.Magenta)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-1, screenH/2+1, 30, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2, 30, rl.White)
|
|
||||||
case TITLE:
|
|
||||||
rl.DrawRectangleRec(rec, rl.DarkGreen)
|
|
||||||
txt := "AN AMAZING TITLE GOES HERE"
|
|
||||||
txtlen := rl.MeasureText(txt, 50)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2-50+2, 50, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2-50, 50, rl.White)
|
|
||||||
txt = "press enter to move to next screen"
|
|
||||||
txtlen = rl.MeasureText(txt, 30)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2+2, 30, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2, 30, rl.White)
|
|
||||||
case GAMEPLAY:
|
|
||||||
rl.DrawRectangleRec(rec, rl.DarkPurple)
|
|
||||||
txt := "FUN GAMEPLAY GOES HERE"
|
|
||||||
txtlen := rl.MeasureText(txt, 50)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2-50+2, 50, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2-50, 50, rl.White)
|
|
||||||
txt = "press enter to move to next screen"
|
|
||||||
txtlen = rl.MeasureText(txt, 30)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2+2, 30, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2, 30, rl.White)
|
|
||||||
case ENDING:
|
|
||||||
rl.DrawRectangleRec(rec, rl.DarkBlue)
|
|
||||||
txt := "A DRAMATIC ENDING GOES HERE"
|
|
||||||
txtlen := rl.MeasureText(txt, 50)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2-50+2, 50, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2-50, 50, rl.White)
|
|
||||||
txt = "press enter to move to next screen"
|
|
||||||
txtlen = rl.MeasureText(txt, 30)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2-2, screenH/2+2, 30, rl.Black)
|
|
||||||
rl.DrawText(txt, screenW/2-txtlen/2, screenH/2, 30, rl.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
||||||
|
|
||||||
|
|
|
@ -1,144 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - split screen
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 3.7, last time updated with raylib 4.0
|
|
||||||
*
|
|
||||||
* Example contributed by Jeffery Myers (@JeffM2501) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021-2022 Jeffery Myers (@JeffM2501)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
var cameraPlayer1 rl.Camera
|
|
||||||
var cameraPlayer2 rl.Camera
|
|
||||||
|
|
||||||
// Scene drawing
|
|
||||||
func DrawScene() {
|
|
||||||
count := float32(5.0)
|
|
||||||
spacing := float32(4.0)
|
|
||||||
|
|
||||||
// Grid of cube trees on a plane to make a "world"
|
|
||||||
rl.DrawPlane(rl.Vector3{0, 0, 0}, rl.Vector2{50, 50}, rl.Beige) // Simple world plane
|
|
||||||
|
|
||||||
for x := -float32(count * spacing); x <= count*spacing; x += spacing {
|
|
||||||
for z := -float32(count * spacing); z <= count*spacing; z += spacing {
|
|
||||||
rl.DrawCube(rl.Vector3{x, 1.5, z}, 1, 1, 1, rl.Lime)
|
|
||||||
rl.DrawCube(rl.Vector3{x, 0.5, z}, 0.25, 1, 0.25, rl.Brown)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw a cube at each player's position
|
|
||||||
rl.DrawCube(cameraPlayer1.Position, 1, 1, 1, rl.Red)
|
|
||||||
rl.DrawCube(cameraPlayer2.Position, 1, 1, 1, rl.Blue)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - split screen")
|
|
||||||
|
|
||||||
// Setup player 1 camera and screen
|
|
||||||
cameraPlayer1.Fovy = 45.0
|
|
||||||
cameraPlayer1.Up.Y = 1.0
|
|
||||||
cameraPlayer1.Target.Y = 1.0
|
|
||||||
cameraPlayer1.Position.Z = -3.0
|
|
||||||
cameraPlayer1.Position.Y = 1.0
|
|
||||||
|
|
||||||
screenPlayer1 := rl.LoadRenderTexture(screenWidth/2, screenHeight)
|
|
||||||
|
|
||||||
// Setup player two camera and screen
|
|
||||||
cameraPlayer2.Fovy = 45.0
|
|
||||||
cameraPlayer2.Up.Y = 1.0
|
|
||||||
cameraPlayer2.Target.Y = 3.0
|
|
||||||
cameraPlayer2.Position.X = -3.0
|
|
||||||
cameraPlayer2.Position.Y = 3.0
|
|
||||||
|
|
||||||
screenPlayer2 := rl.LoadRenderTexture(screenWidth/2, screenHeight)
|
|
||||||
|
|
||||||
// Build a flipped rectangle the size of the split view to use for drawing later
|
|
||||||
splitScreenRect := rl.Rectangle{0.0, 0.0, float32(screenPlayer1.Texture.Width), float32(-screenPlayer1.Texture.Height)}
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// If anyone moves this frame, how far will they move based on the time since the last frame
|
|
||||||
// this moves thigns at 10 world units per second, regardless of the actual FPS
|
|
||||||
offsetThisFrame := 10.0 * rl.GetFrameTime()
|
|
||||||
|
|
||||||
// Move Player1 forward and backwards (no turning)
|
|
||||||
if rl.IsKeyDown(rl.KeyW) {
|
|
||||||
cameraPlayer1.Position.Z += offsetThisFrame
|
|
||||||
cameraPlayer1.Target.Z += offsetThisFrame
|
|
||||||
} else if rl.IsKeyDown(rl.KeyS) {
|
|
||||||
cameraPlayer1.Position.Z -= offsetThisFrame
|
|
||||||
cameraPlayer1.Target.Z -= offsetThisFrame
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move Player2 forward and backwards (no turning)
|
|
||||||
if rl.IsKeyDown(rl.KeyUp) {
|
|
||||||
cameraPlayer2.Position.X += offsetThisFrame
|
|
||||||
cameraPlayer2.Target.X += offsetThisFrame
|
|
||||||
} else if rl.IsKeyDown(rl.KeyDown) {
|
|
||||||
cameraPlayer2.Position.X -= offsetThisFrame
|
|
||||||
cameraPlayer2.Target.X -= offsetThisFrame
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Draw Player1 view to the render texture
|
|
||||||
rl.BeginTextureMode(screenPlayer1)
|
|
||||||
rl.ClearBackground(rl.SkyBlue)
|
|
||||||
rl.BeginMode3D(cameraPlayer1)
|
|
||||||
DrawScene()
|
|
||||||
rl.EndMode3D()
|
|
||||||
rl.DrawText("PLAYER1 W/S to move", 10, 10, 20, rl.Red)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
// Draw Player2 view to the render texture
|
|
||||||
rl.BeginTextureMode(screenPlayer2)
|
|
||||||
rl.ClearBackground(rl.SkyBlue)
|
|
||||||
rl.BeginMode3D(cameraPlayer2)
|
|
||||||
DrawScene()
|
|
||||||
rl.EndMode3D()
|
|
||||||
rl.DrawText("PLAYER2 UP/DOWN to move", 10, 10, 20, rl.Blue)
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
// Draw both views render textures to the screen side by side
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
rl.DrawTextureRec(screenPlayer1.Texture, splitScreenRect, rl.Vector2{0, 0}, rl.White)
|
|
||||||
rl.DrawTextureRec(screenPlayer2.Texture, splitScreenRect, rl.Vector2{screenWidth / 2.0, 0}, rl.White)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.UnloadRenderTexture(screenPlayer1) // Unload render texture
|
|
||||||
rl.UnloadRenderTexture(screenPlayer2) // Unload render texture
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
|
@ -1,131 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - custom frame control
|
|
||||||
*
|
|
||||||
* NOTE: WARNING: This is an example for advanced users willing to have full control over
|
|
||||||
* the frame processes. By default, EndDrawing() calls the following processes:
|
|
||||||
* 1. Draw remaining batch data: rlDrawRenderBatchActive()
|
|
||||||
* 2. SwapScreenBuffer()
|
|
||||||
* 3. Frame time control: WaitTime()
|
|
||||||
* 4. PollInputEvents()
|
|
||||||
*
|
|
||||||
* To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in
|
|
||||||
* config.h (it requires recompiling raylib). This way those steps are up to the user.
|
|
||||||
*
|
|
||||||
* Note that enabling this flag invalidates some functions:
|
|
||||||
* - GetFrameTime()
|
|
||||||
* - SetTargetFPS()
|
|
||||||
* - GetFPS()
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.0, last time updated with raylib 4.0
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Custom Frame Control")
|
|
||||||
|
|
||||||
previousTime := rl.GetTime()
|
|
||||||
currentTime := 0.0
|
|
||||||
updateDrawTime := 0.0
|
|
||||||
waitTime := 0.0
|
|
||||||
deltaTime := 0.0
|
|
||||||
|
|
||||||
timeCounter := 0.0
|
|
||||||
position := 0.0
|
|
||||||
pause := false
|
|
||||||
|
|
||||||
targetFPS := 60
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
rl.PollInputEvents() // Poll input events (SUPPORT_CUSTOM_FRAME_CONTROL)
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
pause = !pause
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyUp) {
|
|
||||||
targetFPS += 20
|
|
||||||
} else if rl.IsKeyPressed(rl.KeyDown) {
|
|
||||||
targetFPS -= 20
|
|
||||||
}
|
|
||||||
|
|
||||||
if targetFPS < 0 {
|
|
||||||
targetFPS = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if !pause {
|
|
||||||
position += 200 * deltaTime // We move at 200 pixels per second
|
|
||||||
if position >= float64(rl.GetScreenWidth()) {
|
|
||||||
position = 0
|
|
||||||
}
|
|
||||||
timeCounter += deltaTime // We count time (seconds)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
for i := 0; i < rl.GetScreenWidth()/200; i++ {
|
|
||||||
rl.DrawRectangle(200*int32(i), 0, 1, int32(rl.GetScreenHeight()), rl.SkyBlue)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawCircle(int32(position), int32(rl.GetScreenHeight()/2-25), 50, rl.Red)
|
|
||||||
|
|
||||||
msg := fmt.Sprintf("%03.0f ms", timeCounter*1000)
|
|
||||||
rl.DrawText(msg, int32(position-40), int32(rl.GetScreenHeight()/2-100), 20, rl.Maroon)
|
|
||||||
msg = fmt.Sprintf("PosX: %03.0f", position)
|
|
||||||
rl.DrawText(msg, int32(position-50), int32(rl.GetScreenHeight()/2+40), 20, rl.Black)
|
|
||||||
|
|
||||||
msg = "Circle is moving at a constant 200 pixels/sec,\nindependently of the frame rate."
|
|
||||||
rl.DrawText(msg, 10, 10, 20, rl.DarkGray)
|
|
||||||
msg = "PRESS SPACE to PAUSE MOVEMENT"
|
|
||||||
rl.DrawText(msg, 10, int32(rl.GetScreenHeight()-60), 20, rl.Gray)
|
|
||||||
msg = "PRESS UP | DOWN to CHANGE TARGET FPS"
|
|
||||||
rl.DrawText(msg, 10, int32(rl.GetScreenHeight()-30), 20, rl.Gray)
|
|
||||||
msg = fmt.Sprintf("TARGET FPS: %d", targetFPS)
|
|
||||||
rl.DrawText(msg, int32(rl.GetScreenWidth()-220), 10, 20, rl.Lime)
|
|
||||||
msg = fmt.Sprintf("CURRENT FPS: %d", int(1/deltaTime))
|
|
||||||
rl.DrawText(msg, int32(rl.GetScreenWidth()-220), 40, 20, rl.Lime)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
|
|
||||||
// NOTE: In case raylib is configured to SUPPORT_CUSTOM_FRAME_CONTROL,
|
|
||||||
// Events polling, screen buffer swap and frame time control must be managed by the user
|
|
||||||
|
|
||||||
rl.SwapScreenBuffer() // We want a fixed frame rate
|
|
||||||
|
|
||||||
currentTime = rl.GetTime()
|
|
||||||
updateDrawTime = currentTime - previousTime
|
|
||||||
|
|
||||||
if targetFPS > 0 { // We want a fixed frame rate
|
|
||||||
waitTime = (1 / float64(targetFPS)) - updateDrawTime
|
|
||||||
if waitTime > 0 {
|
|
||||||
rl.WaitTime(waitTime)
|
|
||||||
currentTime = rl.GetTime()
|
|
||||||
deltaTime = currentTime - previousTime
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
deltaTime = updateDrawTime
|
|
||||||
}
|
|
||||||
|
|
||||||
previousTime = currentTime
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Set custom logger
|
|
||||||
rl.SetTraceLogCallback(customLog)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Custom Logging")
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.DrawText("Check the console output to see the custom logger in action!", 60, 200, 20, rl.LightGray)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom logging function
|
|
||||||
func customLog(msgType int, text string) {
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
switch rl.TraceLogLevel(msgType) {
|
|
||||||
case rl.LogInfo:
|
|
||||||
fmt.Println("[INFO] : ", now, text)
|
|
||||||
case rl.LogError:
|
|
||||||
fmt.Println("[ERROR] : ", now, text)
|
|
||||||
case rl.LogWarning:
|
|
||||||
fmt.Println("[WARNING] : ", now, text)
|
|
||||||
case rl.LogDebug:
|
|
||||||
fmt.Println("[DEBUG] : ", now, text)
|
|
||||||
default:
|
|
||||||
fmt.Println("[UNKNOWN] : ", now, text)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
@ -8,13 +12,12 @@ func main() {
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
var count int
|
count := int32(0)
|
||||||
var droppedFiles []string
|
var droppedFiles []string
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
if rl.IsFileDropped() {
|
if rl.IsFileDropped() {
|
||||||
droppedFiles = rl.LoadDroppedFiles()
|
droppedFiles = rl.GetDroppedFiles(&count)
|
||||||
count = len(droppedFiles)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
@ -25,7 +28,7 @@ func main() {
|
||||||
} else {
|
} else {
|
||||||
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
rl.DrawText("Dropped files:", 100, 40, 20, rl.DarkGray)
|
||||||
|
|
||||||
for i := 0; i < count; i++ {
|
for i := int32(0); i < count; i++ {
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
rl.DrawRectangle(0, int32(85+40*i), screenWidth, 40, rl.Fade(rl.LightGray, 0.5))
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,7 +44,7 @@ func main() {
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.UnloadDroppedFiles()
|
rl.ClearDroppedFiles()
|
||||||
|
|
||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
maxGestureStrings int = 20
|
maxGestureStrings int = 20
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -21,165 +21,163 @@ func main() {
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
var gamepad int32 = 0 // which gamepad to display
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
if rl.IsGamepadAvailable(gamepad) {
|
if rl.IsGamepadAvailable(rl.GamepadPlayer1) {
|
||||||
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(gamepad)), 10, 10, 10, rl.Black)
|
rl.DrawText(fmt.Sprintf("GP1: %s", rl.GetGamepadName(rl.GamepadPlayer1)), 10, 10, 10, rl.Black)
|
||||||
|
|
||||||
if rl.GetGamepadName(gamepad) == xbox360NameID {
|
if rl.IsGamepadName(rl.GamepadPlayer1, xbox360NameID) {
|
||||||
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)
|
rl.DrawTexture(texXboxPad, 0, 0, rl.DarkGray)
|
||||||
|
|
||||||
// Draw buttons: xbox home
|
// Draw buttons: xbox home
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddle) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonHome) {
|
||||||
rl.DrawCircle(394, 89, 19, rl.Red)
|
rl.DrawCircle(394, 89, 19, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: basic
|
// Draw buttons: basic
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonStart) {
|
||||||
rl.DrawCircle(436, 150, 9, rl.Red)
|
rl.DrawCircle(436, 150, 9, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonSelect) {
|
||||||
rl.DrawCircle(352, 150, 9, rl.Red)
|
rl.DrawCircle(352, 150, 9, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonX) {
|
||||||
rl.DrawCircle(501, 151, 15, rl.Blue)
|
rl.DrawCircle(501, 151, 15, rl.Blue)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonA) {
|
||||||
rl.DrawCircle(536, 187, 15, rl.Lime)
|
rl.DrawCircle(536, 187, 15, rl.Lime)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonB) {
|
||||||
rl.DrawCircle(572, 151, 15, rl.Maroon)
|
rl.DrawCircle(572, 151, 15, rl.Maroon)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonY) {
|
||||||
rl.DrawCircle(536, 115, 15, rl.Gold)
|
rl.DrawCircle(536, 115, 15, rl.Gold)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: d-pad
|
// Draw buttons: d-pad
|
||||||
rl.DrawRectangle(317, 202, 19, 71, rl.Black)
|
rl.DrawRectangle(317, 202, 19, 71, rl.Black)
|
||||||
rl.DrawRectangle(293, 228, 69, 19, rl.Black)
|
rl.DrawRectangle(293, 228, 69, 19, rl.Black)
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonUp) {
|
||||||
rl.DrawRectangle(317, 202, 19, 26, rl.Red)
|
rl.DrawRectangle(317, 202, 19, 26, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonDown) {
|
||||||
rl.DrawRectangle(317, 202+45, 19, 26, rl.Red)
|
rl.DrawRectangle(317, 202+45, 19, 26, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLeft) {
|
||||||
rl.DrawRectangle(292, 228, 25, 19, rl.Red)
|
rl.DrawRectangle(292, 228, 25, 19, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRight) {
|
||||||
rl.DrawRectangle(292+44, 228, 26, 19, rl.Red)
|
rl.DrawRectangle(292+44, 228, 26, 19, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: left-right back
|
// Draw buttons: left-right back
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftTrigger1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonLb) {
|
||||||
rl.DrawCircle(259, 61, 20, rl.Red)
|
rl.DrawCircle(259, 61, 20, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightTrigger1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadXboxButtonRb) {
|
||||||
rl.DrawCircle(536, 61, 20, rl.Red)
|
rl.DrawCircle(536, 61, 20, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw axis: left joystick
|
// Draw axis: left joystick
|
||||||
rl.DrawCircle(259, 152, 39, rl.Black)
|
rl.DrawCircle(259, 152, 39, rl.Black)
|
||||||
rl.DrawCircle(259, 152, 34, rl.LightGray)
|
rl.DrawCircle(259, 152, 34, rl.LightGray)
|
||||||
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftX)*20)),
|
rl.DrawCircle(int32(259+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftX)*20)),
|
||||||
int32(152-(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftY)*20)), 25, rl.Black)
|
int32(152-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLeftY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: right joystick
|
// Draw axis: right joystick
|
||||||
rl.DrawCircle(461, 237, 38, rl.Black)
|
rl.DrawCircle(461, 237, 38, rl.Black)
|
||||||
rl.DrawCircle(461, 237, 33, rl.LightGray)
|
rl.DrawCircle(461, 237, 33, rl.LightGray)
|
||||||
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightX)*20)),
|
rl.DrawCircle(int32(461+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightX)*20)),
|
||||||
int32(237-(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightY)*20)), 25, rl.Black)
|
int32(237-(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRightY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: left-right triggers
|
// Draw axis: left-right triggers
|
||||||
rl.DrawRectangle(170, 30, 15, 70, rl.Gray)
|
rl.DrawRectangle(170, 30, 15, 70, rl.Gray)
|
||||||
rl.DrawRectangle(604, 30, 15, 70, rl.Gray)
|
rl.DrawRectangle(604, 30, 15, 70, rl.Gray)
|
||||||
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftTrigger))/2.0)*70), rl.Red)
|
rl.DrawRectangle(170, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisLt))/2.0)*70), rl.Red)
|
||||||
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightTrigger))/2.0)*70), rl.Red)
|
rl.DrawRectangle(604, 30, 15, int32(((1.0+rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadXboxAxisRt))/2.0)*70), rl.Red)
|
||||||
|
|
||||||
} else if rl.GetGamepadName(gamepad) == ps3NameID {
|
} else if rl.IsGamepadName(rl.GamepadPlayer1, ps3NameID) {
|
||||||
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)
|
rl.DrawTexture(texPs3Pad, 0, 0, rl.DarkGray)
|
||||||
|
|
||||||
// Draw buttons: ps
|
// Draw buttons: ps
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddle) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonPs) {
|
||||||
rl.DrawCircle(396, 222, 13, rl.Red)
|
rl.DrawCircle(396, 222, 13, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: basic
|
// Draw buttons: basic
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSelect) {
|
||||||
rl.DrawRectangle(328, 170, 32, 13, rl.Red)
|
rl.DrawRectangle(328, 170, 32, 13, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonMiddleRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonStart) {
|
||||||
rl.DrawTriangle(rl.NewVector2(436, 168), rl.NewVector2(436, 185), rl.NewVector2(464, 177), rl.Red)
|
rl.DrawTriangle(rl.NewVector2(436, 168), rl.NewVector2(436, 185), rl.NewVector2(464, 177), rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonTriangle) {
|
||||||
rl.DrawCircle(557, 144, 13, rl.Lime)
|
rl.DrawCircle(557, 144, 13, rl.Lime)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCircle) {
|
||||||
rl.DrawCircle(586, 173, 13, rl.Red)
|
rl.DrawCircle(586, 173, 13, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonCross) {
|
||||||
rl.DrawCircle(557, 203, 13, rl.Violet)
|
rl.DrawCircle(557, 203, 13, rl.Violet)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightFaceLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonSquare) {
|
||||||
rl.DrawCircle(527, 173, 13, rl.Pink)
|
rl.DrawCircle(527, 173, 13, rl.Pink)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: d-pad
|
// Draw buttons: d-pad
|
||||||
rl.DrawRectangle(225, 132, 24, 84, rl.Black)
|
rl.DrawRectangle(225, 132, 24, 84, rl.Black)
|
||||||
rl.DrawRectangle(195, 161, 84, 25, rl.Black)
|
rl.DrawRectangle(195, 161, 84, 25, rl.Black)
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceUp) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonUp) {
|
||||||
rl.DrawRectangle(225, 132, 24, 29, rl.Red)
|
rl.DrawRectangle(225, 132, 24, 29, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceDown) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonDown) {
|
||||||
rl.DrawRectangle(225, 132+54, 24, 30, rl.Red)
|
rl.DrawRectangle(225, 132+54, 24, 30, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceLeft) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonLeft) {
|
||||||
rl.DrawRectangle(195, 161, 30, 25, rl.Red)
|
rl.DrawRectangle(195, 161, 30, 25, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftFaceRight) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonRight) {
|
||||||
rl.DrawRectangle(195+54, 161, 30, 25, rl.Red)
|
rl.DrawRectangle(195+54, 161, 30, 25, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw buttons: left-right back buttons
|
// Draw buttons: left-right back buttons
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonLeftTrigger1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonL1) {
|
||||||
rl.DrawCircle(239, 82, 20, rl.Red)
|
rl.DrawCircle(239, 82, 20, rl.Red)
|
||||||
}
|
}
|
||||||
if rl.IsGamepadButtonDown(gamepad, rl.GamepadButtonRightTrigger1) {
|
if rl.IsGamepadButtonDown(rl.GamepadPlayer1, rl.GamepadPs3ButtonR1) {
|
||||||
rl.DrawCircle(557, 82, 20, rl.Red)
|
rl.DrawCircle(557, 82, 20, rl.Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw axis: left joystick
|
// Draw axis: left joystick
|
||||||
rl.DrawCircle(319, 255, 35, rl.Black)
|
rl.DrawCircle(319, 255, 35, rl.Black)
|
||||||
rl.DrawCircle(319, 255, 31, rl.LightGray)
|
rl.DrawCircle(319, 255, 31, rl.LightGray)
|
||||||
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftX)*20)),
|
rl.DrawCircle(int32(319+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftX)*20)),
|
||||||
int32(255+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftY)*20)), 25, rl.Black)
|
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisLeftY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: right joystick
|
// Draw axis: right joystick
|
||||||
rl.DrawCircle(475, 255, 35, rl.Black)
|
rl.DrawCircle(475, 255, 35, rl.Black)
|
||||||
rl.DrawCircle(475, 255, 31, rl.LightGray)
|
rl.DrawCircle(475, 255, 31, rl.LightGray)
|
||||||
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightX)*20)),
|
rl.DrawCircle(int32(475+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightX)*20)),
|
||||||
int32(255+(rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightY)*20)), 25, rl.Black)
|
int32(255+(rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisRightY)*20)), 25, rl.Black)
|
||||||
|
|
||||||
// Draw axis: left-right triggers
|
// Draw axis: left-right triggers
|
||||||
rl.DrawRectangle(169, 48, 15, 70, rl.Gray)
|
rl.DrawRectangle(169, 48, 15, 70, rl.Gray)
|
||||||
rl.DrawRectangle(611, 48, 15, 70, rl.Gray)
|
rl.DrawRectangle(611, 48, 15, 70, rl.Gray)
|
||||||
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisLeftTrigger))/2.0)*70), rl.Red)
|
rl.DrawRectangle(169, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisL2))/2.0)*70), rl.Red)
|
||||||
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxisRightTrigger))/2.0)*70), rl.Red)
|
rl.DrawRectangle(611, 48, 15, int32(((1.0-rl.GetGamepadAxisMovement(rl.GamepadPlayer1, rl.GamepadPs3AxisR2))/2.0)*70), rl.Red)
|
||||||
} else {
|
} else {
|
||||||
rl.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, rl.Gray)
|
rl.DrawText("- GENERIC GAMEPAD -", 280, 180, 20, rl.Gray)
|
||||||
|
|
||||||
// TODO: Draw generic gamepad
|
// TODO: Draw generic gamepad
|
||||||
}
|
}
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(gamepad)), 10, 50, 10, rl.Maroon)
|
rl.DrawText(fmt.Sprintf("DETECTED AXIS [%d]:", rl.GetGamepadAxisCount(rl.GamepadPlayer1)), 10, 50, 10, rl.Maroon)
|
||||||
|
|
||||||
for i := int32(0); i < rl.GetGamepadAxisCount(gamepad); i++ {
|
for i := int32(0); i < rl.GetGamepadAxisCount(rl.GamepadPlayer1); i++ {
|
||||||
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(gamepad, i)), 20, 70+20*i, 10, rl.DarkGray)
|
rl.DrawText(fmt.Sprintf("AXIS %d: %.02f", i, rl.GetGamepadAxisMovement(rl.GamepadPlayer1, i)), 20, 70+20*i, 10, rl.DarkGray)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rl.GetGamepadButtonPressed() != -1 {
|
if rl.GetGamepadButtonPressed() != -1 {
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -18,7 +18,7 @@ func main() {
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
boxPositionY -= int32(rl.GetMouseWheelMove()) * scrollSpeed
|
boxPositionY -= rl.GetMouseWheelMove() * scrollSpeed
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
screenW = int32(800)
|
|
||||||
screenH = int32(450)
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
rl.InitWindow(screenW, screenH, "raylib [core] example - scissor test")
|
|
||||||
|
|
||||||
scissorArea := rl.NewRectangle(0, 0, 300, 300)
|
|
||||||
scissorMode := true
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyS) {
|
|
||||||
scissorMode = !scissorMode
|
|
||||||
}
|
|
||||||
|
|
||||||
scissorArea.X = float32(rl.GetMouseX())
|
|
||||||
scissorArea.Y = float32(rl.GetMouseY())
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
if scissorMode {
|
|
||||||
rl.BeginScissorMode(scissorArea.ToInt32().X, scissorArea.ToInt32().Y, scissorArea.ToInt32().Width, scissorArea.ToInt32().Height)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangle(0, 0, screenW, screenH, rl.Red)
|
|
||||||
rl.DrawText("MOVE MOUSE TO REVEAL TEXT", 190, 200, 20, rl.Black)
|
|
||||||
|
|
||||||
if scissorMode {
|
|
||||||
rl.EndScissorMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRectangleLinesEx(scissorArea, 1, rl.Black)
|
|
||||||
rl.DrawText("S KEY TO TOGGLE MODE", 10, 10, 20, rl.Black)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const screenW = int32(1280)
|
|
||||||
const screenH = int32(720)
|
|
||||||
const virtualScreenW = screenW / 5
|
|
||||||
const virtualScreenH = screenH / 5
|
|
||||||
const virtualRatio = float32(screenW) / float32(virtualScreenW)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
rl.InitWindow(screenW, screenH, "raylib [core] example - smooth pixel-perfect camera")
|
|
||||||
|
|
||||||
worldSpaceCam := rl.Camera2D{}
|
|
||||||
worldSpaceCam.Zoom = 1
|
|
||||||
|
|
||||||
screenSpaceCam := rl.Camera2D{}
|
|
||||||
screenSpaceCam.Zoom = 1
|
|
||||||
|
|
||||||
target := rl.LoadRenderTexture(virtualScreenW, virtualScreenH)
|
|
||||||
|
|
||||||
rec1 := rl.NewRectangle(120, 60, 80, 40)
|
|
||||||
rec2 := rl.NewRectangle(130, 70, 90, 30)
|
|
||||||
rec3 := rl.NewRectangle(140, 80, 65, 45)
|
|
||||||
|
|
||||||
sourceRec := rl.NewRectangle(0, 0, float32(target.Texture.Width), -float32(target.Texture.Height))
|
|
||||||
destRec := rl.NewRectangle(-virtualRatio, -virtualRatio, float32(screenW)+(virtualRatio*2), float32(screenH)+(virtualRatio*2))
|
|
||||||
|
|
||||||
origin := rl.NewVector2(0, 0)
|
|
||||||
|
|
||||||
rotation, camX, camY := float32(0), float32(0), float32(0)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
rotation += 60 * rl.GetFrameTime()
|
|
||||||
|
|
||||||
camX = float32(math.Sin(rl.GetTime()) * 50)
|
|
||||||
camY = float32(math.Cos(rl.GetTime()) * 30)
|
|
||||||
|
|
||||||
screenSpaceCam.Target = rl.NewVector2(camX, camY)
|
|
||||||
|
|
||||||
worldSpaceCam.Target.X = screenSpaceCam.Target.X
|
|
||||||
screenSpaceCam.Target.X -= worldSpaceCam.Target.X
|
|
||||||
screenSpaceCam.Target.X *= virtualRatio
|
|
||||||
|
|
||||||
worldSpaceCam.Target.Y = screenSpaceCam.Target.Y
|
|
||||||
screenSpaceCam.Target.Y -= worldSpaceCam.Target.Y
|
|
||||||
screenSpaceCam.Target.Y *= virtualRatio
|
|
||||||
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode2D(worldSpaceCam)
|
|
||||||
|
|
||||||
rl.DrawRectanglePro(rec1, origin, rotation, rl.Black)
|
|
||||||
rl.DrawRectanglePro(rec2, origin, -rotation, rl.Red)
|
|
||||||
rl.DrawRectanglePro(rec3, origin, rotation+45, rl.Blue)
|
|
||||||
|
|
||||||
rl.EndMode2D()
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Red)
|
|
||||||
rl.BeginMode2D(screenSpaceCam)
|
|
||||||
rl.DrawTexturePro(target.Texture, sourceRec, destRec, origin, 0, rl.White)
|
|
||||||
rl.EndMode2D()
|
|
||||||
|
|
||||||
rl.DrawText("screen res "+fmt.Sprint(screenW)+"x"+fmt.Sprint(screenH), 10, 10, 20, rl.Black)
|
|
||||||
rl.DrawText("world res "+fmt.Sprint(virtualScreenW)+"x"+fmt.Sprint(virtualScreenH), 10, 30, 20, rl.Black)
|
|
||||||
rl.DrawFPS(screenW-100, 10)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadRenderTexture(target)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,64 +1,45 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - Storage save/load values
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 1.4, last time updated with raylib 4.2
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
screenWidth = 800
|
storageScore = 0
|
||||||
screenHeight = 450
|
storageHiscore = 1
|
||||||
storageDataFile = "storage.data"
|
|
||||||
// NOTE: Storage positions must start with 0, directly related to file memory layout
|
|
||||||
storagePositionScore = 0
|
|
||||||
storagePositionHiscore = 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values")
|
rl.InitWindow(800, 450, "raylib [core] example - storage save/load values")
|
||||||
|
|
||||||
var score int32
|
score := int32(0)
|
||||||
var hiscore int32
|
hiscore := int32(0)
|
||||||
var framesCounter int32
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
framesCounter := 0
|
||||||
|
|
||||||
// Main game loop
|
rl.SetTargetFPS(60)
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
for !rl.WindowShouldClose() {
|
||||||
if rl.IsKeyPressed(rl.KeyR) {
|
if rl.IsKeyPressed(rl.KeyR) {
|
||||||
score = rl.GetRandomValue(1000, 2000)
|
score = rl.GetRandomValue(1000, 2000)
|
||||||
hiscore = rl.GetRandomValue(2000, 4000)
|
hiscore = rl.GetRandomValue(2000, 4000)
|
||||||
}
|
}
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
if rl.IsKeyPressed(rl.KeyEnter) {
|
||||||
_ = SaveStorageValue(storagePositionScore, score)
|
rl.StorageSaveValue(storageScore, score)
|
||||||
_ = SaveStorageValue(storagePositionHiscore, hiscore)
|
rl.StorageSaveValue(storageHiscore, hiscore)
|
||||||
} else if rl.IsKeyPressed(rl.KeySpace) {
|
} else if rl.IsKeyPressed(rl.KeySpace) {
|
||||||
// NOTE: If requested position could not be found, value 0 is returned
|
// NOTE: If requested position could not be found, value 0 is returned
|
||||||
score, _ = LoadStorageValue(storagePositionScore)
|
score = rl.StorageLoadValue(storageScore)
|
||||||
hiscore, _ = LoadStorageValue(storagePositionHiscore)
|
hiscore = rl.StorageLoadValue(storageHiscore)
|
||||||
}
|
}
|
||||||
|
|
||||||
framesCounter++
|
framesCounter++
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, rl.Maroon)
|
rl.DrawText(fmt.Sprintf("SCORE: %d", score), 280, 130, 40, rl.Maroon)
|
||||||
|
@ -73,55 +54,5 @@ func main() {
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
rl.CloseWindow()
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveStorageValue saves an integer value to storage file (to defined position)
|
|
||||||
// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
|
|
||||||
func SaveStorageValue(position uint32, value int32) error {
|
|
||||||
// Load the file data
|
|
||||||
fileData, err := os.ReadFile(storageDataFile)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return fmt.Errorf("failed to load file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dataSize := len(fileData)
|
|
||||||
requiredSize := int((position + 1) * 4) // Each int32 is 4 bytes
|
|
||||||
newFileData := make([]byte, requiredSize)
|
|
||||||
|
|
||||||
// Copy existing file data to newFileData
|
|
||||||
if dataSize > 0 {
|
|
||||||
copy(newFileData, fileData)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the value at the specified position
|
|
||||||
binary.LittleEndian.PutUint32(newFileData[position*4:], uint32(value))
|
|
||||||
|
|
||||||
// Save the updated data back to the file
|
|
||||||
err = os.WriteFile(storageDataFile, newFileData, 0644)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to save file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadStorageValue loads an integer value from storage file (from defined position)
|
|
||||||
// NOTE: If requested position could not be found, value 0 is returned
|
|
||||||
func LoadStorageValue(position uint32) (int32, error) {
|
|
||||||
// Load the file data
|
|
||||||
fileData, err := os.ReadFile(storageDataFile)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("failed to load file: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dataSize := len(fileData)
|
|
||||||
if dataSize < int((position+1)*4) {
|
|
||||||
return 0, fmt.Errorf("position out of bounds")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the value at the specified position
|
|
||||||
value := int32(binary.LittleEndian.Uint32(fileData[position*4:]))
|
|
||||||
return value, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
#version 100
|
|
||||||
|
|
||||||
precision mediump float;
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
|
||||||
varying vec2 fragTexCoord;
|
|
||||||
varying vec4 fragColor;
|
|
||||||
|
|
||||||
// Input uniform values
|
|
||||||
uniform sampler2D texture0;
|
|
||||||
uniform vec4 colDiffuse;
|
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
|
||||||
uniform vec2 leftLensCenter;
|
|
||||||
uniform vec2 rightLensCenter;
|
|
||||||
uniform vec2 leftScreenCenter;
|
|
||||||
uniform vec2 rightScreenCenter;
|
|
||||||
uniform vec2 scale;
|
|
||||||
uniform vec2 scaleIn;
|
|
||||||
uniform vec4 deviceWarpParam;
|
|
||||||
uniform vec4 chromaAbParam;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
// Compute lens distortion
|
|
||||||
vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter;
|
|
||||||
vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter;
|
|
||||||
vec2 theta = (fragTexCoord - lensCenter)*scaleIn;
|
|
||||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
|
||||||
vec2 theta1 = theta*(deviceWarpParam.x + deviceWarpParam.y*rSq + deviceWarpParam.z*rSq*rSq + deviceWarpParam.w*rSq*rSq*rSq);
|
|
||||||
vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq);
|
|
||||||
vec2 tcBlue = lensCenter + scale*thetaBlue;
|
|
||||||
|
|
||||||
if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue)))
|
|
||||||
{
|
|
||||||
// Set black fragment for everything outside the lens border
|
|
||||||
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Compute color chroma aberration
|
|
||||||
float blue = texture2D(texture0, tcBlue).b;
|
|
||||||
vec2 tcGreen = lensCenter + scale*theta1;
|
|
||||||
float green = texture2D(texture0, tcGreen).g;
|
|
||||||
|
|
||||||
vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq);
|
|
||||||
vec2 tcRed = lensCenter + scale*thetaRed;
|
|
||||||
|
|
||||||
float red = texture2D(texture0, tcRed).r;
|
|
||||||
gl_FragColor = vec4(red, green, blue, 1.0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
#version 330
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
|
||||||
in vec2 fragTexCoord;
|
|
||||||
in vec4 fragColor;
|
|
||||||
|
|
||||||
// Input uniform values
|
|
||||||
uniform sampler2D texture0;
|
|
||||||
uniform vec4 colDiffuse;
|
|
||||||
|
|
||||||
// Output fragment color
|
|
||||||
out vec4 finalColor;
|
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
|
||||||
uniform vec2 leftLensCenter = vec2(0.288, 0.5);
|
|
||||||
uniform vec2 rightLensCenter = vec2(0.712, 0.5);
|
|
||||||
uniform vec2 leftScreenCenter = vec2(0.25, 0.5);
|
|
||||||
uniform vec2 rightScreenCenter = vec2(0.75, 0.5);
|
|
||||||
uniform vec2 scale = vec2(0.25, 0.45);
|
|
||||||
uniform vec2 scaleIn = vec2(4, 2.2222);
|
|
||||||
uniform vec4 deviceWarpParam = vec4(1, 0.22, 0.24, 0);
|
|
||||||
uniform vec4 chromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
// Compute lens distortion
|
|
||||||
vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter;
|
|
||||||
vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter;
|
|
||||||
vec2 theta = (fragTexCoord - lensCenter)*scaleIn;
|
|
||||||
float rSq = theta.x*theta.x + theta.y*theta.y;
|
|
||||||
vec2 theta1 = theta*(deviceWarpParam.x + deviceWarpParam.y*rSq + deviceWarpParam.z*rSq*rSq + deviceWarpParam.w*rSq*rSq*rSq);
|
|
||||||
vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq);
|
|
||||||
vec2 tcBlue = lensCenter + scale*thetaBlue;
|
|
||||||
|
|
||||||
if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue)))
|
|
||||||
{
|
|
||||||
// Set black fragment for everything outside the lens border
|
|
||||||
finalColor = vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Compute color chroma aberration
|
|
||||||
float blue = texture(texture0, tcBlue).b;
|
|
||||||
vec2 tcGreen = lensCenter + scale*theta1;
|
|
||||||
float green = texture(texture0, tcGreen).g;
|
|
||||||
|
|
||||||
vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq);
|
|
||||||
vec2 tcRed = lensCenter + scale*thetaRed;
|
|
||||||
|
|
||||||
float red = texture(texture0, tcRed).r;
|
|
||||||
finalColor = vec4(red, green, blue, 1.0);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,137 +1,54 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - VR Simulator (Oculus Rift CV1 parameters)
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2017-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
glslVersion = 330 // Desktop
|
|
||||||
// glslVersion = 100 // Android, web
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
hmd := rl.GetVrDeviceInfo(rl.HmdOculusRiftCv1) // Oculus Rift CV1
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator")
|
rl.InitWindow(int32(hmd.HScreenSize), int32(hmd.VScreenSize), "raylib [core] example - vr simulator")
|
||||||
|
|
||||||
// VR device parameters definition
|
// NOTE: default device (simulator)
|
||||||
device := rl.VrDeviceInfo{
|
rl.InitVrSimulator(hmd) // Init VR device
|
||||||
// Oculus Rift CV1 parameters for simulator
|
|
||||||
HResolution: 2160, // Horizontal resolution in pixels
|
|
||||||
VResolution: 1200, // Vertical resolution in pixels
|
|
||||||
HScreenSize: 0.133793, // Horizontal size in meters
|
|
||||||
VScreenSize: 0.0669, // Vertical size in meters
|
|
||||||
EyeToScreenDistance: 0.041, // Distance between eye and display in meters
|
|
||||||
LensSeparationDistance: 0.07, // Lens separation distance in meters
|
|
||||||
InterpupillaryDistance: 0.07, // IPD (distance between pupils) in meters
|
|
||||||
|
|
||||||
// NOTE: CV1 uses fresnel-hybrid-asymmetric lenses with specific compute shaders
|
camera := rl.Camera{}
|
||||||
// Following parameters are just an approximation to CV1 distortion stereo rendering
|
camera.Position = rl.NewVector3(5.0, 2.0, 5.0) // Camera position
|
||||||
|
camera.Target = rl.NewVector3(0.0, 2.0, 0.0) // Camera looking at point
|
||||||
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0) // Camera up vector (rotation towards target)
|
||||||
|
camera.Fovy = 60.0 // Camera field-of-view Y
|
||||||
|
|
||||||
// Lens distortion constant parameters
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
LensDistortionValues: [4]float32{1.0, 0.22, 0.24, 0.0},
|
|
||||||
// Chromatic aberration correction parameters
|
|
||||||
ChromaAbCorrection: [4]float32{0.996, -0.004, 1.014, 0.0},
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load VR stereo config for VR device parameters (Oculus Rift CV1 parameters)
|
rl.SetCameraMode(camera, rl.CameraFirstPerson) // Set first person camera mode
|
||||||
config := rl.LoadVrStereoConfig(device)
|
|
||||||
|
|
||||||
// Distortion shader (uses device lens distortion and chroma)
|
rl.SetTargetFPS(90)
|
||||||
fileName := fmt.Sprintf("distortion%d.fs", glslVersion)
|
|
||||||
distortion := rl.LoadShader("", fileName)
|
|
||||||
|
|
||||||
// Update distortion shader with lens and distortion-scale parameters
|
for !rl.WindowShouldClose() {
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "leftLensCenter"),
|
rl.UpdateCamera(&camera) // Update camera (simulator mode)
|
||||||
config.LeftLensCenter[:], rl.ShaderUniformVec2)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "rightLensCenter"),
|
|
||||||
config.RightLensCenter[:], rl.ShaderUniformVec2)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "leftScreenCenter"),
|
|
||||||
config.LeftScreenCenter[:], rl.ShaderUniformVec2)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "rightScreenCenter"),
|
|
||||||
config.RightScreenCenter[:], rl.ShaderUniformVec2)
|
|
||||||
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "scale"),
|
rl.BeginDrawing()
|
||||||
config.Scale[:], rl.ShaderUniformVec2)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "scaleIn"),
|
|
||||||
config.ScaleIn[:], rl.ShaderUniformVec2)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "deviceWarpParam"),
|
|
||||||
device.LensDistortionValues[:], rl.ShaderUniformVec4)
|
|
||||||
rl.SetShaderValue(distortion, rl.GetShaderLocation(distortion, "chromaAbParam"),
|
|
||||||
device.ChromaAbCorrection[:], rl.ShaderUniformVec4)
|
|
||||||
|
|
||||||
// Initialize frame buffer for stereo rendering
|
|
||||||
// NOTE: Screen size should match HMD aspect ratio
|
|
||||||
target := rl.LoadRenderTexture(device.HResolution, device.VResolution)
|
|
||||||
|
|
||||||
// The target's height is flipped (in the source Rectangle), due to OpenGL reasons
|
|
||||||
sourceRec := rl.Rectangle{Width: float32(target.Texture.Width), Height: float32(-target.Texture.Height)}
|
|
||||||
destRec := rl.Rectangle{Width: float32(rl.GetScreenWidth()), Height: float32(rl.GetScreenHeight())}
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
|
||||||
|
|
||||||
camera := rl.Camera{
|
|
||||||
Position: rl.Vector3{X: 5, Y: 2, Z: 5},
|
|
||||||
Target: rl.Vector3{Y: 2},
|
|
||||||
Up: rl.Vector3{Y: 1},
|
|
||||||
Fovy: 60.0,
|
|
||||||
Projection: rl.CameraPerspective,
|
|
||||||
}
|
|
||||||
|
|
||||||
cubePosition := rl.Vector3{}
|
|
||||||
|
|
||||||
rl.DisableCursor() // Limit cursor to relative movement inside the window
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
|
||||||
|
|
||||||
// Draw texture
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
rl.BeginVrStereoMode(config)
|
|
||||||
|
rl.BeginVrDrawing()
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
rl.DrawCube(cubePosition, 2.0, 2.0, 2.0, rl.Red)
|
||||||
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
rl.DrawCubeWires(cubePosition, 2.0, 2.0, 2.0, rl.Maroon)
|
||||||
|
|
||||||
rl.DrawGrid(40, 1.0)
|
rl.DrawGrid(40, 1.0)
|
||||||
|
|
||||||
rl.EndMode3D()
|
rl.EndMode3D()
|
||||||
rl.EndVrStereoMode()
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
// Draw
|
rl.EndVrDrawing()
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginShaderMode(distortion)
|
|
||||||
rl.DrawTexturePro(target.Texture, sourceRec, destRec, rl.Vector2{}, 0.0, rl.White)
|
|
||||||
rl.EndShaderMode()
|
|
||||||
rl.DrawFPS(10, 10)
|
rl.DrawFPS(10, 10)
|
||||||
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
rl.CloseVrSimulator() // Close VR simulator
|
||||||
rl.UnloadVrStereoConfig(config) // Unload stereo config
|
|
||||||
|
|
||||||
rl.UnloadRenderTexture(target) // Unload stereo render fbo
|
rl.CloseWindow()
|
||||||
rl.UnloadShader(distortion) // Unload distortion shader
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,260 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [core] example - window flags
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 3.5, last time updated with raylib 3.5
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
// Possible window flags
|
|
||||||
/*
|
|
||||||
FLAG_VSYNC_HINT
|
|
||||||
FLAG_FULLSCREEN_MODE -> not working properly -> wrong scaling!
|
|
||||||
FLAG_WINDOW_RESIZABLE
|
|
||||||
FLAG_WINDOW_UNDECORATED
|
|
||||||
FLAG_WINDOW_TRANSPARENT
|
|
||||||
FLAG_WINDOW_HIDDEN
|
|
||||||
FLAG_WINDOW_MINIMIZED -> Not supported on window creation
|
|
||||||
FLAG_WINDOW_MAXIMIZED -> Not supported on window creation
|
|
||||||
FLAG_WINDOW_UNFOCUSED
|
|
||||||
FLAG_WINDOW_TOPMOST
|
|
||||||
FLAG_WINDOW_HIGHDPI -> errors after minimize-resize, fb size is recalculated
|
|
||||||
FLAG_WINDOW_ALWAYS_RUN
|
|
||||||
FLAG_MSAA_4X_HINT
|
|
||||||
*/
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Set configuration flags for window creation
|
|
||||||
//SetConfigFlags(FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI);
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Window Flags")
|
|
||||||
|
|
||||||
ballPosition := rl.Vector2{X: float32(rl.GetScreenWidth()) / 2.0, Y: float32(rl.GetScreenHeight()) / 2.0}
|
|
||||||
ballSpeed := rl.Vector2{X: 5.0, Y: 4.0}
|
|
||||||
ballRadius := float32(20.0)
|
|
||||||
framesCounter := 0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
if rl.IsKeyPressed(rl.KeyF) {
|
|
||||||
rl.ToggleFullscreen() // modifies window size when scaling!
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyR) {
|
|
||||||
if rl.IsWindowState(rl.FlagWindowResizable) {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowResizable)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagWindowResizable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyD) {
|
|
||||||
if rl.IsWindowState(rl.FlagWindowUndecorated) {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowUndecorated)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagWindowUndecorated)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyH) {
|
|
||||||
if !rl.IsWindowState(rl.FlagWindowHidden) {
|
|
||||||
rl.SetWindowState(rl.FlagWindowHidden)
|
|
||||||
}
|
|
||||||
|
|
||||||
framesCounter = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsWindowState(rl.FlagWindowHidden) {
|
|
||||||
framesCounter++
|
|
||||||
if framesCounter >= 240 {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowHidden) // Show window after 3 seconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyN) {
|
|
||||||
if !rl.IsWindowState(rl.FlagWindowMinimized) {
|
|
||||||
rl.MinimizeWindow()
|
|
||||||
}
|
|
||||||
|
|
||||||
framesCounter = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsWindowState(rl.FlagWindowMinimized) {
|
|
||||||
framesCounter++
|
|
||||||
if framesCounter >= 240 {
|
|
||||||
rl.RestoreWindow() // Restore window after 3 seconds
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyM) {
|
|
||||||
// NOTE: Requires FLAG_WINDOW_RESIZABLE enabled!
|
|
||||||
if rl.IsWindowState(rl.FlagWindowMaximized) {
|
|
||||||
rl.RestoreWindow()
|
|
||||||
} else {
|
|
||||||
rl.MaximizeWindow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyU) {
|
|
||||||
if rl.IsWindowState(rl.FlagWindowUnfocused) {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowUnfocused)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagWindowUnfocused)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyT) {
|
|
||||||
if rl.IsWindowState(rl.FlagWindowTopmost) {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowTopmost)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagWindowTopmost)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyA) {
|
|
||||||
if rl.IsWindowState(rl.FlagWindowAlwaysRun) {
|
|
||||||
rl.ClearWindowState(rl.FlagWindowAlwaysRun)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagWindowAlwaysRun)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyV) {
|
|
||||||
if rl.IsWindowState(rl.FlagVsyncHint) {
|
|
||||||
rl.ClearWindowState(rl.FlagVsyncHint)
|
|
||||||
} else {
|
|
||||||
rl.SetWindowState(rl.FlagVsyncHint)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bouncing ball logic
|
|
||||||
ballPosition.X += ballSpeed.X
|
|
||||||
ballPosition.Y += ballSpeed.Y
|
|
||||||
if (ballPosition.X >= (float32(rl.GetScreenWidth()) - ballRadius)) || (ballPosition.X <= ballRadius) {
|
|
||||||
ballSpeed.X *= -1.0
|
|
||||||
}
|
|
||||||
if (ballPosition.Y >= (float32(rl.GetScreenHeight()) - ballRadius)) || (ballPosition.Y <= ballRadius) {
|
|
||||||
ballSpeed.Y *= -1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
if rl.IsWindowState(rl.FlagWindowTransparent) {
|
|
||||||
rl.ClearBackground(rl.Blank)
|
|
||||||
} else {
|
|
||||||
rl.ClearBackground(rl.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawCircleV(ballPosition, ballRadius, rl.Maroon)
|
|
||||||
rl.DrawRectangleLinesEx(
|
|
||||||
rl.Rectangle{
|
|
||||||
Width: float32(rl.GetScreenWidth()),
|
|
||||||
Height: float32(rl.GetScreenHeight()),
|
|
||||||
},
|
|
||||||
4, rl.White,
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.DrawCircleV(rl.GetMousePosition(), 10, rl.DarkBlue)
|
|
||||||
|
|
||||||
rl.DrawFPS(10, 10)
|
|
||||||
|
|
||||||
rl.DrawText(
|
|
||||||
fmt.Sprintf("Screen Size: [%d, %d]", rl.GetScreenWidth(), rl.GetScreenHeight()),
|
|
||||||
10,
|
|
||||||
40,
|
|
||||||
10,
|
|
||||||
rl.Green,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Draw window state info
|
|
||||||
rl.DrawText("Following flags can be set after window creation:", 10, 60, 10, rl.Gray)
|
|
||||||
if rl.IsWindowState(rl.FlagFullscreenMode) {
|
|
||||||
rl.DrawText("[F] FLAG_FULLSCREEN_MODE: on", 10, 80, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[F] FLAG_FULLSCREEN_MODE: off", 10, 80, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowResizable) {
|
|
||||||
rl.DrawText("[R] FLAG_WINDOW_RESIZABLE: on", 10, 100, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[R] FLAG_WINDOW_RESIZABLE: off", 10, 100, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowUndecorated) {
|
|
||||||
rl.DrawText("[D] FLAG_WINDOW_UNDECORATED: on", 10, 120, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[D] FLAG_WINDOW_UNDECORATED: off", 10, 120, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowHidden) {
|
|
||||||
rl.DrawText("[H] FLAG_WINDOW_HIDDEN: on", 10, 140, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[H] FLAG_WINDOW_HIDDEN: off", 10, 140, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowMinimized) {
|
|
||||||
rl.DrawText("[N] FLAG_WINDOW_MINIMIZED: on", 10, 160, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[N] FLAG_WINDOW_MINIMIZED: off", 10, 160, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowMaximized) {
|
|
||||||
rl.DrawText("[M] FLAG_WINDOW_MAXIMIZED: on", 10, 180, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[M] FLAG_WINDOW_MAXIMIZED: off", 10, 180, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowUnfocused) {
|
|
||||||
rl.DrawText("[G] FLAG_WINDOW_UNFOCUSED: on", 10, 200, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[U] FLAG_WINDOW_UNFOCUSED: off", 10, 200, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowTopmost) {
|
|
||||||
rl.DrawText("[T] FLAG_WINDOW_TOPMOST: on", 10, 220, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[T] FLAG_WINDOW_TOPMOST: off", 10, 220, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowAlwaysRun) {
|
|
||||||
rl.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: on", 10, 240, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: off", 10, 240, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagVsyncHint) {
|
|
||||||
rl.DrawText("[V] FLAG_VSYNC_HINT: on", 10, 260, 10,
|
|
||||||
rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("[V] FLAG_VSYNC_HINT: off", 10, 260, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawText("Following flags can only be set before window creation:", 10, 300, 10, rl.Gray)
|
|
||||||
if rl.IsWindowState(rl.FlagWindowHighdpi) {
|
|
||||||
rl.DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagWindowTransparent) {
|
|
||||||
rl.DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
if rl.IsWindowState(rl.FlagMsaa4xHint) {
|
|
||||||
rl.DrawText("FLAG_MSAA_4X_HINT: on", 10, 360, 10, rl.Lime)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("FLAG_MSAA_4X_HINT: off", 10, 360, 10, rl.Maroon)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"image/color"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Enable config flags for resizable window and vertical synchro
|
|
||||||
rl.SetConfigFlags(rl.FlagWindowResizable | rl.FlagVsyncHint)
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Window Scale Letterbox")
|
|
||||||
rl.SetWindowMinSize(320, 240)
|
|
||||||
|
|
||||||
gameScreenWidth, gameScreenHeight := int32(640), int32(480)
|
|
||||||
|
|
||||||
// Render texture initialization, used to hold the rendering result so we can easily resize it
|
|
||||||
target := rl.LoadRenderTexture(gameScreenWidth, gameScreenHeight)
|
|
||||||
rl.SetTextureFilter(target.Texture, rl.FilterBilinear) // Texture scale filter to use
|
|
||||||
|
|
||||||
colors := getRandomColors()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Compute required frame buffer scaling
|
|
||||||
scale := min(float32(rl.GetScreenWidth())/float32(gameScreenWidth),
|
|
||||||
float32(rl.GetScreenHeight())/float32(gameScreenHeight))
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
// Recalculate random colors for the bars
|
|
||||||
colors = getRandomColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update virtual mouse (clamped mouse value behind game screen)
|
|
||||||
mouse := rl.GetMousePosition()
|
|
||||||
virtualMouse := rl.Vector2{
|
|
||||||
X: (mouse.X - (float32(rl.GetScreenWidth())-(float32(gameScreenWidth)*scale))*0.5) / scale,
|
|
||||||
Y: (mouse.Y - (float32(rl.GetScreenHeight())-(float32(gameScreenHeight)*scale))*0.5) / scale,
|
|
||||||
}
|
|
||||||
virtualMouse = rl.Vector2Clamp(
|
|
||||||
virtualMouse,
|
|
||||||
rl.Vector2{},
|
|
||||||
rl.Vector2{X: float32(gameScreenWidth), Y: float32(gameScreenHeight)},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Apply the same transformation as the virtual mouse to the real mouse (i.e. to work with raygui)
|
|
||||||
//rl.SetMouseOffset(
|
|
||||||
// int(-(float32(rl.GetScreenWidth())-(float32(gameScreenWidth)*scale))*0.5),
|
|
||||||
// int(-(float32(rl.GetScreenHeight())-(float32(gameScreenHeight)*scale))*0.5),
|
|
||||||
//)
|
|
||||||
//rl.SetMouseScale(1/scale, 1/scale)
|
|
||||||
|
|
||||||
// Draw everything in the render texture, note this will not be rendered on screen, yet
|
|
||||||
rl.BeginTextureMode(target)
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.White)
|
|
||||||
for i := int32(0); i < 10; i++ {
|
|
||||||
rl.DrawRectangle(0, (gameScreenHeight/10)*i, gameScreenWidth, gameScreenHeight/10, colors[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
text := "If executed inside a window,\nyou can resize the window,\nand see the screen scaling!"
|
|
||||||
rl.DrawText(text, 10, 25, 20, rl.White)
|
|
||||||
text = fmt.Sprintf("Default Mouse: [%.0f , %.0f]", mouse.X, mouse.Y)
|
|
||||||
rl.DrawText(text, 350, 25, 20, rl.Green)
|
|
||||||
text = fmt.Sprintf("Virtual Mouse: [%.0f , %.0f]", virtualMouse.X, virtualMouse.Y)
|
|
||||||
rl.DrawText(text, 350, 55, 20, rl.Yellow)
|
|
||||||
|
|
||||||
rl.EndTextureMode()
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
// Draw render texture to screen, properly scaled
|
|
||||||
rl.DrawTexturePro(
|
|
||||||
target.Texture,
|
|
||||||
rl.Rectangle{Width: float32(target.Texture.Width), Height: float32(-target.Texture.Height)},
|
|
||||||
rl.Rectangle{
|
|
||||||
X: (float32(rl.GetScreenWidth()) - float32(gameScreenWidth)*scale) * 0.5,
|
|
||||||
Y: (float32(rl.GetScreenHeight()) - float32(gameScreenHeight)*scale) * 0.5,
|
|
||||||
Width: float32(gameScreenWidth) * scale,
|
|
||||||
Height: float32(gameScreenHeight) * scale,
|
|
||||||
},
|
|
||||||
rl.Vector2{X: 0, Y: 0}, 0, rl.White,
|
|
||||||
)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
rl.UnloadRenderTexture(target)
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
||||||
|
|
||||||
func getRandomColors() []color.RGBA {
|
|
||||||
var colors []color.RGBA
|
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
|
||||||
randomColor := color.RGBA{
|
|
||||||
R: rndUint8(100, 250),
|
|
||||||
G: rndUint8(50, 150),
|
|
||||||
B: rndUint8(10, 100),
|
|
||||||
A: 255,
|
|
||||||
}
|
|
||||||
colors = append(colors, randomColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
return colors
|
|
||||||
}
|
|
||||||
|
|
||||||
func rndUint8(min, max int32) uint8 {
|
|
||||||
return uint8(rl.GetRandomValue(min, max))
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 850
|
|
||||||
screenHeight = 480
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close")
|
|
||||||
|
|
||||||
rl.SetExitKey(rl.KeyNull) // Disable KEY_ESCAPE to close window, X-button still works
|
|
||||||
|
|
||||||
exitWindowRequested := false // Flag to request window to exit
|
|
||||||
exitWindow := false // Flag to set window to exit
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
for !exitWindow {
|
|
||||||
if rl.WindowShouldClose() || rl.IsMouseButtonPressed(rl.KeyEscape) {
|
|
||||||
exitWindowRequested = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if exitWindowRequested {
|
|
||||||
if rl.IsKeyPressed(rl.KeyY) {
|
|
||||||
exitWindow = true
|
|
||||||
} else if rl.IsKeyPressed(rl.KeyN) {
|
|
||||||
exitWindowRequested = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
if exitWindowRequested {
|
|
||||||
rl.DrawRectangle(0, 100, screenWidth, 200, rl.Black)
|
|
||||||
rl.DrawText("Are you sure you want to exit the program? [Y/N]", 40, 180, 30, rl.White)
|
|
||||||
} else {
|
|
||||||
rl.DrawText("Try to close the window to get confirmation message!", 120, 200, 20, rl.LightGray)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -19,10 +19,12 @@ func main() {
|
||||||
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
cubePosition := rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
cubeScreenPosition := rl.Vector2{}
|
cubeScreenPosition := rl.Vector2{}
|
||||||
|
|
||||||
|
rl.SetCameraMode(camera, rl.CameraFree) // Set a free camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
rl.UpdateCamera(&camera, rl.CameraFree) // Update camera with free camera mode
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Calculate cube screen space position (with a little offset to be in top)
|
// Calculate cube screen space position (with a little offset to be in top)
|
||||||
cubeScreenPosition = rl.GetWorldToScreen(rl.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
cubeScreenPosition = rl.GetWorldToScreen(rl.NewVector3(cubePosition.X, cubePosition.Y+2.5, cubePosition.Z), camera)
|
||||||
|
|
Before Width: | Height: | Size: 244 KiB |
|
@ -1,11 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"github.com/gen2brain/raylib-go/easings"
|
||||||
|
"github.com/gen2brain/raylib-go/raygui"
|
||||||
"git.terah.dev/UnrealXR/raylib-go/easings"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -23,8 +21,8 @@ func main() {
|
||||||
|
|
||||||
ballPosition := rl.NewVector2(startPositionX, float32(screenHeight)/2)
|
ballPosition := rl.NewVector2(startPositionX, float32(screenHeight)/2)
|
||||||
|
|
||||||
comboActive := int32(0)
|
comboActive := 0
|
||||||
comboLastActive := int32(0)
|
comboLastActive := 0
|
||||||
|
|
||||||
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
|
easingTypes := []string{"SineIn", "SineOut", "SineInOut", "BounceIn", "BounceOut", "BounceInOut", "BackIn", "BackOut", "BackInOut"}
|
||||||
ease := easingTypes[comboActive]
|
ease := easingTypes[comboActive]
|
||||||
|
@ -77,7 +75,7 @@ func main() {
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
raygui.Label(rl.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
raygui.Label(rl.NewRectangle(20, 20, 200, 20), "Easing Type:")
|
||||||
comboActive = raygui.ComboBox(rl.NewRectangle(20, 40, 200, 20), strings.Join(easingTypes, ";"), comboActive)
|
comboActive = raygui.ComboBox(rl.NewRectangle(20, 40, 200, 20), easingTypes, comboActive)
|
||||||
|
|
||||||
raygui.Label(rl.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
raygui.Label(rl.NewRectangle(20, 80, 200, 20), "Press R to reset")
|
||||||
|
|
||||||
|
|
|
@ -1,277 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib - sample game: arkanoid
|
|
||||||
*
|
|
||||||
* Sample game Marc Palau and Ramon Santamaria
|
|
||||||
*
|
|
||||||
* This game has been created using raylib v1.3 (www.raylib.com)
|
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Ported to raylib-go by Nehpe (@nehpe), July 2019
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
PLAYER_MAX_LIFE = 5
|
|
||||||
LINES_OF_BRICKS = 5
|
|
||||||
BRICKS_PER_LINE = 20
|
|
||||||
)
|
|
||||||
|
|
||||||
type Player struct {
|
|
||||||
position rl.Vector2
|
|
||||||
size rl.Vector2
|
|
||||||
life int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Ball struct {
|
|
||||||
position rl.Vector2
|
|
||||||
speed rl.Vector2
|
|
||||||
radius float32
|
|
||||||
active bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Brick struct {
|
|
||||||
position rl.Vector2
|
|
||||||
active bool
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
type Game struct {
|
|
||||||
gameOver bool
|
|
||||||
pause bool
|
|
||||||
player Player
|
|
||||||
ball Ball
|
|
||||||
brick [LINES_OF_BRICKS][BRICKS_PER_LINE]Brick
|
|
||||||
brickSize rl.Vector2
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "sample game: arkanoid")
|
|
||||||
|
|
||||||
// Init game
|
|
||||||
game := NewGame()
|
|
||||||
game.gameOver = true
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
game.Update()
|
|
||||||
|
|
||||||
game.Draw()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// For android
|
|
||||||
func init() {
|
|
||||||
rl.SetCallbackFunc(main)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewGame - Create a new game instance
|
|
||||||
func NewGame() (g Game) {
|
|
||||||
g.Init()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init - initialize game
|
|
||||||
func (g *Game) Init() {
|
|
||||||
g.brickSize = rl.Vector2{float32(rl.GetScreenWidth() / BRICKS_PER_LINE), 40}
|
|
||||||
|
|
||||||
// Initialize player
|
|
||||||
g.player.position = rl.Vector2{float32(screenWidth / 2), float32(screenHeight * 7 / 8)}
|
|
||||||
g.player.size = rl.Vector2{float32(screenWidth / 10), 20}
|
|
||||||
g.player.life = PLAYER_MAX_LIFE
|
|
||||||
|
|
||||||
// Initialize ball
|
|
||||||
g.ball.position = rl.Vector2{float32(screenWidth / 2), float32(screenHeight*7/8 - 30)}
|
|
||||||
g.ball.speed = rl.Vector2{0, 0}
|
|
||||||
g.ball.radius = 7
|
|
||||||
g.ball.active = false
|
|
||||||
|
|
||||||
initialDownPosition := int(50)
|
|
||||||
|
|
||||||
for i := 0; i < LINES_OF_BRICKS; i++ {
|
|
||||||
for j := 0; j < BRICKS_PER_LINE; j++ {
|
|
||||||
g.brick[i][j].position = rl.Vector2{float32(j)*g.brickSize.X + g.brickSize.X/2, float32(i)*g.brickSize.Y + float32(initialDownPosition)}
|
|
||||||
g.brick[i][j].active = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update - update game state
|
|
||||||
func (g *Game) Update() {
|
|
||||||
if !g.gameOver {
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyP) {
|
|
||||||
g.pause = !g.pause
|
|
||||||
}
|
|
||||||
|
|
||||||
if !g.pause {
|
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyLeft) || rl.IsKeyDown(rl.KeyA) {
|
|
||||||
g.player.position.X -= 5
|
|
||||||
}
|
|
||||||
if (g.player.position.X - g.player.size.X/2) <= 0 {
|
|
||||||
g.player.position.X = g.player.size.X / 2
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyRight) || rl.IsKeyDown(rl.KeyD) {
|
|
||||||
g.player.position.X += 5
|
|
||||||
}
|
|
||||||
if (g.player.position.X + g.player.size.X/2) >= screenWidth {
|
|
||||||
g.player.position.X = screenWidth - g.player.size.X/2
|
|
||||||
}
|
|
||||||
|
|
||||||
if !g.ball.active {
|
|
||||||
if rl.IsKeyPressed(rl.KeySpace) {
|
|
||||||
g.ball.active = true
|
|
||||||
g.ball.speed = rl.Vector2{0, -5}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if g.ball.active {
|
|
||||||
g.ball.position.X += g.ball.speed.X
|
|
||||||
g.ball.position.Y += g.ball.speed.Y
|
|
||||||
} else {
|
|
||||||
g.ball.position = rl.Vector2{g.player.position.X, screenHeight*7/8 - 30}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collision logic: ball vs walls
|
|
||||||
if ((g.ball.position.X + g.ball.radius) >= screenWidth) || ((g.ball.position.X - g.ball.radius) <= 0) {
|
|
||||||
g.ball.speed.X *= -1
|
|
||||||
}
|
|
||||||
if (g.ball.position.Y - g.ball.radius) <= 0 {
|
|
||||||
g.ball.speed.Y *= -1
|
|
||||||
}
|
|
||||||
if (g.ball.position.Y + g.ball.radius) >= screenHeight {
|
|
||||||
g.ball.speed = rl.Vector2{0, 0}
|
|
||||||
g.ball.active = false
|
|
||||||
|
|
||||||
g.player.life--
|
|
||||||
}
|
|
||||||
if (rl.CheckCollisionCircleRec(g.ball.position, g.ball.radius,
|
|
||||||
rl.Rectangle{g.player.position.X - g.player.size.X/2, g.player.position.Y - g.player.size.Y/2, g.player.size.X, g.player.size.Y})) {
|
|
||||||
if g.ball.speed.Y > 0 {
|
|
||||||
g.ball.speed.Y *= -1
|
|
||||||
g.ball.speed.X = (g.ball.position.X - g.player.position.X) / (g.player.size.X / 2) * 5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Collision logic: ball vs bricks
|
|
||||||
for i := 0; i < LINES_OF_BRICKS; i++ {
|
|
||||||
for j := 0; j < BRICKS_PER_LINE; j++ {
|
|
||||||
if g.brick[i][j].active {
|
|
||||||
if ((g.ball.position.Y - g.ball.radius) <= (g.brick[i][j].position.Y + g.brickSize.Y/2)) &&
|
|
||||||
((g.ball.position.Y - g.ball.radius) > (g.brick[i][j].position.Y + g.brickSize.Y/2 + g.ball.speed.Y)) &&
|
|
||||||
((float32(math.Abs(float64(g.ball.position.X - g.brick[i][j].position.X)))) < (g.brickSize.X/2 + g.ball.radius*2/3)) &&
|
|
||||||
(g.ball.speed.Y < 0) {
|
|
||||||
// Hit below
|
|
||||||
g.brick[i][j].active = false
|
|
||||||
g.ball.speed.Y *= -1
|
|
||||||
} else if ((g.ball.position.Y + g.ball.radius) >= (g.brick[i][j].position.Y - g.brickSize.Y/2)) &&
|
|
||||||
((g.ball.position.Y + g.ball.radius) < (g.brick[i][j].position.Y - g.brickSize.Y/2 + g.ball.speed.Y)) &&
|
|
||||||
((float32(math.Abs(float64(g.ball.position.X - g.brick[i][j].position.X)))) < (g.brickSize.X/2 + g.ball.radius*2/3)) &&
|
|
||||||
(g.ball.speed.Y > 0) {
|
|
||||||
// Hit above
|
|
||||||
g.brick[i][j].active = false
|
|
||||||
g.ball.speed.Y *= -1
|
|
||||||
} else if ((g.ball.position.X + g.ball.radius) >= (g.brick[i][j].position.X - g.brickSize.X/2)) &&
|
|
||||||
((g.ball.position.X + g.ball.radius) < (g.brick[i][j].position.X - g.brickSize.X/2 + g.ball.speed.X)) &&
|
|
||||||
((float32(math.Abs(float64(g.ball.position.Y - g.brick[i][j].position.Y)))) < (g.brickSize.Y/2 + g.ball.radius*2/3)) &&
|
|
||||||
(g.ball.speed.X > 0) {
|
|
||||||
// Hit left
|
|
||||||
g.brick[i][j].active = false
|
|
||||||
g.ball.speed.X *= -1
|
|
||||||
} else if ((g.ball.position.X - g.ball.radius) <= (g.brick[i][j].position.X + g.brickSize.X/2)) &&
|
|
||||||
((g.ball.position.X - g.ball.radius) > (g.brick[i][j].position.X + g.brickSize.X/2 + g.ball.speed.X)) &&
|
|
||||||
((float32(math.Abs(float64(g.ball.position.Y - g.brick[i][j].position.Y)))) < (g.brickSize.Y/2 + g.ball.radius*2/3)) &&
|
|
||||||
(g.ball.speed.X < 0) {
|
|
||||||
// Hit right
|
|
||||||
g.brick[i][j].active = false
|
|
||||||
g.ball.speed.X *= -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Game over logic
|
|
||||||
if g.player.life <= 0 {
|
|
||||||
g.gameOver = true
|
|
||||||
} else {
|
|
||||||
g.gameOver = true
|
|
||||||
|
|
||||||
for i := 0; i < LINES_OF_BRICKS; i++ {
|
|
||||||
for j := 0; j < BRICKS_PER_LINE; j++ {
|
|
||||||
if g.brick[i][j].active {
|
|
||||||
g.gameOver = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if rl.IsKeyPressed(rl.KeyEnter) {
|
|
||||||
g.Init()
|
|
||||||
g.gameOver = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw - draw game
|
|
||||||
func (g *Game) Draw() {
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.White)
|
|
||||||
|
|
||||||
if !g.gameOver {
|
|
||||||
// Draw player bar
|
|
||||||
rl.DrawRectangle(int32(g.player.position.X-g.player.size.X/2), int32(g.player.position.Y-g.player.size.Y/2), int32(g.player.size.X), int32(g.player.size.Y), rl.Black)
|
|
||||||
|
|
||||||
// Draw player lives
|
|
||||||
for i := 0; i < g.player.life; i++ {
|
|
||||||
rl.DrawRectangle(int32(20+40*i), screenHeight-30, 35, 10, rl.LightGray)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw Ball
|
|
||||||
rl.DrawCircleV(g.ball.position, g.ball.radius, rl.Maroon)
|
|
||||||
|
|
||||||
for i := 0; i < LINES_OF_BRICKS; i++ {
|
|
||||||
for j := 0; j < BRICKS_PER_LINE; j++ {
|
|
||||||
if g.brick[i][j].active {
|
|
||||||
if (i+j)%2 == 0 {
|
|
||||||
rl.DrawRectangle(int32(g.brick[i][j].position.X-g.brickSize.X/2), int32(g.brick[i][j].position.Y-g.brickSize.Y/2), int32(g.brickSize.X), int32(g.brickSize.Y), rl.Gray)
|
|
||||||
} else {
|
|
||||||
rl.DrawRectangle(int32(g.brick[i][j].position.X-g.brickSize.X/2), int32(g.brick[i][j].position.Y-g.brickSize.Y/2), int32(g.brickSize.X), int32(g.brickSize.Y), rl.DarkGray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if g.pause {
|
|
||||||
rl.DrawText("GAME PAUSED", screenWidth/2-rl.MeasureText("GAME PAUSED", 40)/2, screenHeight/2+screenHeight/4-40, 40, rl.Gray)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
str := "PRESS [ENTER] TO PLAY AGAIN"
|
|
||||||
x := int(rl.GetScreenWidth()/2) - int(rl.MeasureText(str, 20)/2)
|
|
||||||
y := rl.GetScreenHeight()/2 - 50
|
|
||||||
rl.DrawText(str, int32(x), int32(y), 20, rl.Gray)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -32,7 +32,7 @@ type Game struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano()))
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
game := Game{}
|
game := Game{}
|
||||||
game.Init(false)
|
game.Init(false)
|
||||||
|
|
|
@ -1,174 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Game settings
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 600
|
|
||||||
)
|
|
||||||
|
|
||||||
// Paddle struct
|
|
||||||
type Paddle struct {
|
|
||||||
Pos rl.Vector2
|
|
||||||
Width float32
|
|
||||||
Height float32
|
|
||||||
Speed float32
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ball struct
|
|
||||||
type Ball struct {
|
|
||||||
Pos rl.Vector2
|
|
||||||
Speed rl.Vector2
|
|
||||||
Radius float32
|
|
||||||
}
|
|
||||||
|
|
||||||
// Game struct
|
|
||||||
type Game struct {
|
|
||||||
paddle1 Paddle
|
|
||||||
paddle2 Paddle
|
|
||||||
ball Ball
|
|
||||||
player1Score int
|
|
||||||
player2Score int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for collision between ball and paddle, and determine side
|
|
||||||
func CheckCollisionSide(ball Ball, paddle Paddle) string {
|
|
||||||
closestX := rl.Clamp(ball.Pos.X, paddle.Pos.X, paddle.Pos.X+paddle.Width)
|
|
||||||
closestY := rl.Clamp(ball.Pos.Y, paddle.Pos.Y, paddle.Pos.Y+paddle.Height)
|
|
||||||
|
|
||||||
dx := ball.Pos.X - closestX
|
|
||||||
dy := ball.Pos.Y - closestY
|
|
||||||
|
|
||||||
distanceSq := dx*dx + dy*dy
|
|
||||||
radiusSq := ball.Radius * ball.Radius
|
|
||||||
|
|
||||||
if distanceSq <= radiusSq {
|
|
||||||
// Determine where it hit
|
|
||||||
if closestX == paddle.Pos.X || closestX == paddle.Pos.X+paddle.Width {
|
|
||||||
return "side"
|
|
||||||
}
|
|
||||||
if closestY == paddle.Pos.Y || closestY == paddle.Pos.Y+paddle.Height {
|
|
||||||
return "topbottom"
|
|
||||||
}
|
|
||||||
return "side" // fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
return "none"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize the game state
|
|
||||||
func (g *Game) Init() {
|
|
||||||
g.paddle1 = Paddle{
|
|
||||||
Pos: rl.NewVector2(30, float32(screenHeight/2-50)),
|
|
||||||
Width: 10,
|
|
||||||
Height: 100,
|
|
||||||
Speed: 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
g.paddle2 = Paddle{
|
|
||||||
Pos: rl.NewVector2(float32(screenWidth-40), float32(screenHeight/2-50)),
|
|
||||||
Width: 10,
|
|
||||||
Height: 100,
|
|
||||||
Speed: 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
g.ball = Ball{
|
|
||||||
Pos: rl.NewVector2(float32(screenWidth/2), float32(screenHeight/2)),
|
|
||||||
Speed: rl.NewVector2(5, 4),
|
|
||||||
Radius: 10,
|
|
||||||
}
|
|
||||||
|
|
||||||
g.player1Score = 0
|
|
||||||
g.player2Score = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Game update logic
|
|
||||||
func (g *Game) Update() {
|
|
||||||
// Player 1 - W/S
|
|
||||||
if rl.IsKeyDown(rl.KeyW) && g.paddle1.Pos.Y > 0 {
|
|
||||||
g.paddle1.Pos.Y -= g.paddle1.Speed
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyS) && g.paddle1.Pos.Y < screenHeight-g.paddle1.Height {
|
|
||||||
g.paddle1.Pos.Y += g.paddle1.Speed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Player 2 - Up/Down
|
|
||||||
if rl.IsKeyDown(rl.KeyUp) && g.paddle2.Pos.Y > 0 {
|
|
||||||
g.paddle2.Pos.Y -= g.paddle2.Speed
|
|
||||||
}
|
|
||||||
if rl.IsKeyDown(rl.KeyDown) && g.paddle2.Pos.Y < screenHeight-g.paddle2.Height {
|
|
||||||
g.paddle2.Pos.Y += g.paddle2.Speed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ball movement
|
|
||||||
g.ball.Pos.X += g.ball.Speed.X
|
|
||||||
g.ball.Pos.Y += g.ball.Speed.Y
|
|
||||||
|
|
||||||
// Ball bounce off top/bottom walls
|
|
||||||
if g.ball.Pos.Y <= g.ball.Radius || g.ball.Pos.Y >= float32(screenHeight)-g.ball.Radius {
|
|
||||||
g.ball.Speed.Y *= -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ball collisions with paddle sides only
|
|
||||||
if CheckCollisionSide(g.ball, g.paddle1) == "side" {
|
|
||||||
g.ball.Speed.X *= -1
|
|
||||||
// Reposition ball outside paddle1
|
|
||||||
g.ball.Pos.X = g.paddle1.Pos.X + g.paddle1.Width + g.ball.Radius
|
|
||||||
}
|
|
||||||
|
|
||||||
if CheckCollisionSide(g.ball, g.paddle2) == "side" {
|
|
||||||
g.ball.Speed.X *= -1
|
|
||||||
// Reposition ball outside paddle2
|
|
||||||
g.ball.Pos.X = g.paddle2.Pos.X - g.ball.Radius
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scoring
|
|
||||||
if g.ball.Pos.X < 0 {
|
|
||||||
g.player2Score++
|
|
||||||
g.ball.Pos = rl.NewVector2(float32(screenWidth/2), float32(screenHeight/2))
|
|
||||||
g.ball.Speed.X *= -1
|
|
||||||
}
|
|
||||||
if g.ball.Pos.X > float32(screenWidth) {
|
|
||||||
g.player1Score++
|
|
||||||
g.ball.Pos = rl.NewVector2(float32(screenWidth/2), float32(screenHeight/2))
|
|
||||||
g.ball.Speed.X *= -1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw game elements
|
|
||||||
func (g *Game) Draw() {
|
|
||||||
// Draw paddles
|
|
||||||
rl.DrawRectangleV(g.paddle1.Pos, rl.NewVector2(g.paddle1.Width, g.paddle1.Height), rl.Black)
|
|
||||||
rl.DrawRectangleV(g.paddle2.Pos, rl.NewVector2(g.paddle2.Width, g.paddle2.Height), rl.Black)
|
|
||||||
|
|
||||||
// Draw ball
|
|
||||||
rl.DrawCircleV(g.ball.Pos, g.ball.Radius, rl.Black)
|
|
||||||
|
|
||||||
// Draw scores
|
|
||||||
rl.DrawText(fmt.Sprintf("Player 1 : %d", g.player1Score), 20, 20, 20, rl.DarkGray)
|
|
||||||
rl.DrawText(fmt.Sprintf("Player 2 : %d", g.player2Score), screenWidth-140, 20, 20, rl.DarkGray)
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "Pong in Go!")
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
var game Game
|
|
||||||
game.Init()
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
game.Update()
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
game.Draw()
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
snakeLength = 256
|
snakeLength = 256
|
||||||
squareSize = 31
|
squareSize = 31
|
||||||
|
@ -156,15 +160,15 @@ func (g *Game) Update() {
|
||||||
if !g.Fruit.Active {
|
if !g.Fruit.Active {
|
||||||
g.Fruit.Active = true
|
g.Fruit.Active = true
|
||||||
g.Fruit.Position = rl.NewVector2(
|
g.Fruit.Position = rl.NewVector2(
|
||||||
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize)+(g.Offset.X)/2,
|
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize+int32(g.Offset.X)/2),
|
||||||
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize)+(g.Offset.Y)/2,
|
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize+int32(g.Offset.Y)/2),
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < g.CounterTail; i++ {
|
for i := 0; i < g.CounterTail; i++ {
|
||||||
for (g.Fruit.Position.X == g.Snake[i].Position.X) && (g.Fruit.Position.Y == g.Snake[i].Position.Y) {
|
for (g.Fruit.Position.X == g.Snake[i].Position.X) && (g.Fruit.Position.Y == g.Snake[i].Position.Y) {
|
||||||
g.Fruit.Position = rl.NewVector2(
|
g.Fruit.Position = rl.NewVector2(
|
||||||
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize)+g.Offset.X/2,
|
float32(rl.GetRandomValue(0, (g.ScreenWidth/squareSize)-1)*squareSize),
|
||||||
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize)+g.Offset.Y/2,
|
float32(rl.GetRandomValue(0, (g.ScreenHeight/squareSize)-1)*squareSize),
|
||||||
)
|
)
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
module examples
|
|
||||||
|
|
||||||
go 1.21
|
|
||||||
|
|
||||||
replace git.terah.dev/UnrealXR/raylib-go/raylib => ../raylib
|
|
||||||
|
|
||||||
replace git.terah.dev/UnrealXR/raylib-go/raygui => ../raygui
|
|
||||||
|
|
||||||
replace git.terah.dev/UnrealXR/raylib-go/easings => ../easings
|
|
||||||
|
|
||||||
replace git.terah.dev/UnrealXR/raylib-go/physics => ../physics
|
|
||||||
|
|
||||||
require (
|
|
||||||
git.terah.dev/UnrealXR/raylib-go/easings v0.0.0-00010101000000-000000000000
|
|
||||||
git.terah.dev/UnrealXR/raylib-go/physics v0.0.0-00010101000000-000000000000
|
|
||||||
git.terah.dev/UnrealXR/raylib-go/raygui v0.0.0-00010101000000-000000000000
|
|
||||||
git.terah.dev/UnrealXR/raylib-go/raylib v0.0.0-20241202103652-5d50abe7c65b
|
|
||||||
github.com/jakecoffman/cp v1.2.1
|
|
||||||
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/ebitengine/purego v0.8.1 // indirect
|
|
||||||
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
|
|
||||||
golang.org/x/sys v0.27.0 // indirect
|
|
||||||
)
|
|
|
@ -1,10 +0,0 @@
|
||||||
github.com/ebitengine/purego v0.8.1 h1:sdRKd6plj7KYW33EH5As6YKfe8m9zbN9JMrOjNVF/BE=
|
|
||||||
github.com/ebitengine/purego v0.8.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
|
|
||||||
github.com/jakecoffman/cp v1.2.1 h1:zkhc2Gpo9l4NLUZfeG3j33+3bQD7MkqPa+n5PdX+5mI=
|
|
||||||
github.com/jakecoffman/cp v1.2.1/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
|
||||||
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b h1:+67TGbwfgeB5o03Rx+ZBW44zAQ+wUujcwdRA0p9CbJI=
|
|
||||||
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b/go.mod h1:kvKwD9codtns5mvpA53V3vLnqFb/Ahcu8zgkGM0SIbI=
|
|
||||||
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
|
|
||||||
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
|
|
||||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
|
||||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
92
examples/gui/basic_controls/main.go
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gen2brain/raylib-go/raygui"
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
screenWidth := int32(800)
|
||||||
|
screenHeight := int32(450)
|
||||||
|
|
||||||
|
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||||
|
|
||||||
|
rl.InitWindow(screenWidth, screenHeight, "raylib [gui] example - basic controls")
|
||||||
|
|
||||||
|
buttonToggle := true
|
||||||
|
buttonClicked := false
|
||||||
|
checkboxChecked := false
|
||||||
|
|
||||||
|
spinnerValue := 5
|
||||||
|
sliderValue := float32(10)
|
||||||
|
sliderBarValue := float32(70)
|
||||||
|
progressValue := float32(0.5)
|
||||||
|
|
||||||
|
comboActive := 0
|
||||||
|
comboLastActive := 0
|
||||||
|
toggleActive := 0
|
||||||
|
|
||||||
|
toggleText := []string{"Item 1", "Item 2", "Item 3"}
|
||||||
|
comboText := []string{"default_light", "default_dark", "hello_kitty", "monokai", "obsidian", "solarized_light", "solarized", "zahnrad"}
|
||||||
|
|
||||||
|
var inputText string
|
||||||
|
|
||||||
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
|
for !rl.WindowShouldClose() {
|
||||||
|
if buttonClicked {
|
||||||
|
progressValue += 0.1
|
||||||
|
if progressValue >= 1.1 {
|
||||||
|
progressValue = 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.BeginDrawing()
|
||||||
|
|
||||||
|
rl.ClearBackground(rl.Beige)
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(50, 50, 80, 20), "Label")
|
||||||
|
|
||||||
|
buttonClicked = raygui.Button(rl.NewRectangle(50, 70, 80, 40), "Button")
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(70, 140, 20, 20), "Checkbox")
|
||||||
|
checkboxChecked = raygui.CheckBox(rl.NewRectangle(50, 140, 20, 20), checkboxChecked)
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(50, 190, 200, 20), "ProgressBar")
|
||||||
|
raygui.ProgressBar(rl.NewRectangle(50, 210, 200, 20), progressValue)
|
||||||
|
raygui.Label(rl.NewRectangle(200+50+5, 210, 20, 20), fmt.Sprintf("%.1f", progressValue))
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(50, 260, 200, 20), "Slider")
|
||||||
|
sliderValue = raygui.Slider(rl.NewRectangle(50, 280, 200, 20), sliderValue, 0, 100)
|
||||||
|
raygui.Label(rl.NewRectangle(200+50+5, 280, 20, 20), fmt.Sprintf("%.0f", sliderValue))
|
||||||
|
|
||||||
|
buttonToggle = raygui.ToggleButton(rl.NewRectangle(50, 350, 100, 40), "ToggleButton", buttonToggle)
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(500, 50, 200, 20), "ToggleGroup")
|
||||||
|
toggleActive = raygui.ToggleGroup(rl.NewRectangle(500, 70, 60, 30), toggleText, toggleActive)
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(500, 120, 200, 20), "SliderBar")
|
||||||
|
sliderBarValue = raygui.SliderBar(rl.NewRectangle(500, 140, 200, 20), sliderBarValue, 0, 100)
|
||||||
|
raygui.Label(rl.NewRectangle(500+200+5, 140, 20, 20), fmt.Sprintf("%.0f", sliderBarValue))
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(500, 190, 200, 20), "Spinner")
|
||||||
|
spinnerValue = raygui.Spinner(rl.NewRectangle(500, 210, 200, 20), spinnerValue, 0, 100)
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(500, 260, 200, 20), "ComboBox")
|
||||||
|
comboActive = raygui.ComboBox(rl.NewRectangle(500, 280, 200, 20), comboText, comboActive)
|
||||||
|
|
||||||
|
if comboLastActive != comboActive {
|
||||||
|
raygui.LoadGuiStyle(fmt.Sprintf("styles/%s.style", comboText[comboActive]))
|
||||||
|
comboLastActive = comboActive
|
||||||
|
}
|
||||||
|
|
||||||
|
raygui.Label(rl.NewRectangle(500, 330, 200, 20), "TextBox")
|
||||||
|
inputText = raygui.TextBox(rl.NewRectangle(500, 350, 200, 20), inputText)
|
||||||
|
|
||||||
|
rl.EndDrawing()
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.CloseWindow()
|
||||||
|
}
|
99
examples/gui/basic_controls/styles/default_dark.style
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
GLOBAL_BASE_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_BORDER_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0x293235ff
|
||||||
|
LINES_COLOR 0x90abb5ff
|
||||||
|
LABEL_BORDER_WIDTH 0x0
|
||||||
|
LABEL_TEXT_COLOR 0x90acb4ff
|
||||||
|
LABEL_TEXT_PADDING 0x0
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x0
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x3e4a4fff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0x344041ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0x90acb4ff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x47595fff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0x334f59ff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0x90acb4ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x5f9aa4ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0x334f59ff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x20
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x3e4b4dff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0x344041ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0x828282ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x47595fff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0x334f59ff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0x828282ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x5f9aa8ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0x334f59ff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x92c763ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0x334f59ff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0x92c763ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x0
|
||||||
|
SLIDER_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDER_INSIDE_COLOR 0x3e4b4dff
|
||||||
|
SLIDER_DEFAULT_COLOR 0x92c763ff
|
||||||
|
SLIDER_HOVER_COLOR 0xc3e0a9ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0xffffffff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0x344041ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0x92c763ff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0xc3e0a9ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0xffffffff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0x3e4b4dff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0x92c763ff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x1
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x3e4b4dff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0x344041ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x3e4b4dff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0x344041ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0x5f9aa8ff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x47595fff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0x334f59ff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0x5f9aa8ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x92c763ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0x334f59ff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0x92c763ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0x92c763ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x30
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x20
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x3e4b4dff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0x344041ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x47595fff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0x334f59ff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0x334f59ff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0x5f9aa8ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x92c763ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x334f59ff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0x92c763ff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x47595fff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0x344041ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x47595fff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0x334f59ff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x5f9aa8ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0x334f59ff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0x92c763ff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x2
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x47595fff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0x828282ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xff
|
||||||
|
TEXTBOX_LINE_COLOR 0xff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
99
examples/gui/basic_controls/styles/default_light.style
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
GLOBAL_BASE_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_BORDER_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xf5f5f5ff
|
||||||
|
LINES_COLOR 0x90abb5ff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0x4d4d4dff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0x4d4d4dff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0x868686ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0xbcecffff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0x5f9aa7ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0x828282ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0x828282ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0xbdd7eaff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0xddf5ffff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xafccd3ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0xbcecffff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0x5f9aa7ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDER_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0xbcecffff
|
||||||
|
SLIDER_HOVER_COLOR 0xffffffff
|
||||||
|
SLIDER_ACTIVE_COLOR 0xddf5ffff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0xbcecffff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0xffffffff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0xddf5ffff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0xbcecffff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x828282ff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x828282ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0xff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0xff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0xffffffff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0xff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0xff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0xbcecffff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0x5f9aa7ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x14
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0xc8c8c8ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0x828282ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0x828282ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0x828282ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0x828282ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0xbcecffff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0x5f9aa7ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x78acff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x66e7ffff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0x78acff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x66e7ffff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0xddf5ffff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0xbcecffff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x828282ff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0xf5f5f5ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xff
|
||||||
|
TEXTBOX_LINE_COLOR 0xff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/hello_kitty.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0xff80c1ff
|
||||||
|
GLOBAL_BORDER_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_COLOR 0x650065ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xffd4eaff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0x650065ff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0x650065ff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0x761c76ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0xffb8dcff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0xa971a9ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0x650065ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0x761c76ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0xbdd7eaff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0xffb8dcff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xa971a9ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0xff8ec7ff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xa971a9ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDER_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0xffaad5ff
|
||||||
|
SLIDER_HOVER_COLOR 0xff9cceff
|
||||||
|
SLIDER_ACTIVE_COLOR 0xff80c1ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0xffaad5ff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0xff9cceff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0xff80c1ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0xff8ec7ff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0xffaad5ff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x828282ff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x828282ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0x650065ff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0x650065ff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0x761c76ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0x761c76ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0xffb8dcff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0xa971a9ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xa971a9ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0x650065ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0x650065ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0x761c76ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0x761c76ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x7bb0d6ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0xff8ec7ff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0xba8dbaff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x78acff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0xff8ec7ff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0xba8dbaff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x828282ff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0xc8c8c8ff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x66e7ffff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0xffaad5ff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0xff8ec7ff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x4
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x828282ff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0xffc6e3ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0x650065ff
|
||||||
|
TEXTBOX_LINE_COLOR 0x985598ff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/monokai.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0x262921ff
|
||||||
|
GLOBAL_BORDER_COLOR 0x102ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xb6b7b5ff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0x868883ff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0x868883ff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0x3e4039ff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDER_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
SLIDER_DEFAULT_COLOR 0x6e706bff
|
||||||
|
SLIDER_HOVER_COLOR 0x565852ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0x262921ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0x6e706bff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0x565852ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0x262921ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0x3e4039ff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x38393aff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0x6e706bff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0xf8f8f1ff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x1c1d1eff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0xf8f8f2ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x102ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0x868883ff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0xfbfbf7ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0x3e4039ff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0xfbfbf8ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x3e4039ff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0xfbfbf8ff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x102ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0x6e706bff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0x3e4039ff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x4
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x38393aff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0x9e9f9cff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
TEXTBOX_LINE_COLOR 0xfafaf5ff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/obsidian.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0x293034ff
|
||||||
|
GLOBAL_BORDER_COLOR 0x102ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xa8e2aeff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xb7babbff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0xa8e2aeff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0xa8e2aeff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0xb1e5b7ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0x888c8eff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0xceeed2ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0xa8e2aeff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0xb1e5b7ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0x888c8eff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xceeed2ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0x40474aff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xceeed2ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDER_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0x707577ff
|
||||||
|
SLIDER_HOVER_COLOR 0x585e61ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0x293034ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0x707577ff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0x585e61ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0x293034ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0x40474aff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x38393aff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0x707577ff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0xa8e2aeff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0xa8e2aeff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x1c1d1eff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0xb1e5b7ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0xb1e5b7ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x102ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0x888c8eff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0xceeed2ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xceeed2ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0xa8e2aeff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0xa8e2aeff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0xb1e5b7ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0xb1e5b7ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0x40474aff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0xd8f2dbff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x40474aff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0xd8f2dbff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x102ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0x707577ff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0x40474aff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x4
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x38393aff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0x9fa3a4ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xa8e2aeff
|
||||||
|
TEXTBOX_LINE_COLOR 0xc5ebc9ff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/solarized.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0x2b36ff
|
||||||
|
GLOBAL_BORDER_COLOR 0x102ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xaab8bcff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0x71898fff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0x71898fff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0x1c424cff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDER_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0x557179ff
|
||||||
|
SLIDER_HOVER_COLOR 0x385a62ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0x2b36ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0x557179ff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0x385a62ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0x2b36ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0x1c424cff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x38393aff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0x557179ff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0xf8f8f1ff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x1c1d1eff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0xf8f8f2ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x102ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0x71898fff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0xfbfbf7ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xfbfbf7ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0xf8f8f2ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0x1c424cff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0xfbfbf8ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x1c424cff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0xfbfbf8ff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x102ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0x557179ff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0x1c424cff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x4
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x38393aff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0x8da0a5ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xf8f8f1ff
|
||||||
|
TEXTBOX_LINE_COLOR 0xfafaf5ff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/solarized_light.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0xfcf6e3ff
|
||||||
|
GLOBAL_BORDER_COLOR 0x102ff
|
||||||
|
GLOBAL_TEXT_COLOR 0x657b82ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0xfefcf5ff
|
||||||
|
LABEL_BORDER_WIDTH 0x1
|
||||||
|
LABEL_TEXT_COLOR 0x657b82ff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x2
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0x657b82ff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0x76898fff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0xfdfaefff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0xa9b5b9ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0x657b82ff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0x76898fff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0xfdfaefff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0xa9b5b9ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0x102ff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0xfcf7e6ff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xa9b5b9ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x1
|
||||||
|
SLIDER_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDER_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0xfdf9ecff
|
||||||
|
SLIDER_HOVER_COLOR 0xfcf8e9ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0xfcf6e3ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x38393aff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0xfdf9ecff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0xfcf8e9ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0xfcf6e3ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0xfcf7e6ff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x38393aff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0xfdf9ecff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x2
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x38393aff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0x657b82ff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0x657b82ff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x1c1d1eff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0x76898fff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0x76898fff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x102ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0xfdfaefff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0xa9b5b9ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0xa9b5b9ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0x657b82ff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0x657b82ff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0x76898fff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0x76898fff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0xfcf7e6ff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0xbac4c7ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x102ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0xfcf7e6ff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0xbac4c7ff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x38393aff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x1c1d1eff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0xffffffff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x102ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0xfdf9ecff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0xfcf7e6ff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x4
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x38393aff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0xfdfbf2ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0x657b82ff
|
||||||
|
TEXTBOX_LINE_COLOR 0x98a7abff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0xa
|
98
examples/gui/basic_controls/styles/zahnrad.style
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
GLOBAL_BASE_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_BORDER_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_COLOR 0xf5f5f5ff
|
||||||
|
GLOBAL_TEXT_FONTSIZE 0xa
|
||||||
|
GLOBAL_BORDER_WIDTH 0x1
|
||||||
|
BACKGROUND_COLOR 0x2d2d2dff
|
||||||
|
LABEL_BORDER_WIDTH 0x2
|
||||||
|
LABEL_TEXT_COLOR 0xafafafff
|
||||||
|
LABEL_TEXT_PADDING 0x14
|
||||||
|
BUTTON_BORDER_WIDTH 0x1
|
||||||
|
BUTTON_TEXT_PADDING 0x14
|
||||||
|
BUTTON_DEFAULT_BORDER_COLOR 0x414141ff
|
||||||
|
BUTTON_DEFAULT_INSIDE_COLOR 0x323232ff
|
||||||
|
BUTTON_DEFAULT_TEXT_COLOR 0xafafafff
|
||||||
|
BUTTON_HOVER_BORDER_COLOR 0x3e3e3eff
|
||||||
|
BUTTON_HOVER_INSIDE_COLOR 0x2d2d2dff
|
||||||
|
BUTTON_HOVER_TEXT_COLOR 0x767472ff
|
||||||
|
BUTTON_PRESSED_BORDER_COLOR 0x414141ff
|
||||||
|
BUTTON_PRESSED_INSIDE_COLOR 0x323232ff
|
||||||
|
BUTTON_PRESSED_TEXT_COLOR 0x616161ff
|
||||||
|
TOGGLE_TEXT_PADDING 0x14
|
||||||
|
TOGGLE_BORDER_WIDTH 0x1
|
||||||
|
TOGGLE_DEFAULT_BORDER_COLOR 0x414141ff
|
||||||
|
TOGGLE_DEFAULT_INSIDE_COLOR 0x323232ff
|
||||||
|
TOGGLE_DEFAULT_TEXT_COLOR 0xafafafff
|
||||||
|
TOGGLE_HOVER_BORDER_COLOR 0x3e3e3eff
|
||||||
|
TOGGLE_HOVER_INSIDE_COLOR 0x2d2d2dff
|
||||||
|
TOGGLE_HOVER_TEXT_COLOR 0x767472ff
|
||||||
|
TOGGLE_PRESSED_BORDER_COLOR 0x414141ff
|
||||||
|
TOGGLE_PRESSED_INSIDE_COLOR 0x323232ff
|
||||||
|
TOGGLE_PRESSED_TEXT_COLOR 0x616161ff
|
||||||
|
TOGGLE_ACTIVE_BORDER_COLOR 0xafafafff
|
||||||
|
TOGGLE_ACTIVE_INSIDE_COLOR 0x414141ff
|
||||||
|
TOGGLE_ACTIVE_TEXT_COLOR 0xa3a3a3ff
|
||||||
|
TOGGLEGROUP_PADDING 0x3
|
||||||
|
SLIDER_BORDER_WIDTH 0x0
|
||||||
|
SLIDER_BUTTON_BORDER_WIDTH 0x0
|
||||||
|
SLIDER_BORDER_COLOR 0x414141ff
|
||||||
|
SLIDER_INSIDE_COLOR 0x232525ff
|
||||||
|
SLIDER_DEFAULT_COLOR 0x646464ff
|
||||||
|
SLIDER_HOVER_COLOR 0x767472ff
|
||||||
|
SLIDER_ACTIVE_COLOR 0x929291ff
|
||||||
|
SLIDERBAR_BORDER_COLOR 0x828282ff
|
||||||
|
SLIDERBAR_INSIDE_COLOR 0x262626ff
|
||||||
|
SLIDERBAR_DEFAULT_COLOR 0x616161ff
|
||||||
|
SLIDERBAR_HOVER_COLOR 0x646464ff
|
||||||
|
SLIDERBAR_ACTIVE_COLOR 0x929292ff
|
||||||
|
SLIDERBAR_ZERO_LINE_COLOR 0xafafafff
|
||||||
|
PROGRESSBAR_BORDER_COLOR 0x828282ff
|
||||||
|
PROGRESSBAR_INSIDE_COLOR 0x262626ff
|
||||||
|
PROGRESSBAR_PROGRESS_COLOR 0x646464ff
|
||||||
|
PROGRESSBAR_BORDER_WIDTH 0x0
|
||||||
|
SPINNER_LABEL_BORDER_COLOR 0x414141ff
|
||||||
|
SPINNER_LABEL_INSIDE_COLOR 0x323232ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_BORDER_COLOR 0x414141ff
|
||||||
|
SPINNER_DEFAULT_BUTTON_INSIDE_COLOR 0x323232ff
|
||||||
|
SPINNER_DEFAULT_SYMBOL_COLOR 0xafafafff
|
||||||
|
SPINNER_DEFAULT_TEXT_COLOR 0xafafafff
|
||||||
|
SPINNER_HOVER_BUTTON_BORDER_COLOR 0x3e3e3eff
|
||||||
|
SPINNER_HOVER_BUTTON_INSIDE_COLOR 0x2d2d2dff
|
||||||
|
SPINNER_HOVER_SYMBOL_COLOR 0x767472ff
|
||||||
|
SPINNER_HOVER_TEXT_COLOR 0x767472ff
|
||||||
|
SPINNER_PRESSED_BUTTON_BORDER_COLOR 0x414141ff
|
||||||
|
SPINNER_PRESSED_BUTTON_INSIDE_COLOR 0x323232ff
|
||||||
|
SPINNER_PRESSED_SYMBOL_COLOR 0x646464ff
|
||||||
|
SPINNER_PRESSED_TEXT_COLOR 0x646464ff
|
||||||
|
COMBOBOX_PADDING 0x1
|
||||||
|
COMBOBOX_BUTTON_WIDTH 0x1e
|
||||||
|
COMBOBOX_BUTTON_HEIGHT 0x1e
|
||||||
|
COMBOBOX_BORDER_WIDTH 0x1
|
||||||
|
COMBOBOX_DEFAULT_BORDER_COLOR 0x414141ff
|
||||||
|
COMBOBOX_DEFAULT_INSIDE_COLOR 0x323232ff
|
||||||
|
COMBOBOX_DEFAULT_TEXT_COLOR 0xafafafff
|
||||||
|
COMBOBOX_DEFAULT_LIST_TEXT_COLOR 0xafafafff
|
||||||
|
COMBOBOX_HOVER_BORDER_COLOR 0x3e3e3eff
|
||||||
|
COMBOBOX_HOVER_INSIDE_COLOR 0x2d2d2dff
|
||||||
|
COMBOBOX_HOVER_TEXT_COLOR 0x767472ff
|
||||||
|
COMBOBOX_HOVER_LIST_TEXT_COLOR 0x767472ff
|
||||||
|
COMBOBOX_PRESSED_BORDER_COLOR 0x414141ff
|
||||||
|
COMBOBOX_PRESSED_INSIDE_COLOR 0x323232ff
|
||||||
|
COMBOBOX_PRESSED_TEXT_COLOR 0x646464ff
|
||||||
|
COMBOBOX_PRESSED_LIST_BORDER_COLOR 0x414141ff
|
||||||
|
COMBOBOX_PRESSED_LIST_INSIDE_COLOR 0x323232ff
|
||||||
|
COMBOBOX_PRESSED_LIST_TEXT_COLOR 0x646464ff
|
||||||
|
CHECKBOX_DEFAULT_BORDER_COLOR 0x414141ff
|
||||||
|
CHECKBOX_DEFAULT_INSIDE_COLOR 0x323232ff
|
||||||
|
CHECKBOX_HOVER_BORDER_COLOR 0x3e3e3eff
|
||||||
|
CHECKBOX_HOVER_INSIDE_COLOR 0x2d2d2dff
|
||||||
|
CHECKBOX_CLICK_BORDER_COLOR 0x414141ff
|
||||||
|
CHECKBOX_CLICK_INSIDE_COLOR 0x323232ff
|
||||||
|
CHECKBOX_STATUS_ACTIVE_COLOR 0x414141ff
|
||||||
|
CHECKBOX_INSIDE_WIDTH 0x2
|
||||||
|
TEXTBOX_BORDER_WIDTH 0x1
|
||||||
|
TEXTBOX_BORDER_COLOR 0x414141ff
|
||||||
|
TEXTBOX_INSIDE_COLOR 0x323232ff
|
||||||
|
TEXTBOX_TEXT_COLOR 0xafafafff
|
||||||
|
TEXTBOX_LINE_COLOR 0xafafafff
|
||||||
|
TEXTBOX_TEXT_FONTSIZE 0x9
|
|
@ -1,31 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(800, 450, "raygui - button")
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
var button bool
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.Black)
|
|
||||||
|
|
||||||
button = gui.Button(rl.NewRectangle(50, 150, 100, 40), "Click")
|
|
||||||
if button {
|
|
||||||
fmt.Println("Clicked on button")
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,281 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raygui - controls test suite
|
|
||||||
*
|
|
||||||
* TEST CONTROLS:
|
|
||||||
* - gui.DropdownBox()
|
|
||||||
* - gui.CheckBox()
|
|
||||||
* - gui.Spinner()
|
|
||||||
* - gui.ValueBox()
|
|
||||||
* - gui.TextBox()
|
|
||||||
* - gui.Button()
|
|
||||||
* - gui.ComboBox()
|
|
||||||
* - gui.ListView()
|
|
||||||
* - gui.ToggleGroup()
|
|
||||||
* - gui.ColorPicker()
|
|
||||||
* - gui.Slider()
|
|
||||||
* - gui.SliderBar()
|
|
||||||
* - gui.ProgressBar()
|
|
||||||
* - gui.ColorBarAlpha()
|
|
||||||
* - gui.ScrollPanel()
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* DEPENDENCIES:
|
|
||||||
* raylib 4.0 - Windowing/input management and drawing.
|
|
||||||
* raygui 3.2 - Immediate-mode GUI controls.
|
|
||||||
*
|
|
||||||
* COMPILATION (Windows - MinGW):
|
|
||||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
|
|
||||||
*
|
|
||||||
* LICENSE: zlib/libpng
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016-2022 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
**********************************************************************************************/
|
|
||||||
|
|
||||||
//#define RAYGUI_CUSTOM_ICONS // It requires providing gui_icons.h in the same directory
|
|
||||||
//#include "gui_icons.h" // External icons data provided, it can be generated with rGuiIcons tool
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
//---------------------------------------------------------------------------------------
|
|
||||||
const (
|
|
||||||
screenWidth = 690
|
|
||||||
screenHeight = 560
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raygui - controls test suite")
|
|
||||||
rl.SetExitKey(0)
|
|
||||||
|
|
||||||
// GUI controls initialization
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
var (
|
|
||||||
dropdownBox000Active int32 = 0
|
|
||||||
dropDown000EditMode bool = false
|
|
||||||
|
|
||||||
dropdownBox001Active int32 = 0
|
|
||||||
dropDown001EditMode bool = false
|
|
||||||
|
|
||||||
spinner001Value int32 = 0
|
|
||||||
spinnerEditMode bool = false
|
|
||||||
|
|
||||||
valueBox002Value int32 = 0
|
|
||||||
valueBoxEditMode bool = false
|
|
||||||
|
|
||||||
textBoxText = "Text box"
|
|
||||||
textBoxEditMode bool = false
|
|
||||||
|
|
||||||
listViewScrollIndex int32 = 0
|
|
||||||
listViewActive int32 = -1
|
|
||||||
|
|
||||||
listViewExScrollIndex int32 = 0
|
|
||||||
listViewExActive int32 = 2
|
|
||||||
listViewExFocus int32 = -1
|
|
||||||
listViewExList = []string{"This", "is", "a", "list view", "with", "disable", "elements", "amazing!"}
|
|
||||||
|
|
||||||
colorPickerValue = rl.Red
|
|
||||||
|
|
||||||
sliderValue float32 = 50
|
|
||||||
sliderBarValue float32 = 60
|
|
||||||
progressValue float32 = 0.4
|
|
||||||
|
|
||||||
forceSquaredChecked bool = false
|
|
||||||
|
|
||||||
alphaValue float32 = 0.5
|
|
||||||
|
|
||||||
comboBoxActive int32 = 1
|
|
||||||
|
|
||||||
toggleGroupActive int32 = 0
|
|
||||||
|
|
||||||
viewScroll = rl.Vector2{0, 0}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Custom GUI font loading
|
|
||||||
//Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
|
|
||||||
//GuiSetFont(font);
|
|
||||||
|
|
||||||
exitWindow bool = false
|
|
||||||
showMessageBox bool = false
|
|
||||||
|
|
||||||
textInput string
|
|
||||||
showTextInputBox bool = false
|
|
||||||
|
|
||||||
// TODO textInputFileName string
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !exitWindow { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
exitWindow = rl.WindowShouldClose()
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyEscape) {
|
|
||||||
showMessageBox = !showMessageBox
|
|
||||||
}
|
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeyLeftControl) && rl.IsKeyPressed(rl.KeyS) {
|
|
||||||
showTextInputBox = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO if rl.IsFileDropped() {
|
|
||||||
// TODO var droppedFiles gui.FilePathList = rl.LoadDroppedFiles()
|
|
||||||
// TODO if (droppedFiles.count > 0) && rl.IsFileExtension(droppedFiles.paths[0], ".rgs") {
|
|
||||||
// TODO gui.LoadStyle(droppedFiles.paths[0])
|
|
||||||
// TODO }
|
|
||||||
// TODO rl.UnloadDroppedFiles(droppedFiles) // Clear internal buffers
|
|
||||||
// TODO }
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.GetColor(uint(gui.GetStyle(gui.DEFAULT, gui.BACKGROUND_COLOR))))
|
|
||||||
|
|
||||||
// raygui: controls drawing
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
if dropDown000EditMode || dropDown001EditMode {
|
|
||||||
gui.Lock()
|
|
||||||
} else if !dropDown000EditMode && !dropDown001EditMode {
|
|
||||||
gui.Unlock()
|
|
||||||
}
|
|
||||||
//GuiDisable();
|
|
||||||
|
|
||||||
// First GUI column
|
|
||||||
//GuiSetStyle(CHECKBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
|
||||||
forceSquaredChecked = gui.CheckBox(rl.Rectangle{25, 108, 15, 15}, "FORCE CHECK!", forceSquaredChecked)
|
|
||||||
|
|
||||||
gui.SetStyle(gui.TEXTBOX, gui.TEXT_ALIGNMENT, gui.TEXT_ALIGN_CENTER)
|
|
||||||
//GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
|
||||||
gui.Spinner(rl.Rectangle{25, 135, 125, 30}, "", &spinner001Value, 0, 100, spinnerEditMode)
|
|
||||||
|
|
||||||
if gui.ValueBox(rl.Rectangle{25, 175, 125, 30}, "", &valueBox002Value, 0, 100, valueBoxEditMode) {
|
|
||||||
valueBoxEditMode = !valueBoxEditMode
|
|
||||||
}
|
|
||||||
gui.SetStyle(gui.TEXTBOX, gui.TEXT_ALIGNMENT, int64(gui.TEXT_ALIGN_LEFT))
|
|
||||||
if gui.TextBox(rl.Rectangle{25, 215, 125, 30}, &textBoxText, 64, textBoxEditMode) {
|
|
||||||
textBoxEditMode = !textBoxEditMode
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.SetStyle(gui.BUTTON, gui.TEXT_ALIGNMENT, gui.TEXT_ALIGN_CENTER)
|
|
||||||
|
|
||||||
if gui.Button(rl.Rectangle{25, 255, 125, 30}, gui.IconText(gui.ICON_FILE_SAVE, "Save File")) {
|
|
||||||
showTextInputBox = true
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.GroupBox(rl.Rectangle{25, 310, 125, 150}, "STATES")
|
|
||||||
//GuiLock();
|
|
||||||
gui.SetState(gui.STATE_NORMAL)
|
|
||||||
if gui.Button(rl.Rectangle{30, 320, 115, 30}, "NORMAL") {
|
|
||||||
}
|
|
||||||
gui.SetState(gui.STATE_FOCUSED)
|
|
||||||
if gui.Button(rl.Rectangle{30, 355, 115, 30}, "FOCUSED") {
|
|
||||||
}
|
|
||||||
gui.SetState(gui.STATE_PRESSED)
|
|
||||||
if gui.Button(rl.Rectangle{30, 390, 115, 30}, "#15#PRESSED") {
|
|
||||||
}
|
|
||||||
gui.SetState(gui.STATE_DISABLED)
|
|
||||||
if gui.Button(rl.Rectangle{30, 425, 115, 30}, "DISABLED") {
|
|
||||||
}
|
|
||||||
gui.SetState(gui.STATE_NORMAL)
|
|
||||||
//GuiUnlock();
|
|
||||||
|
|
||||||
comboBoxActive = gui.ComboBox(rl.Rectangle{25, 470, 125, 30}, "ONE;TWO;THREE;FOUR", comboBoxActive)
|
|
||||||
|
|
||||||
// NOTE: gui.DropdownBox must draw after any other control that can be covered on unfolding
|
|
||||||
gui.SetStyle(gui.DROPDOWNBOX, gui.TEXT_ALIGNMENT, int64(gui.TEXT_ALIGN_LEFT))
|
|
||||||
if gui.DropdownBox(rl.Rectangle{25, 65, 125, 30}, "#01#ONE;#02#TWO;#03#THREE;#04#FOUR", &dropdownBox001Active, dropDown001EditMode) {
|
|
||||||
dropDown001EditMode = !dropDown001EditMode
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.SetStyle(gui.DROPDOWNBOX, gui.TEXT_ALIGNMENT, gui.TEXT_ALIGN_CENTER)
|
|
||||||
if gui.DropdownBox(rl.Rectangle{25, 25, 125, 30}, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode) {
|
|
||||||
dropDown000EditMode = !dropDown000EditMode
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second GUI column
|
|
||||||
listViewActive = gui.ListView(rl.Rectangle{165, 25, 140, 140}, "Charmander;Bulbasaur;#18#Squirtel;Pikachu;Eevee;Pidgey", &listViewScrollIndex, listViewActive)
|
|
||||||
listViewExActive = gui.ListViewEx(rl.Rectangle{165, 180, 140, 200}, listViewExList, &listViewExFocus, &listViewExScrollIndex, listViewExActive)
|
|
||||||
|
|
||||||
toggleGroupActive = gui.ToggleGroup(rl.Rectangle{165, 400, 140, 25}, "#1#ONE\n#3#TWO\n#8#THREE\n#23#", toggleGroupActive)
|
|
||||||
|
|
||||||
// Third GUI column
|
|
||||||
gui.Panel(rl.NewRectangle(320, 25, 225, 140), "Panel Info")
|
|
||||||
colorPickerValue = gui.ColorPicker(rl.Rectangle{320, 185, 196, 192}, "", colorPickerValue)
|
|
||||||
|
|
||||||
sliderValue = gui.Slider(rl.Rectangle{355, 400, 165, 20}, "TEST",
|
|
||||||
fmt.Sprintf("%2.2f", sliderValue), sliderValue, -50, 100)
|
|
||||||
sliderBarValue = gui.SliderBar(rl.Rectangle{320, 430, 200, 20}, "",
|
|
||||||
fmt.Sprintf("%2.2f", sliderBarValue), sliderBarValue, 0, 100)
|
|
||||||
progressValue = gui.ProgressBar(rl.Rectangle{320, 460, 200, 20}, "", "", progressValue, 0, 1)
|
|
||||||
|
|
||||||
// NOTE: View rectangle could be used to perform some scissor test
|
|
||||||
var view rl.Rectangle
|
|
||||||
gui.ScrollPanel(rl.Rectangle{560, 25, 102, 354}, "", rl.Rectangle{560, 25, 300, 1200}, &viewScroll, &view)
|
|
||||||
|
|
||||||
var mouseCell rl.Vector2
|
|
||||||
gui.Grid(rl.Rectangle{560, 25 + 180 + 195, 100, 120}, "", 20, 3, &mouseCell)
|
|
||||||
|
|
||||||
alphaValue = gui.ColorBarAlpha(rl.Rectangle{320, 490, 200, 30}, "", alphaValue)
|
|
||||||
|
|
||||||
gui.StatusBar(rl.Rectangle{0, float32(rl.GetScreenHeight()) - 20, float32(rl.GetScreenWidth()), 20}, "This is a status bar")
|
|
||||||
|
|
||||||
if showMessageBox {
|
|
||||||
rl.DrawRectangle(0, 0, int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()), rl.Fade(rl.RayWhite, 0.8))
|
|
||||||
var result int32 = gui.MessageBox(rl.Rectangle{float32(rl.GetScreenWidth())/2 - 125, float32(rl.GetScreenHeight())/2 - 50, 250, 100}, gui.IconText(gui.ICON_EXIT, "Close Window"), "Do you really want to exit?", "Yes;No")
|
|
||||||
|
|
||||||
if (result == 0) || (result == 2) {
|
|
||||||
showMessageBox = false
|
|
||||||
} else if result == 1 {
|
|
||||||
exitWindow = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if showTextInputBox {
|
|
||||||
rl.DrawRectangle(0, 0, int32(rl.GetScreenWidth()), int32(rl.GetScreenHeight()), rl.Fade(rl.RayWhite, 0.8))
|
|
||||||
var secretViewActive bool
|
|
||||||
var result int32 = gui.TextInputBox(
|
|
||||||
rl.Rectangle{float32(rl.GetScreenWidth())/2 - 120, float32(rl.GetScreenHeight())/2 - 60, 240, 140},
|
|
||||||
"Save",
|
|
||||||
gui.IconText(gui.ICON_FILE_SAVE, "Save file as..."),
|
|
||||||
"Ok;Cancel",
|
|
||||||
&textInput, 255, &secretViewActive)
|
|
||||||
|
|
||||||
if result == 1 {
|
|
||||||
// TODO: Validate textInput value and save
|
|
||||||
// strcpy(textInputFileName, textInput)
|
|
||||||
// TODO textInputFileName = textInput
|
|
||||||
}
|
|
||||||
if (result == 0) || (result == 1) || (result == 2) {
|
|
||||||
showTextInputBox = false
|
|
||||||
//strcpy(textInput, "\0");
|
|
||||||
textInput = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
Before Width: | Height: | Size: 26 KiB |
|
@ -1,3 +0,0 @@
|
||||||
This example loads a custom .rgi-file and draws the 255th icon. You can use the [rGuiIcons](https://raylibtech.itch.io/rguiicons) tool to view or create icon files.
|
|
||||||
|
|
||||||

|
|
|
@ -1,20 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(800, 600, "raylib-go - icons example")
|
|
||||||
defer rl.CloseWindow()
|
|
||||||
|
|
||||||
raygui.LoadIcons("default_icons_with_255.rgi", false)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
raygui.DrawIcon(raygui.ICON_255, 100, 100, 8, rl.Gray)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
}
|
|
Before Width: | Height: | Size: 8 KiB |
|
@ -1,99 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raygui - portable window
|
|
||||||
*
|
|
||||||
* DEPENDENCIES:
|
|
||||||
* raylib 4.0 - Windowing/input management and drawing.
|
|
||||||
* raygui 3.0 - Immediate-mode GUI controls.
|
|
||||||
*
|
|
||||||
* COMPILATION (Windows - MinGW):
|
|
||||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
|
|
||||||
*
|
|
||||||
* LICENSE: zlib/libpng
|
|
||||||
*
|
|
||||||
* Copyright (c) 2016-2022 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
**********************************************************************************************/
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
//---------------------------------------------------------------------------------------
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 600
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.SetConfigFlags(rl.FlagWindowUndecorated)
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raygui - portable window")
|
|
||||||
|
|
||||||
// General variables
|
|
||||||
var (
|
|
||||||
mousePosition = rl.Vector2{0, 0}
|
|
||||||
windowPosition = rl.Vector2{500, 200}
|
|
||||||
panOffset = mousePosition
|
|
||||||
dragWindow = false
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.SetWindowPosition(int(windowPosition.X), int(windowPosition.Y))
|
|
||||||
|
|
||||||
exitWindow := false
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !exitWindow && !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
mousePosition = rl.GetMousePosition()
|
|
||||||
|
|
||||||
if rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
|
||||||
if (rl.CheckCollisionPointRec(mousePosition, rl.Rectangle{0, 0, screenWidth, 20})) {
|
|
||||||
dragWindow = true
|
|
||||||
panOffset = mousePosition
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if dragWindow {
|
|
||||||
windowPosition.X += (mousePosition.X - panOffset.X)
|
|
||||||
windowPosition.Y += (mousePosition.Y - panOffset.Y)
|
|
||||||
|
|
||||||
if rl.IsMouseButtonReleased(rl.MouseLeftButton) {
|
|
||||||
dragWindow = false
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.SetWindowPosition(int(windowPosition.X), int(windowPosition.Y))
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
exitWindow = gui.WindowBox(rl.Rectangle{0, 0, screenWidth, screenHeight}, "#198# PORTABLE WINDOW")
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("Mouse Position: [ %.0f, %.0f ]", mousePosition.X, mousePosition.Y), 10, 40, 10, rl.DarkGray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
|
@ -1,193 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raygui - Controls test
|
|
||||||
*
|
|
||||||
* TEST CONTROLS:
|
|
||||||
* - gui.ScrollPanel()
|
|
||||||
*
|
|
||||||
* DEPENDENCIES:
|
|
||||||
* raylib 4.0 - Windowing/input management and drawing.
|
|
||||||
* raygui 3.0 - Immediate-mode GUI controls.
|
|
||||||
*
|
|
||||||
* COMPILATION (Windows - MinGW):
|
|
||||||
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
|
|
||||||
*
|
|
||||||
* COMPILATION (Linux - gcc):
|
|
||||||
* gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -std=c99
|
|
||||||
*
|
|
||||||
* LICENSE: zlib/libpng
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2022 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
**********************************************************************************************/
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
// Program main entry point
|
|
||||||
// ------------------------------------------------------------------------------------
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
// Initialization
|
|
||||||
//---------------------------------------------------------------------------------------
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raygui - gui.ScrollPanel()")
|
|
||||||
|
|
||||||
var (
|
|
||||||
panelRec = rl.Rectangle{20, 40, 200, 150}
|
|
||||||
panelContentRec = rl.Rectangle{0, 0, 340, 340}
|
|
||||||
panelView = rl.Rectangle{0, 0, 0, 0}
|
|
||||||
panelScroll = rl.Vector2{99, -20}
|
|
||||||
mouseCell = rl.Vector2{0, 0}
|
|
||||||
|
|
||||||
showContentArea = true
|
|
||||||
)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
//---------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
// Detect window close button or ESC key
|
|
||||||
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// TODO: Implement required update logic
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("[%.1f, %.1f]", panelScroll.X, panelScroll.Y), 4, 4, 20, rl.Red)
|
|
||||||
|
|
||||||
gui.ScrollPanel(panelRec, "", panelContentRec, &panelScroll, &panelView)
|
|
||||||
|
|
||||||
rl.BeginScissorMode(int32(panelView.X), int32(panelView.Y), int32(panelView.Width), int32(panelView.Height))
|
|
||||||
gui.Grid(rl.Rectangle{
|
|
||||||
float32(panelRec.X + panelScroll.X),
|
|
||||||
float32(panelRec.Y + panelScroll.Y),
|
|
||||||
float32(panelContentRec.Width),
|
|
||||||
float32(panelContentRec.Height),
|
|
||||||
}, "", 16, 3, &mouseCell)
|
|
||||||
rl.EndScissorMode()
|
|
||||||
|
|
||||||
if showContentArea {
|
|
||||||
rl.DrawRectangle(
|
|
||||||
int32(panelRec.X+panelScroll.X),
|
|
||||||
int32(panelRec.Y+panelScroll.Y),
|
|
||||||
int32(panelContentRec.Width),
|
|
||||||
int32(panelContentRec.Height),
|
|
||||||
rl.Fade(rl.Red, 0.1),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawStyleEditControls()
|
|
||||||
|
|
||||||
showContentArea = gui.CheckBox(rl.Rectangle{565, 80, 20, 20}, "SHOW CONTENT AREA", showContentArea)
|
|
||||||
|
|
||||||
panelContentRec.Width = gui.SliderBar(rl.Rectangle{590, 385, 145, 15},
|
|
||||||
"WIDTH",
|
|
||||||
fmt.Sprintf("%.1f", panelContentRec.Width),
|
|
||||||
panelContentRec.Width,
|
|
||||||
1, 600)
|
|
||||||
panelContentRec.Height = gui.SliderBar(rl.Rectangle{590, 410, 145, 15},
|
|
||||||
"HEIGHT",
|
|
||||||
fmt.Sprintf("%.1f", panelContentRec.Height),
|
|
||||||
panelContentRec.Height, 1, 400)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw and process scroll bar style edition controls
|
|
||||||
func DrawStyleEditControls() {
|
|
||||||
// ScrollPanel style controls
|
|
||||||
//----------------------------------------------------------
|
|
||||||
gui.GroupBox(rl.Rectangle{550, 170, 220, 205}, "SCROLLBAR STYLE")
|
|
||||||
|
|
||||||
var style int32
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.SCROLLBAR, gui.BORDER_WIDTH))
|
|
||||||
gui.Label(rl.Rectangle{555, 195, 110, 10}, "BORDER_WIDTH")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 190, 90, 20}, "", &style, 0, 6, false)
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.BORDER_WIDTH, int64(style))
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.SCROLLBAR, gui.ARROWS_SIZE))
|
|
||||||
gui.Label(rl.Rectangle{555, 220, 110, 10}, "ARROWS_SIZE")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 215, 90, 20}, "", &style, 4, 14, false)
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.ARROWS_SIZE, int64(style))
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.SCROLLBAR, gui.SLIDER_PADDING))
|
|
||||||
gui.Label(rl.Rectangle{555, 245, 110, 10}, "SLIDER_PADDING")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 240, 90, 20}, "", &style, 0, 14, false)
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.SLIDER_PADDING, int64(style))
|
|
||||||
|
|
||||||
style = boolToint32(gui.CheckBox(rl.Rectangle{565, 280, 20, 20}, "ARROWS_VISIBLE", int32Tobool(int32(gui.GetStyle(gui.SCROLLBAR, gui.ARROWS_VISIBLE)))))
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.ARROWS_VISIBLE, int64(style))
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.SCROLLBAR, gui.SLIDER_PADDING))
|
|
||||||
gui.Label(rl.Rectangle{555, 325, 110, 10}, "SLIDER_PADDING")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 320, 90, 20}, "", &style, 0, 14, false)
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.SLIDER_PADDING, int64(style))
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.SCROLLBAR, gui.SLIDER_WIDTH))
|
|
||||||
gui.Label(rl.Rectangle{555, 350, 110, 10}, "SLIDER_WIDTH")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 345, 90, 20}, "", &style, 2, 100, false)
|
|
||||||
gui.SetStyle(gui.SCROLLBAR, gui.SLIDER_WIDTH, int64(style))
|
|
||||||
|
|
||||||
var text string
|
|
||||||
if gui.GetStyle(gui.LISTVIEW, gui.SCROLLBAR_SIDE) == gui.SCROLLBAR_LEFT_SIDE {
|
|
||||||
text = "SCROLLBAR: LEFT"
|
|
||||||
} else {
|
|
||||||
text = "SCROLLBAR: RIGHT"
|
|
||||||
}
|
|
||||||
style = boolToint32(gui.Toggle(rl.Rectangle{560, 110, 200, 35}, text, int32Tobool(int32(gui.GetStyle(gui.LISTVIEW, gui.SCROLLBAR_SIDE)))))
|
|
||||||
gui.SetStyle(gui.LISTVIEW, gui.SCROLLBAR_SIDE, int64(style))
|
|
||||||
//----------------------------------------------------------
|
|
||||||
|
|
||||||
// ScrollBar style controls
|
|
||||||
//----------------------------------------------------------
|
|
||||||
gui.GroupBox(rl.Rectangle{550, 20, 220, 135}, "SCROLLPANEL STYLE")
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.LISTVIEW, gui.SCROLLBAR_WIDTH))
|
|
||||||
gui.Label(rl.Rectangle{555, 35, 110, 10}, "SCROLLBAR_WIDTH")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 30, 90, 20}, "", &style, 6, 30, false)
|
|
||||||
gui.SetStyle(gui.LISTVIEW, gui.SCROLLBAR_WIDTH, int64(style))
|
|
||||||
|
|
||||||
style = int32(gui.GetStyle(gui.DEFAULT, gui.BORDER_WIDTH))
|
|
||||||
gui.Label(rl.Rectangle{555, 60, 110, 10}, "BORDER_WIDTH")
|
|
||||||
gui.Spinner(rl.Rectangle{670, 55, 90, 20}, "", &style, 0, 20, false)
|
|
||||||
gui.SetStyle(gui.DEFAULT, gui.BORDER_WIDTH, int64(style))
|
|
||||||
//----------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
func boolToint32(b bool) int32 {
|
|
||||||
if b {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func int32Tobool(v int32) bool {
|
|
||||||
return 0 < v
|
|
||||||
}
|
|
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 295 KiB |
|
@ -1,95 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - Load 3d model with animations and play them
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 3.5
|
|
||||||
*
|
|
||||||
* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019-2024 Culacant (@culacant) and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************
|
|
||||||
*
|
|
||||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
|
||||||
* in the same position as they would be in edit mode and the scale of your models is
|
|
||||||
* set to 0. Scaling can be done from the export menu.
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - model animation")
|
|
||||||
|
|
||||||
camera := rl.Camera{}
|
|
||||||
camera.Position = rl.NewVector3(10.0, 10.0, 10.0)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Fovy = 45.0
|
|
||||||
camera.Projection = rl.CameraPerspective
|
|
||||||
|
|
||||||
model := rl.LoadModel("guy.iqm")
|
|
||||||
texture := rl.LoadTexture("guytex.png")
|
|
||||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture)
|
|
||||||
|
|
||||||
position := rl.NewVector3(0, 0, 0)
|
|
||||||
|
|
||||||
anims := rl.LoadModelAnimations("guyanim.iqm")
|
|
||||||
animFrameCount := 0
|
|
||||||
|
|
||||||
rl.DisableCursor()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
|
||||||
|
|
||||||
if rl.IsKeyDown(rl.KeySpace) {
|
|
||||||
animFrameCount++
|
|
||||||
animCurrent := anims[0]
|
|
||||||
animFrameNum := animCurrent.FrameCount
|
|
||||||
|
|
||||||
rl.UpdateModelAnimation(model, anims[0], int32(animFrameCount))
|
|
||||||
if animFrameCount >= int(animFrameNum) {
|
|
||||||
animFrameCount = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
rl.DrawModelEx(model, position, rl.NewVector3(1, 0, 0), -90, rl.NewVector3(1, 1, 1), rl.White)
|
|
||||||
// Draw translation cubes
|
|
||||||
for i := int32(0); i < model.BoneCount; i++ {
|
|
||||||
pose := anims[0].GetFramePose(animFrameCount, int(i))
|
|
||||||
rl.DrawCube(pose.Translation, 0.2, 0.2, 0.2, rl.Red)
|
|
||||||
}
|
|
||||||
rl.DrawGrid(10, 1)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, rl.Black)
|
|
||||||
rl.DrawText("(c) Guy IQM 3D model by @culacant", 10, 30, 10, rl.Black)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadModel(model)
|
|
||||||
rl.UnloadModelAnimations(anims)
|
|
||||||
rl.UnloadTexture(texture)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
@ -1,26 +1,13 @@
|
||||||
/*******************************************************************************************
|
package main
|
||||||
*
|
|
||||||
* raylib [models] example - Drawing billboards
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 1.3, last time updated with raylib 3.5
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/package main
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
screenWidth := int32(800)
|
||||||
|
screenHeight := int32(450)
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards")
|
||||||
|
|
||||||
camera := rl.Camera{}
|
camera := rl.Camera{}
|
||||||
|
@ -28,63 +15,30 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Projection = rl.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
bill := rl.LoadTexture("billboard.png") // Our texture billboard
|
bill := rl.LoadTexture("billboard.png") // Our texture billboard
|
||||||
billPositionStatic := rl.NewVector3(0.0, 2.0, 0.0) // Position of static billboard
|
billPosition := rl.NewVector3(0.0, 2.0, 0.0) // Position where draw billboard
|
||||||
billPositionRotating := rl.NewVector3(1.0, 2.0, 1.0) // Position of rotating billboard
|
|
||||||
|
|
||||||
// Entire billboard texture, source is used to take a segment from a larger texture.
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
source := rl.Rectangle{
|
|
||||||
Width: float32(bill.Width),
|
|
||||||
Height: float32(bill.Height),
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: Billboard locked on axis-Y
|
|
||||||
billUp := rl.Vector3{Y: 1.0}
|
|
||||||
|
|
||||||
// Set the height of the rotating billboard to 1.0 with the aspect ratio fixed
|
|
||||||
size := rl.Vector2{
|
|
||||||
X: source.Width / source.Height,
|
|
||||||
Y: 1.0,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rotate around origin
|
|
||||||
// Here we choose to rotate around the image center
|
|
||||||
origin := rl.Vector2Scale(size, 0.5)
|
|
||||||
|
|
||||||
// Distance is needed for the correct billboard draw order
|
|
||||||
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
|
|
||||||
var distanceStatic, distanceRotating, rotation float32
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
rl.UpdateCamera(&camera, rl.CameraOrbital) // Update camera with orbital camera mode
|
|
||||||
|
|
||||||
rotation += 0.4
|
|
||||||
distanceStatic = rl.Vector3Distance(camera.Position, billPositionStatic)
|
|
||||||
distanceRotating = rl.Vector3Distance(camera.Position, billPositionRotating)
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
rl.ClearBackground(rl.RayWhite)
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
rl.BeginMode3D(camera)
|
||||||
|
|
||||||
|
rl.DrawBillboard(camera, bill, billPosition, 2.0, rl.White)
|
||||||
|
|
||||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
rl.DrawGrid(10, 1.0) // Draw a grid
|
||||||
|
|
||||||
// Draw order matters!
|
|
||||||
if distanceStatic > distanceRotating {
|
|
||||||
rl.DrawBillboard(camera, bill, billPositionStatic, 2.0, rl.White)
|
|
||||||
rl.DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, rl.White)
|
|
||||||
} else {
|
|
||||||
rl.DrawBillboardPro(camera, bill, source, billPositionRotating, billUp, size, origin, rotation, rl.White)
|
|
||||||
rl.DrawBillboard(camera, bill, billPositionStatic, 2.0, rl.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
rl.EndMode3D()
|
||||||
rl.DrawFPS(10, 10)
|
|
||||||
rl.EndDrawing()
|
rl.EndDrawing()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -15,7 +15,7 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
camera.Projection = rl.CameraPerspective
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
playerPosition := rl.NewVector3(0.0, 1.0, 2.0)
|
playerPosition := rl.NewVector3(0.0, 1.0, 2.0)
|
||||||
playerSize := rl.NewVector3(1.0, 2.0, 1.0)
|
playerSize := rl.NewVector3(1.0, 2.0, 1.0)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -15,6 +15,7 @@ func main() {
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
||||||
camera.Fovy = 45.0
|
camera.Fovy = 45.0
|
||||||
|
camera.Type = rl.CameraPerspective
|
||||||
|
|
||||||
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
image := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
||||||
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
cubicmap := rl.LoadTextureFromImage(image) // Convert image to texture to display (VRAM)
|
||||||
|
@ -24,18 +25,20 @@ func main() {
|
||||||
|
|
||||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
// NOTE: By default each cube is mapped to one part of texture atlas
|
||||||
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
texture := rl.LoadTexture("cubicmap_atlas.png") // Load map texture
|
||||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
|
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||||
|
|
||||||
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
||||||
|
|
||||||
rl.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
rl.UnloadImage(image) // Unload cubicmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraOrbital) // Update camera with orbital camera mode
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
|
|
Before Width: | Height: | Size: 36 KiB |
|
@ -1,256 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - Draw textured cube
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - draw cube texture")
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
|
||||||
camera := rl.Camera{
|
|
||||||
Position: rl.Vector3{
|
|
||||||
Y: 10.0,
|
|
||||||
Z: 10.0,
|
|
||||||
},
|
|
||||||
Target: rl.Vector3{},
|
|
||||||
Up: rl.Vector3{Y: 1.0},
|
|
||||||
Fovy: 45.0,
|
|
||||||
Projection: rl.CameraPerspective,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load texture to be applied to the cubes sides
|
|
||||||
texture := rl.LoadTexture("cubicmap_atlas.png")
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
// TODO: Update your variables here
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
// Draw cube with an applied texture
|
|
||||||
vec := rl.Vector3{
|
|
||||||
X: -2.0,
|
|
||||||
Y: 2.0,
|
|
||||||
}
|
|
||||||
DrawCubeTexture(texture, vec, 2.0, 4.0, 2.0, rl.White)
|
|
||||||
|
|
||||||
// Draw cube with an applied texture, but only a defined rectangle piece of the texture
|
|
||||||
rec := rl.Rectangle{
|
|
||||||
Y: float32(texture.Height) / 2.0,
|
|
||||||
Width: float32(texture.Width) / 2.0,
|
|
||||||
Height: float32(texture.Height) / 2.0,
|
|
||||||
}
|
|
||||||
vec = rl.Vector3{
|
|
||||||
X: 2.0,
|
|
||||||
Y: 1.0,
|
|
||||||
}
|
|
||||||
DrawCubeTextureRec(texture, rec, vec, 2.0, 2.0, 2.0, rl.White)
|
|
||||||
|
|
||||||
rl.DrawGrid(10, 1.0) // Draw a grid
|
|
||||||
rl.EndMode3D()
|
|
||||||
rl.DrawFPS(10, 10)
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
rl.UnloadTexture(texture) // Unload texture
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawCubeTexture draws a textured cube
|
|
||||||
// NOTE: Cube position is the center position
|
|
||||||
func DrawCubeTexture(texture rl.Texture2D, position rl.Vector3, width, height, length float32, color rl.Color) {
|
|
||||||
x := position.X
|
|
||||||
y := position.Y
|
|
||||||
z := position.Z
|
|
||||||
|
|
||||||
// Set desired texture to be enabled while drawing following vertex data
|
|
||||||
rl.SetTexture(texture.ID)
|
|
||||||
|
|
||||||
// Vertex data transformation can be defined with the commented lines,
|
|
||||||
// but in this example we calculate the transformed vertex data directly when calling rlVertex3f()
|
|
||||||
// rl.PushMatrix()
|
|
||||||
// NOTE: Transformation is applied in inverse order (scale -> rotate -> translate)
|
|
||||||
//rl.Translatef(2.0, 0.0, 0.0)
|
|
||||||
//rl.Rotatef(45, 0, 1, )
|
|
||||||
//rl.Scalef(2.0, 2.0, 2.0)
|
|
||||||
|
|
||||||
rl.Begin(rl.Quads)
|
|
||||||
rl.Color4ub(color.R, color.G, color.B, color.A)
|
|
||||||
// Front Face
|
|
||||||
rl.Normal3f(0.0, 0.0, 1.0) // Normal Pointing Towards Viewer
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2) // Top Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2) // Top Left Of The Texture and Quad
|
|
||||||
// Back Face
|
|
||||||
rl.Normal3f(0.0, 0.0, -1.0) // Normal Pointing Away From Viewer
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2) // Top Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2) // Top Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
// Top Face
|
|
||||||
rl.Normal3f(0.0, 1.0, 0.0) // Normal Pointing Up
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2) // Top Left Of The Texture and Quad.
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2) // Top Right Of The Texture and Quad Bottom Face
|
|
||||||
rl.Normal3f(0.0, -1.0, 0.0) // Normal Pointing Down
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2) // Top Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2) // Top Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
// Right face
|
|
||||||
rl.Normal3f(1.0, 0.0, 0.0) // Normal Pointing Right
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2) // Top Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2) // Top Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
// Left Face
|
|
||||||
rl.Normal3f(-1.0, 0.0, 0.0) // Normal Pointing Left
|
|
||||||
rl.TexCoord2f(0.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2) // Bottom Left Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 0.0)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2) // Bottom Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(1.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2) // Top Right Of The Texture and Quad
|
|
||||||
rl.TexCoord2f(0.0, 1.0)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2) // Top Left Of The Texture and Quad
|
|
||||||
|
|
||||||
rl.End()
|
|
||||||
//rl.PopMatrix()
|
|
||||||
|
|
||||||
rl.SetTexture(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawCubeTextureRec draws a cube with texture piece applied to all faces
|
|
||||||
func DrawCubeTextureRec(texture rl.Texture2D, source rl.Rectangle, position rl.Vector3, width, height,
|
|
||||||
length float32, color rl.Color) {
|
|
||||||
|
|
||||||
x := position.X
|
|
||||||
y := position.Y
|
|
||||||
z := position.Z
|
|
||||||
|
|
||||||
texWidth := float32(texture.Width)
|
|
||||||
texHeight := float32(texture.Height)
|
|
||||||
|
|
||||||
// Set desired texture to be enabled while drawing following vertex data
|
|
||||||
rl.SetTexture(texture.ID)
|
|
||||||
|
|
||||||
// We calculate the normalized texture coordinates for the desired texture-source-rectangle
|
|
||||||
// It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent
|
|
||||||
rl.Begin(rl.Quads)
|
|
||||||
rl.Color4ub(color.R, color.G, color.B, color.A)
|
|
||||||
|
|
||||||
// Front face
|
|
||||||
rl.Normal3f(0.0, 0.0, 1.0)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2)
|
|
||||||
|
|
||||||
// Back face
|
|
||||||
rl.Normal3f(0.0, 0.0, -1.0)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2)
|
|
||||||
|
|
||||||
// Top face
|
|
||||||
rl.Normal3f(0.0, 1.0, 0.0)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2)
|
|
||||||
|
|
||||||
// Bottom face
|
|
||||||
rl.Normal3f(0.0, -1.0, 0.0)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2)
|
|
||||||
|
|
||||||
// Right face
|
|
||||||
rl.Normal3f(1.0, 0.0, 0.0)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z-length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z-length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y+height/2, z+length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x+width/2, y-height/2, z+length/2)
|
|
||||||
|
|
||||||
// Left face
|
|
||||||
rl.Normal3f(-1.0, 0.0, 0.0)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z-length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, (source.Y+source.Height)/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y-height/2, z+length/2)
|
|
||||||
rl.TexCoord2f((source.X+source.Width)/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z+length/2)
|
|
||||||
rl.TexCoord2f(source.X/texWidth, source.Y/texHeight)
|
|
||||||
rl.Vertex3f(x-width/2, y+height/2, z-length/2)
|
|
||||||
|
|
||||||
rl.End()
|
|
||||||
|
|
||||||
rl.SetTexture(0)
|
|
||||||
}
|
|
Before Width: | Height: | Size: 164 B |
Before Width: | Height: | Size: 36 KiB |
|
@ -1,117 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - first person maze
|
|
||||||
*
|
|
||||||
* This example has been created using raylib-go v0.0.0-20220104071325-2f072dc2d259 (https://git.terah.dev/UnrealXR/raylib-go)
|
|
||||||
* raylib-go is licensed under an unmodified zlib/libpng license (https://git.terah.dev/UnrealXR/raylib-go/blob/master/LICENSE)
|
|
||||||
*
|
|
||||||
* Original C version for Raylib 2.5 Copyright (c) 2019 Ramon Santamaria (@raysan5)
|
|
||||||
* Converted to Go by Michael Redman January 4, 2022
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
var screenWidth int32 = 800
|
|
||||||
var screenHeight int32 = 450
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - first person maze")
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
|
||||||
camera := rl.Camera{}
|
|
||||||
camera.Position = rl.NewVector3(0.2, 0.4, 0.2)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Fovy = 45.0
|
|
||||||
camera.Projection = rl.CameraPerspective
|
|
||||||
|
|
||||||
imMap := rl.LoadImage("cubicmap.png") // Load cubicmap image (RAM)
|
|
||||||
cubicmap := rl.LoadTextureFromImage(imMap) // Convert image to texture to display (VRAM)
|
|
||||||
mesh := rl.GenMeshCubicmap(*imMap, rl.NewVector3(1.0, 1.0, 1.0))
|
|
||||||
model := rl.LoadModelFromMesh(mesh)
|
|
||||||
|
|
||||||
// NOTE: By default each cube is mapped to one part of texture atlas
|
|
||||||
texture := rl.LoadTexture("cubicmap_atlas.png") // load map texture
|
|
||||||
model.Materials.GetMap(rl.MapDiffuse).Texture = texture // Set map diffuse texture
|
|
||||||
// Get map image data to be used for collision detectio
|
|
||||||
mapPixels := rl.LoadImageColors(imMap)
|
|
||||||
rl.UnloadImage(imMap) // Unload image from RAM
|
|
||||||
|
|
||||||
mapPosition := rl.NewVector3(-16.0, 0.0, -8.0) // Set model position
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
oldCamPos := camera.Position // Store old camera position
|
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson) // Update camera with first person mode
|
|
||||||
|
|
||||||
// Check player collision (we simplify to 2D collision detection)
|
|
||||||
playerPos := rl.NewVector2(camera.Position.X, camera.Position.Z)
|
|
||||||
playerRadius := 0.1 // Collision radius (player is modelled as a cylinder for collision)
|
|
||||||
|
|
||||||
playerCellX := (int)(playerPos.X - mapPosition.X + 0.5)
|
|
||||||
playerCellY := (int)(playerPos.Y - mapPosition.Z + 0.5)
|
|
||||||
|
|
||||||
// Out-of-limits security check
|
|
||||||
if playerCellX < 0 {
|
|
||||||
playerCellX = 0
|
|
||||||
} else if playerCellX >= int(cubicmap.Width) {
|
|
||||||
playerCellX = int(cubicmap.Width) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if playerCellY < 0 {
|
|
||||||
playerCellY = 0
|
|
||||||
} else if playerCellY >= int(cubicmap.Height) {
|
|
||||||
playerCellY = int(cubicmap.Height) - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check map collisions using image data and player position
|
|
||||||
// TODO: Improvement: Just check player surrounding cells for collision
|
|
||||||
for y := 0; y < int(cubicmap.Height); y++ {
|
|
||||||
for x := 0; x < int(cubicmap.Width); x++ {
|
|
||||||
// Collision: white pixel, only check R channel
|
|
||||||
if mapPixels[y*int(cubicmap.Width)+x].R == 255 && (rl.CheckCollisionCircleRec(playerPos, float32(playerRadius), rl.NewRectangle(float32(mapPosition.X-0.5+float32(x)), float32(mapPosition.Z-0.5+float32(y)), 1.0, 1.0))) {
|
|
||||||
// Collision detected, reset camera position
|
|
||||||
camera.Position = oldCamPos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
// Draw
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
rl.DrawModel(model, mapPosition, 1.0, rl.White) // Draw maze map
|
|
||||||
rl.EndMode3D()
|
|
||||||
rl.DrawTextureEx(cubicmap, rl.NewVector2(float32(rl.GetScreenWidth())-float32(cubicmap.Width)*4.0-20, 20.0), 0.0, 4.0, rl.White)
|
|
||||||
rl.DrawRectangleLines(int32(rl.GetScreenWidth())-cubicmap.Width*4-20, 20, cubicmap.Width*4, cubicmap.Height*4, rl.Green)
|
|
||||||
// Draw player position radar
|
|
||||||
rl.DrawRectangle(int32(rl.GetScreenWidth()-int(cubicmap.Width*4)-20+(playerCellX*4)), int32(20+playerCellY*4), 4, 4, rl.Red)
|
|
||||||
|
|
||||||
rl.DrawFPS(10, 10)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
rl.UnloadTexture(cubicmap) // Unload cubicmap texture
|
|
||||||
rl.UnloadTexture(texture) // Unload map texture
|
|
||||||
rl.UnloadModel(model) // Unload map model
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
}
|
|
|
@ -1,5 +1,9 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
screenWidth := int32(800)
|
screenWidth := int32(800)
|
||||||
screenHeight := int32(450)
|
screenHeight := int32(450)
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
screenWidth := int32(1280)
|
|
||||||
screenHeight := int32(720)
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - gltf loading")
|
|
||||||
|
|
||||||
camera := rl.Camera{}
|
|
||||||
camera.Position = rl.NewVector3(5.0, 5.0, 5.0)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 2.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Fovy = 45.0
|
|
||||||
camera.Projection = rl.CameraPerspective
|
|
||||||
|
|
||||||
model := rl.LoadModel("robot.glb")
|
|
||||||
|
|
||||||
animIndex := 0
|
|
||||||
animCurrentFrame := 0
|
|
||||||
|
|
||||||
modelAnims := rl.LoadModelAnimations("robot.glb")
|
|
||||||
|
|
||||||
position := rl.NewVector3(0, 0, 0)
|
|
||||||
rl.DisableCursor()
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraOrbital)
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyUp) {
|
|
||||||
animIndex++
|
|
||||||
if animIndex >= len(modelAnims) {
|
|
||||||
animIndex = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyDown) {
|
|
||||||
animIndex--
|
|
||||||
if animIndex < 0 {
|
|
||||||
animIndex = len(modelAnims) - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
animPlaying := modelAnims[animIndex]
|
|
||||||
animCurrentFrame = (animCurrentFrame + 1) % int(animPlaying.FrameCount)
|
|
||||||
rl.UpdateModelAnimation(model, animPlaying, int32(animCurrentFrame))
|
|
||||||
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
rl.DrawModel(model, position, 0.8, rl.White)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawText(fmt.Sprintf("current animation: %s [%d]", animPlaying.GetName(), animIndex), 10, 10, 10, rl.Black)
|
|
||||||
rl.DrawText("UP/DOWN ARROW KEYS CHANGE ANIMATION", 10, 30, 10, rl.Black)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadModel(model)
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,9 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"fmt"
|
"github.com/gen2brain/raylib-go/raylib"
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -24,18 +22,19 @@ func main() {
|
||||||
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
mesh := rl.GenMeshHeightmap(*image, rl.NewVector3(16, 8, 16)) // Generate heightmap mesh (RAM and VRAM)
|
||||||
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
model := rl.LoadModelFromMesh(mesh) // Load model from generated mesh
|
||||||
|
|
||||||
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
|
model.Material.Maps[rl.MapDiffuse].Texture = texture // Set map diffuse texture
|
||||||
|
|
||||||
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
mapPosition := rl.NewVector3(-8.0, 0.0, -8.0) // Set model position
|
||||||
|
|
||||||
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
rl.UnloadImage(image) // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
rl.SetCameraMode(camera, rl.CameraOrbital) // Set an orbital camera mode
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
rl.SetTargetFPS(60)
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
for !rl.WindowShouldClose() {
|
||||||
// Update
|
// Update
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraOrbital) // Update camera with orbital camera mode
|
rl.UpdateCamera(&camera) // Update camera
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
||||||
|
|
|
@ -1,155 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - Load models M3D
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
|
||||||
*
|
|
||||||
* Example contributed by bzt (@bztsrc) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* NOTES:
|
|
||||||
* - Model3D (M3D) fileformat specs: https://gitlab.com/bztsrc/model3d
|
|
||||||
* - Bender M3D exported: https://gitlab.com/bztsrc/model3d/-/tree/master/blender
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2022-2024 bzt (@bztsrc)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
// Initialization
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - M3D model loading")
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
|
||||||
camera := rl.Camera{
|
|
||||||
Position: rl.NewVector3(1.5, 1.5, 1.5),
|
|
||||||
Target: rl.NewVector3(0.0, 0.4, 0.0),
|
|
||||||
Up: rl.NewVector3(0.0, 1.0, 0.0),
|
|
||||||
Fovy: 45.0,
|
|
||||||
Projection: rl.CameraPerspective,
|
|
||||||
}
|
|
||||||
|
|
||||||
position := rl.NewVector3(0.0, 0.0, 0.0)
|
|
||||||
|
|
||||||
modelFileName := "cesium_man.m3d"
|
|
||||||
drawMesh := true
|
|
||||||
drawSkeleton := true
|
|
||||||
animPlaying := false // Store anim state, what to draw
|
|
||||||
|
|
||||||
// Load model
|
|
||||||
model := rl.LoadModel(modelFileName)
|
|
||||||
|
|
||||||
// Load animations
|
|
||||||
|
|
||||||
animFrameCounter := 0
|
|
||||||
animID := 0
|
|
||||||
anims := rl.LoadModelAnimations(modelFileName)
|
|
||||||
animsCount := int32(len(anims))
|
|
||||||
|
|
||||||
rl.DisableCursor()
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
// Update
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson)
|
|
||||||
|
|
||||||
if animsCount > 0 {
|
|
||||||
// Play animation when space bar is held down (or step one frame with N)
|
|
||||||
if rl.IsKeyDown(rl.KeySpace) || rl.IsKeyPressed(rl.KeyN) {
|
|
||||||
animFrameCounter++
|
|
||||||
if animFrameCounter >= int(anims[animID].FrameCount) {
|
|
||||||
animFrameCounter = 0
|
|
||||||
}
|
|
||||||
rl.UpdateModelAnimation(model, anims[animID], int32(animFrameCounter))
|
|
||||||
animPlaying = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select animation by pressing C
|
|
||||||
if rl.IsKeyPressed(rl.KeyC) {
|
|
||||||
animFrameCounter = 0
|
|
||||||
animID++
|
|
||||||
if animID >= int(animsCount) {
|
|
||||||
animID = 0
|
|
||||||
}
|
|
||||||
rl.UpdateModelAnimation(model, anims[animID], 0)
|
|
||||||
animPlaying = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle skeleton drawing
|
|
||||||
if rl.IsKeyPressed(rl.KeyB) {
|
|
||||||
drawSkeleton = !drawSkeleton
|
|
||||||
}
|
|
||||||
|
|
||||||
// Toggle mesh drawing
|
|
||||||
if rl.IsKeyPressed(rl.KeyM) {
|
|
||||||
drawMesh = !drawMesh
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
// Draw 3d model with texture
|
|
||||||
if drawMesh {
|
|
||||||
rl.DrawModel(model, position, 1.0, rl.White)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the animated skeleton
|
|
||||||
if drawSkeleton {
|
|
||||||
modelBones := model.GetBones()
|
|
||||||
modelPoses := model.GetBindPose()
|
|
||||||
anim := anims[animID]
|
|
||||||
animBones := anim.GetBones()
|
|
||||||
for bone := 0; bone < int(model.BoneCount)-1; bone++ {
|
|
||||||
if !animPlaying || animsCount == 0 {
|
|
||||||
// Display the bind-pose skeleton
|
|
||||||
rl.DrawCube(modelPoses[bone].Translation, 0.04, 0.04, 0.04, rl.Red)
|
|
||||||
if modelBones[bone].Parent >= 0 {
|
|
||||||
rl.DrawLine3D(modelPoses[bone].Translation, modelPoses[modelBones[bone].Parent].Translation, rl.Red)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// // Display the frame-pose skeleton
|
|
||||||
pos := anim.GetFramePose(animFrameCounter, bone).Translation
|
|
||||||
rl.DrawCube(pos, 0.05, 0.05, 0.05, rl.Red)
|
|
||||||
if animBones[bone].Parent >= 0 {
|
|
||||||
endPos := anim.GetFramePose(animFrameCounter, int(animBones[bone].Parent)).Translation
|
|
||||||
rl.DrawLine3D(pos, endPos, rl.Red)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawGrid(10, 1.0)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawText("PRESS SPACE to PLAY MODEL ANIMATION", 10, screenHeight-80, 10, rl.Maroon)
|
|
||||||
rl.DrawText("PRESS N to STEP ONE ANIMATION FRAME", 10, screenHeight-60, 10, rl.DarkGray)
|
|
||||||
rl.DrawText("PRESS C to CYCLE THROUGH ANIMATIONS", 10, screenHeight-40, 10, rl.DarkGray)
|
|
||||||
rl.DrawText("PRESS M to toggle MESH, B to toggle SKELETON DRAWING", 10, screenHeight-20, 10, rl.DarkGray)
|
|
||||||
rl.DrawText("(c) CesiumMan model by KhronosGroup", screenWidth-210, screenHeight-20, 10, rl.Gray)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
rl.UnloadModelAnimations(anims)
|
|
||||||
rl.UnloadModel(model)
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
|
@ -1,167 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
screenWidth := int32(1280)
|
|
||||||
screenHeight := int32(720)
|
|
||||||
|
|
||||||
numModels := 9
|
|
||||||
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh generation")
|
|
||||||
|
|
||||||
camera := rl.Camera{}
|
|
||||||
camera.Position = rl.NewVector3(10.0, 5.0, 10.0)
|
|
||||||
camera.Target = rl.NewVector3(0.0, 0.0, 0.0)
|
|
||||||
camera.Up = rl.NewVector3(0.0, 1.0, 0.0)
|
|
||||||
camera.Fovy = 45.0
|
|
||||||
camera.Projection = rl.CameraPerspective
|
|
||||||
|
|
||||||
checked := rl.GenImageChecked(2, 2, 1, 1, rl.Black, rl.Red)
|
|
||||||
texture := rl.LoadTextureFromImage(checked)
|
|
||||||
rl.UnloadImage(checked)
|
|
||||||
|
|
||||||
models := make([]rl.Model, numModels)
|
|
||||||
|
|
||||||
models[0] = rl.LoadModelFromMesh(rl.GenMeshPlane(2, 2, 4, 3))
|
|
||||||
models[1] = rl.LoadModelFromMesh(rl.GenMeshCube(2, 1, 2))
|
|
||||||
models[2] = rl.LoadModelFromMesh(rl.GenMeshSphere(2, 32, 32))
|
|
||||||
models[3] = rl.LoadModelFromMesh(rl.GenMeshHemiSphere(2, 16, 16))
|
|
||||||
models[4] = rl.LoadModelFromMesh(rl.GenMeshCylinder(1, 2, 16))
|
|
||||||
models[5] = rl.LoadModelFromMesh(rl.GenMeshTorus(0.25, 4, 16, 32))
|
|
||||||
models[6] = rl.LoadModelFromMesh(rl.GenMeshKnot(1, 2, 16, 128))
|
|
||||||
models[7] = rl.LoadModelFromMesh(rl.GenMeshPoly(5, 2))
|
|
||||||
models[8] = rl.LoadModelFromMesh(GenMeshCustom())
|
|
||||||
|
|
||||||
for i := 0; i < numModels; i++ {
|
|
||||||
rl.SetMaterialTexture(models[i].Materials, rl.MapDiffuse, texture)
|
|
||||||
}
|
|
||||||
|
|
||||||
position := rl.Vector3Zero()
|
|
||||||
|
|
||||||
currentModel := 0
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60)
|
|
||||||
|
|
||||||
for !rl.WindowShouldClose() {
|
|
||||||
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraOrbital)
|
|
||||||
|
|
||||||
if rl.IsKeyPressed(rl.KeyUp) {
|
|
||||||
currentModel = (currentModel + 1) % numModels // Cycle between the textures
|
|
||||||
}
|
|
||||||
if rl.IsKeyPressed(rl.KeyDown) {
|
|
||||||
// Adding numModels here is necessary to avoid a crash
|
|
||||||
// where the golang % (modulus) operator, doesn't work as
|
|
||||||
// one might expect for negative numbers.
|
|
||||||
currentModel = (currentModel + numModels - 1) % numModels // Cycle between the textures
|
|
||||||
}
|
|
||||||
if rl.IsMouseButtonPressed(rl.MouseButtonLeft) {
|
|
||||||
currentModel = (currentModel + 1) % numModels // Cycle between the textures
|
|
||||||
}
|
|
||||||
rl.BeginDrawing()
|
|
||||||
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
rl.DrawModel(models[currentModel], position, 1, rl.White)
|
|
||||||
rl.DrawGrid(10, 1)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
rl.DrawRectangle(10, 10, 310, 50, rl.Fade(rl.SkyBlue, 0.5))
|
|
||||||
rl.DrawRectangleLines(10, 10, 310, 50, rl.Fade(rl.DarkBlue, 0.5))
|
|
||||||
rl.DrawText("UP/DOWN ARROW KEY OR LEFT MOUSE", 20, 20, 10, rl.Blue)
|
|
||||||
rl.DrawText("BUTTON TO CHANGE MODELS", 20, 40, 10, rl.Blue)
|
|
||||||
|
|
||||||
txt := "PLANE"
|
|
||||||
switch currentModel {
|
|
||||||
case 1:
|
|
||||||
txt = "CUBE"
|
|
||||||
case 2:
|
|
||||||
txt = "SPHERE"
|
|
||||||
case 3:
|
|
||||||
txt = "HEMISPHERE"
|
|
||||||
case 4:
|
|
||||||
txt = "CYLINDER"
|
|
||||||
case 5:
|
|
||||||
txt = "TORUS"
|
|
||||||
case 6:
|
|
||||||
txt = "KNOT"
|
|
||||||
case 7:
|
|
||||||
txt = "POLY"
|
|
||||||
case 8:
|
|
||||||
txt = "Custom (triangle)"
|
|
||||||
}
|
|
||||||
txtlen := rl.MeasureText(txt, 20)
|
|
||||||
rl.DrawText(txt, screenWidth/2-txtlen/2, 10, 20, rl.DarkBlue)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.UnloadTexture(texture)
|
|
||||||
// Custom models meshes needs to be
|
|
||||||
// cleared manually
|
|
||||||
clearCustomMesh(models[8])
|
|
||||||
for i := 0; i < numModels; i++ {
|
|
||||||
rl.UnloadModel(models[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.CloseWindow()
|
|
||||||
}
|
|
||||||
|
|
||||||
func clearCustomMesh(model rl.Model) {
|
|
||||||
// Vertices, Normals and Texcoords of your CUSTOM mesh are Go slices.
|
|
||||||
// UnloadModel calls UnloadMesh for every mesh and UnloadMesh tries
|
|
||||||
// to free your Go slices. This will panic because it cannot free
|
|
||||||
// Go slices. Free() is a C function and it expects to free C memory
|
|
||||||
// and not a Go slice. So clear the slices manually like this.
|
|
||||||
model.Meshes.Vertices = nil
|
|
||||||
model.Meshes.Normals = nil
|
|
||||||
model.Meshes.Texcoords = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenMeshCustom generates a simple triangle mesh from code
|
|
||||||
func GenMeshCustom() rl.Mesh {
|
|
||||||
mesh := rl.Mesh{
|
|
||||||
TriangleCount: 1,
|
|
||||||
VertexCount: 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
var vertices, normals, texcoords []float32
|
|
||||||
|
|
||||||
// 3 vertices
|
|
||||||
vertices = addCoord(vertices, 0, 0, 0)
|
|
||||||
vertices = addCoord(vertices, 1, 0, 2)
|
|
||||||
vertices = addCoord(vertices, 2, 0, 0)
|
|
||||||
mesh.Vertices = unsafe.SliceData(vertices)
|
|
||||||
|
|
||||||
// 3 normals
|
|
||||||
normals = addCoord(normals, 0, 1, 0)
|
|
||||||
normals = addCoord(normals, 0, 1, 0)
|
|
||||||
normals = addCoord(normals, 0, 1, 0)
|
|
||||||
mesh.Normals = unsafe.SliceData(normals)
|
|
||||||
|
|
||||||
// 3 texcoords
|
|
||||||
texcoords = addCoord(texcoords, 0, 0)
|
|
||||||
texcoords = addCoord(texcoords, 0.5, 1)
|
|
||||||
texcoords = addCoord(texcoords, 1, 0)
|
|
||||||
mesh.Texcoords = unsafe.SliceData(texcoords)
|
|
||||||
|
|
||||||
// Upload mesh data from CPU (RAM) to GPU (VRAM) memory
|
|
||||||
rl.UploadMesh(&mesh, false)
|
|
||||||
|
|
||||||
return mesh
|
|
||||||
}
|
|
||||||
|
|
||||||
func addCoord(slice []float32, values ...float32) []float32 {
|
|
||||||
for _, value := range values {
|
|
||||||
slice = append(slice, value)
|
|
||||||
}
|
|
||||||
return slice
|
|
||||||
}
|
|
|
@ -1,261 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh
|
|
||||||
*
|
|
||||||
* Example originally created with raylib 1.7, last time updated with raylib 4.0
|
|
||||||
*
|
|
||||||
* Example contributed by Joel Davis (@joeld42) and reviewed by Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
||||||
* BSD-like license that allows static linking with closed source software
|
|
||||||
*
|
|
||||||
* Copyright (c) 2017-2024 Joel Davis (@joeld42) and Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
********************************************************************************************/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
screenWidth = 800
|
|
||||||
screenHeight = 450
|
|
||||||
)
|
|
||||||
|
|
||||||
// Program main entry point
|
|
||||||
func main() {
|
|
||||||
rl.InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking")
|
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
|
||||||
camera := rl.Camera{
|
|
||||||
Position: rl.Vector3{
|
|
||||||
X: 20.0,
|
|
||||||
Y: 20.0,
|
|
||||||
Z: 20.0,
|
|
||||||
}, // Camera position
|
|
||||||
Target: rl.Vector3{Y: 8.0}, // Camera looking at point
|
|
||||||
Up: rl.Vector3{Y: 1.6}, // Camera up vector (rotation towards target)
|
|
||||||
Fovy: 45.0, // Camera field-of-view Y
|
|
||||||
Projection: rl.CameraPerspective, // Camera projection type
|
|
||||||
}
|
|
||||||
var ray rl.Ray // Picking ray
|
|
||||||
|
|
||||||
tower := rl.LoadModel("turret.obj") // Load OBJ model
|
|
||||||
texture := rl.LoadTexture("turret_diffuse.png") // Load model texture
|
|
||||||
materials := unsafe.Slice(tower.Materials, tower.MaterialCount)
|
|
||||||
materials[0].GetMap(rl.MapDiffuse).Texture = texture // Set model diffuse texture
|
|
||||||
|
|
||||||
towerPos := rl.Vector3{} // Set model position
|
|
||||||
meshes := unsafe.Slice(tower.Meshes, tower.MeshCount)
|
|
||||||
towerBBox := rl.GetMeshBoundingBox(meshes[0]) // Get mesh bounding box
|
|
||||||
|
|
||||||
// Ground quad
|
|
||||||
g0 := rl.Vector3{
|
|
||||||
X: -50.0,
|
|
||||||
Z: -50.0,
|
|
||||||
}
|
|
||||||
g1 := rl.Vector3{
|
|
||||||
X: -50.0,
|
|
||||||
Z: 50.0,
|
|
||||||
}
|
|
||||||
g2 := rl.Vector3{
|
|
||||||
X: 50.0,
|
|
||||||
Z: 50.0,
|
|
||||||
}
|
|
||||||
g3 := rl.Vector3{
|
|
||||||
X: 50.0,
|
|
||||||
Z: -50.0,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test triangle
|
|
||||||
ta := rl.Vector3{
|
|
||||||
X: -25.0,
|
|
||||||
Y: 0.5,
|
|
||||||
}
|
|
||||||
tb := rl.Vector3{
|
|
||||||
X: -4.0,
|
|
||||||
Y: 2.5,
|
|
||||||
Z: 1.0,
|
|
||||||
}
|
|
||||||
tc := rl.Vector3{
|
|
||||||
X: -8.0,
|
|
||||||
Y: 6.5,
|
|
||||||
}
|
|
||||||
|
|
||||||
bary := rl.Vector3{}
|
|
||||||
|
|
||||||
// Test sphere
|
|
||||||
sp := rl.Vector3{
|
|
||||||
X: -30.0,
|
|
||||||
Y: 5.0,
|
|
||||||
Z: 5.0,
|
|
||||||
}
|
|
||||||
sr := float32(4.0)
|
|
||||||
|
|
||||||
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
|
|
||||||
// Main game loop
|
|
||||||
for !rl.WindowShouldClose() { // Detect window close button or ESC key
|
|
||||||
// Update
|
|
||||||
if rl.IsCursorHidden() {
|
|
||||||
rl.UpdateCamera(&camera, rl.CameraFirstPerson) // Update camera
|
|
||||||
}
|
|
||||||
// Toggle camera controls
|
|
||||||
if rl.IsMouseButtonPressed(rl.MouseButtonRight) {
|
|
||||||
if rl.IsCursorHidden() {
|
|
||||||
rl.EnableCursor()
|
|
||||||
} else {
|
|
||||||
rl.DisableCursor()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display information about the closest hit
|
|
||||||
collision := rl.RayCollision{
|
|
||||||
Distance: math.MaxFloat32,
|
|
||||||
Hit: false,
|
|
||||||
}
|
|
||||||
hitObjectName := "None"
|
|
||||||
cursorColor := rl.White
|
|
||||||
|
|
||||||
// Get ray and test against objects
|
|
||||||
// See issue : https://git.terah.dev/UnrealXR/raylib-go/issues/457
|
|
||||||
//ray = rl.GetScreenToWorldRay(rl.GetMousePosition(), camera)
|
|
||||||
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
|
||||||
|
|
||||||
// Check ray collision against ground quad
|
|
||||||
groundHitInfo := rl.GetRayCollisionQuad(ray, g0, g1, g2, g3)
|
|
||||||
|
|
||||||
if (groundHitInfo.Hit) && (groundHitInfo.Distance < collision.Distance) {
|
|
||||||
collision = groundHitInfo
|
|
||||||
cursorColor = rl.Green
|
|
||||||
hitObjectName = "Ground"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ray collision against test triangle
|
|
||||||
triHitInfo := rl.GetRayCollisionTriangle(ray, ta, tb, tc)
|
|
||||||
|
|
||||||
if (triHitInfo.Hit) && (triHitInfo.Distance < collision.Distance) {
|
|
||||||
collision = triHitInfo
|
|
||||||
cursorColor = rl.Purple
|
|
||||||
hitObjectName = "Triangle"
|
|
||||||
|
|
||||||
bary = rl.Vector3Barycenter(collision.Point, ta, tb, tc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ray collision against test sphere
|
|
||||||
sphereHitInfo := rl.GetRayCollisionSphere(ray, sp, sr)
|
|
||||||
|
|
||||||
if (sphereHitInfo.Hit) && (sphereHitInfo.Distance < collision.Distance) {
|
|
||||||
collision = sphereHitInfo
|
|
||||||
cursorColor = rl.Orange
|
|
||||||
hitObjectName = "Sphere"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check ray collision against bounding box first, before trying the full ray-mesh test
|
|
||||||
boxHitInfo := rl.GetRayCollisionBox(ray, towerBBox)
|
|
||||||
|
|
||||||
if (boxHitInfo.Hit) && (boxHitInfo.Distance < collision.Distance) {
|
|
||||||
collision = boxHitInfo
|
|
||||||
cursorColor = rl.Orange
|
|
||||||
hitObjectName = "Box"
|
|
||||||
|
|
||||||
// Check ray collision against model meshes
|
|
||||||
meshHitInfo := rl.RayCollision{}
|
|
||||||
for m := int32(0); m < tower.MeshCount; m++ {
|
|
||||||
// NOTE: We consider the model.transform for the collision check, but
|
|
||||||
// it can be checked against any transform Matrix, used when checking against same
|
|
||||||
// model drawn multiple times with multiple transforms
|
|
||||||
meshHitInfo = rl.GetRayCollisionMesh(ray, meshes[m], tower.Transform)
|
|
||||||
if meshHitInfo.Hit {
|
|
||||||
// Save the closest hit mesh
|
|
||||||
if (!collision.Hit) || (collision.Distance > meshHitInfo.Distance) {
|
|
||||||
collision = meshHitInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
break // Stop once one mesh collision is detected, the colliding mesh is m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if meshHitInfo.Hit {
|
|
||||||
collision = meshHitInfo
|
|
||||||
cursorColor = rl.Orange
|
|
||||||
hitObjectName = "Mesh"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw
|
|
||||||
rl.BeginDrawing()
|
|
||||||
rl.ClearBackground(rl.RayWhite)
|
|
||||||
rl.BeginMode3D(camera)
|
|
||||||
|
|
||||||
// Draw the tower
|
|
||||||
// WARNING: If scale is different from 1.0f,
|
|
||||||
// not considered by GetRayCollisionModel()
|
|
||||||
rl.DrawModel(tower, towerPos, 1.0, rl.White)
|
|
||||||
|
|
||||||
// Draw the test triangle
|
|
||||||
rl.DrawLine3D(ta, tb, rl.Purple)
|
|
||||||
rl.DrawLine3D(tb, tc, rl.Purple)
|
|
||||||
rl.DrawLine3D(tc, ta, rl.Purple)
|
|
||||||
|
|
||||||
// Draw the test sphere
|
|
||||||
rl.DrawSphereWires(sp, sr, 8, 8, rl.Purple)
|
|
||||||
|
|
||||||
// Draw the mesh bbox if we hit it
|
|
||||||
if boxHitInfo.Hit {
|
|
||||||
rl.DrawBoundingBox(towerBBox, rl.Lime)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we hit something, draw the cursor at the hit point
|
|
||||||
if collision.Hit {
|
|
||||||
rl.DrawCube(collision.Point, 0.3, 0.3, 0.3, cursorColor)
|
|
||||||
rl.DrawCubeWires(collision.Point, 0.3, 0.3, 0.3, rl.Red)
|
|
||||||
|
|
||||||
normalEnd := rl.Vector3{}
|
|
||||||
normalEnd.X = collision.Point.X + collision.Normal.X
|
|
||||||
normalEnd.Y = collision.Point.Y + collision.Normal.Y
|
|
||||||
normalEnd.Z = collision.Point.Z + collision.Normal.Z
|
|
||||||
|
|
||||||
rl.DrawLine3D(collision.Point, normalEnd, rl.Red)
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawRay(ray, rl.Maroon)
|
|
||||||
rl.DrawGrid(10, 10.0)
|
|
||||||
|
|
||||||
rl.EndMode3D()
|
|
||||||
|
|
||||||
// Draw some debug GUI text
|
|
||||||
rl.DrawText(fmt.Sprintf("Hit Object: %s", hitObjectName), 10, 50, 10, rl.Black)
|
|
||||||
|
|
||||||
if collision.Hit {
|
|
||||||
ypos := int32(70)
|
|
||||||
rl.DrawText(fmt.Sprintf("Distance: %3.2f", collision.Distance), 10, ypos, 10, rl.Black)
|
|
||||||
rl.DrawText(Vec2Str("Hit Pos : %3.2f %3.2f %3.2f", collision.Point), 10, ypos+15, 10, rl.Black)
|
|
||||||
rl.DrawText(Vec2Str("Hit Norm: %3.2f %3.2f %3.2f", collision.Normal), 10, ypos+30, 10, rl.Black)
|
|
||||||
if triHitInfo.Hit && hitObjectName == "Triangle" {
|
|
||||||
rl.DrawText(Vec2Str("Barycenter: %3.2f %3.2f %3.2f", bary), 10, ypos+45, 10, rl.Black)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.DrawText("Right click mouse to toggle camera controls", 10, 430, 10, rl.Gray)
|
|
||||||
rl.DrawText("(c) Turret 3D model by Alberto Cano", screenWidth-200, screenHeight-20, 10, rl.Gray)
|
|
||||||
|
|
||||||
rl.DrawFPS(10, 10)
|
|
||||||
|
|
||||||
rl.EndDrawing()
|
|
||||||
}
|
|
||||||
|
|
||||||
// De-Initialization
|
|
||||||
rl.UnloadModel(tower) // Unload model
|
|
||||||
rl.UnloadTexture(texture) // Unload texture
|
|
||||||
|
|
||||||
rl.CloseWindow() // Close window and OpenGL context
|
|
||||||
}
|
|
||||||
|
|
||||||
func Vec2Str(format string, vec rl.Vector3) string {
|
|
||||||
return fmt.Sprintf(format, vec.X, vec.Y, vec.Z)
|
|
||||||
}
|
|