Compare commits

...

60 commits

Author SHA1 Message Date
1468af2636 chore: Update README with notice of the fork status and build tags 2025-06-22 20:27:39 -04:00
d63f1b19df
chore: Fix module path 2025-06-22 17:48:18 -04:00
45473d7240
feature: Add DRM leasing code 2025-06-22 17:41:05 -04:00
3df816e2bf
chore: Remove broken CI workflows 2025-06-22 17:40:19 -04:00
d707d9e51c
chore: Initial attempt to migrate workflows
Some checks failed
Build / test-rgfw (1.21.x, docker) (push) Has been cancelled
Build / test-purego (1.21.x, docker) (push) Has been cancelled
Build / test-examples (1.21.x, docker) (push) Has been cancelled
Build / test-sdl (1.21.x, docker) (push) Has been cancelled
Build / test (1.21.x, docker) (push) Has been cancelled
Build / test-drm (1.21.x, docker) (push) Has been cancelled
2025-06-21 13:32:42 -04:00
bc3da009ef
fix: Fixes image URL
Some checks are pending
Build / test-rgfw (1.21.x, windows-latest) (push) Waiting to run
Build / test-purego (1.21.x, ubuntu-latest) (push) Waiting to run
Build / test-examples (1.21.x, ubuntu-latest) (push) Waiting to run
Build / test (1.21.x, macos-latest) (push) Waiting to run
Build / test (1.21.x, ubuntu-latest) (push) Waiting to run
Build / test (1.21.x, windows-latest) (push) Waiting to run
Build / test-drm (1.21.x, ubuntu-latest) (push) Waiting to run
Build / test-sdl (1.21.x, ubuntu-latest) (push) Waiting to run
Build / test-rgfw (1.21.x, macos-latest) (push) Waiting to run
Build / test-rgfw (1.21.x, ubuntu-latest) (push) Waiting to run
2025-06-21 13:24:38 -04:00
Milan Nikolic
eddd038123
Update README.md 2025-06-17 21:43:46 +02:00
Milan Nikolic
6039070d78
Merge pull request #505 from JupiterRider/raygui_return_values
raygui: fix Spinner() return value and fix possible misuse of unsafe.Pointer
2025-06-17 19:41:27 +02:00
JupiterRider
9a87dd6d60 raygui: Spinner returns true if clicked #503 2025-06-17 17:48:13 +02:00
JupiterRider
7e9246c069 raygui/cstring.go: "fix" possible misuse of unsafe.Pointer 2025-06-17 17:47:09 +02:00
Milan Nikolic
5d704708c4
Update bunnymark, issue #480 2025-06-09 19:36:06 +02:00
Milan Nikolic
3327fcaf9f
Update C sources 2025-06-09 15:53:56 +02:00
Milan Nikolic
e08c4cd054
Remove rres 2025-06-09 15:53:08 +02:00
Milan Nikolic
fca3bf26c5
Merge pull request #500 from lloydlobo/lloydlobo/examples-vertex-displacement
[examples] Add shader example: `vertex_displacement`
2025-05-21 23:03:03 +02:00
Lloyd Lobo
1d42dc5846 docs(examples): remove screenshot and screen recording artifacts
- remove screenshot PNG
- remove screenrec GIF
2025-05-18 15:02:12 +05:30
Lloyd Lobo
0380afdf21 docs(examples): create vertex_displacement example 2025-05-18 11:44:24 +05:30
Milan Nikolic
e6017e5fc4
Merge pull request #497 from SunnyFuji/patch-1
Create main.go
2025-05-04 04:26:11 +02:00
Milan Nikolic
5ca0e770e3
Merge pull request #486 from mohsengreen1388/pbr-example
example: I can add physic base render to example
2025-05-04 04:25:48 +02:00
SunnyFuji
761bde1e61
Create main.go
I created a pong Game and would like to submit it to the examples catalogue. I have debugged it and the only external dependencies are this projects and fmt.
2025-04-19 14:35:50 -05:00
Milan Nikolic
a4292f0f04
Merge pull request #495 from thearturca/feat/unload-sound-alias
feat(raylib): adds UnloadSoundAlias function
2025-04-09 07:28:54 +02:00
thearturca
ce20f0c639 feat(raylib): adds UnloadSoundAlias function
docs(raudio): adds function name to UnloadSoundAlias comment
2025-03-31 10:59:58 +03:00
Milan Nikolic
b542022337
Merge pull request #493 from jroimartin/wave-ptr
Change `WaveFormat` and `WaveCrop` signatures to accept a pointer to `Wave`
2025-03-27 11:37:58 +01:00
Roi Martin
705f704ecf Change WaveFormat and WaveCrop signatures to accept a pointer to Wave
The raylib functions `WaveFormat` and `WaveCrop` accept a pointer to
`Wave` because the wave is updated in-place. However, the current Go
bindings pass a copy of the wave to the C functions, so it is not
updated. This commit changes the signatures of the Go API so they also
accept a pointer to `Wave`.
2025-03-27 09:12:54 +01:00
Milan Nikolic
db8e47f0e5
Merge pull request #489 from JupiterRider/missing_rlgl_constants
missing constants from RLGL added
2025-02-15 05:22:52 +01:00
JupiterRider
3fd9012394 missing constants from RLGL added (fixes #488) 2025-02-14 22:42:09 +01:00
Mohsen Baghri
960a135c15 example: I can add physic base render to example 2025-01-26 21:57:23 +03:30
Milan Nikolic
6dbba4f81a
Merge pull request #484 from geo-stark/master
Add GetClipboardImage for drm platform.
2025-01-09 18:28:33 +01:00
George Stark
e31988d117 Add GetClipboardImage for drm platform.
Signed-off-by: George Stark <stark.georgy@gmail.com>
2025-01-09 19:07:59 +03:00
Milan Nikolic
d58ffe1a3a
Merge pull request #479 from sugarvoid/master
Add return value to `LoadTextureDepth`
2024-12-28 13:07:19 +01:00
sugarvoid
ff0ecd0e76 Add return value in rlgl_purego.go 2024-12-28 05:23:49 -06:00
sugarvoid
8e035f761c Add return value to LoadTextureDepth 2024-12-27 07:59:46 -06:00
Milan Nikolic
453bad2769
Merge pull request #477 from JupiterRider/rgfw_rumble
rcore_desktop_rgfw.c SetGamepadVibration added
2024-12-17 19:56:05 +01:00
JupiterRider
2040136e38 rcore_desktop_rgfw.c SetGamepadVibration added 2024-12-17 19:42:54 +01:00
Milan Nikolic
edb2c107b3
Merge pull request #476 from Alireza-Ta/android_enhancement
Android Compilation Enhancement
2024-12-17 12:51:49 +01:00
Milan Nikolic
078d0bec34
Merge pull request #475 from JupiterRider/audiostream_processor
fix purego version of DetachAudioStreamProcessor and DetachAudioMixedProcessor
2024-12-17 12:51:40 +01:00
Alireza-Ta
5dad257e8d Update androidcompile.bat file with minor tweaks. 2024-12-17 14:54:04 +03:30
Alireza-Ta
8490a60f72 Add GetClipboardImage for android platform. 2024-12-17 11:09:31 +03:30
JupiterRider
5868292fd5 fix purego version of DetachAudioStreamProcessor and DetachAudioMixedProcessor #425 2024-12-15 18:19:57 +01:00
Milan Nikolic
7a899c5e3a
Merge pull request #474 from JupiterRider/model_animation
ModelAnimation improvements
2024-12-15 05:38:39 +01:00
JupiterRider
c301540ef5 gltf_loading example shows the name of the current animation now 2024-12-14 22:04:59 +01:00
JupiterRider
041142d30c update another ModelAnimation example 2024-12-14 21:57:46 +01:00
JupiterRider
46524a8c46 Update examples for #466 2024-12-14 21:47:37 +01:00
JupiterRider
533c35110b ModelAnimation.GetName() added 2024-12-14 21:26:58 +01:00
JupiterRider
dce94f509d ModelAnimation.GetFramePose() added #466 2024-12-14 21:15:08 +01:00
JupiterRider
98ce816ab8 ModelAnimation.GetBones() added #466 2024-12-14 20:19:05 +01:00
Milan Nikolic
a9ad86d501
Update wayland headers 2024-12-07 12:43:08 +01:00
Milan Nikolic
659b0700ba
Add support for vendor 2024-12-07 11:37:19 +01:00
Milan Nikolic
3b89a24e68
Update README.md 2024-12-03 10:19:12 +01:00
Milan Nikolic
28ef2a891c
Update README.md 2024-12-03 09:25:44 +01:00
Milan Nikolic
b6bb8ec528
Export Wave data, issue #402 2024-12-03 09:17:34 +01:00
Milan Nikolic
ea071de5c2
Add support for SDL3 2024-12-03 09:06:39 +01:00
Milan Nikolic
5df9325f63
Add wayland build tag, issue #404 2024-12-03 08:00:59 +01:00
Milan Nikolic
aef24a2104
Update README.md 2024-12-03 07:15:50 +01:00
Milan Nikolic
c4ef7b53e9
Merge pull request #470 from Hultan/draw_cube_texture
New example: models/draw_cube_textured
2024-12-03 07:13:53 +01:00
Milan Nikolic
b6d58c5ba6
Merge pull request #469 from Hultan/yaw_pitch_roll
New example: models/yaw_pitch_roll
2024-12-03 07:13:38 +01:00
Milan Nikolic
db948137ee
Merge pull request #468 from Hultan/rlgl_solar_system
Models/rlgl_solar_system example
2024-12-03 07:13:24 +01:00
Per Hultqvist
8d54e15dc2 New example: models/draw_cube_textured 2024-11-18 14:18:05 +01:00
Per Hultqvist
bc9182ac34 New example: models/yaw_pitch_roll 2024-11-18 13:22:01 +01:00
Per Hultqvist
af2e6d755e New example: models/rlgl_solar_system 2024-11-18 12:41:48 +01:00
Per Hultqvist
5b33862cc1 Example fixed models/rlgl_solar_system 2024-11-18 12:19:33 +01:00
275 changed files with 29195 additions and 23976 deletions

View file

@ -1,143 +0,0 @@
on: [push, pull_request]
name: Build
jobs:
test:
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install package
run: |
sudo apt-get update -y; sudo apt-get -y install libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev libgl1-mesa-dev libwayland-dev libxkbcommon-dev
if: runner.os == 'Linux'
- name: Build
run: go build ./...
working-directory: raylib
- name: Verify dependencies
run: go mod verify
working-directory: raylib
- name: Build
run: go build -v ./...
working-directory: raylib
- name: Run go vet
run: go vet ./...
working-directory: raylib
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
working-directory: raylib
- name: Run staticcheck
run: staticcheck ./...
working-directory: raylib
- name: Run tests
run: go test -race -vet=off ./...
working-directory: raylib
test-drm:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install package
run: |
sudo apt-get update -y; sudo apt-get -y install libegl1-mesa-dev libdrm-dev libgbm-dev
- name: Build
run: go build -tags drm
working-directory: raylib
test-sdl:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install package
run: |
sudo apt-get update -y; sudo apt-get -y install libgl1-mesa-dev libsdl2-dev
- name: Build
run: go build -tags sdl
working-directory: raylib
test-rgfw:
strategy:
fail-fast: false
matrix:
go-version: [1.21.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install package
run: |
sudo apt-get update -y; sudo apt-get -y install libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev libgl1-mesa-dev libxkbcommon-dev
if: runner.os == 'Linux'
- name: Build
run: go build -tags rgfw
working-directory: raylib
test-purego:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Build
run: go build
working-directory: raylib
env:
GOOS: windows
test-examples:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install package
run: |
sudo apt-get update -y; sudo apt-get -y install libxi-dev libxinerama-dev libxcursor-dev libxrandr-dev libgl1-mesa-dev libwayland-dev libxkbcommon-dev
- name: Build
run: go build ./...
working-directory: examples

View file

@ -1,12 +1,14 @@
![logo](https://goo.gl/XlIcXz)
![logo](https://git.terah.dev/UnrealXR/raylib-go/raw/branch/master/assets/raylib-go_256x256.png)
## raylib-go
[![Build Status](https://github.com/gen2brain/raylib-go/actions/workflows/build.yml/badge.svg)](https://github.com/gen2brain/raylib-go/actions)
[![GoDoc](https://godoc.org/github.com/gen2brain/raylib-go/raylib?status.svg)](https://godoc.org/github.com/gen2brain/raylib-go/raylib)
[![Go Report Card](https://goreportcard.com/badge/github.com/gen2brain/raylib-go/raylib)](https://goreportcard.com/report/github.com/gen2brain/raylib-go/raylib)
[![Examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/gen2brain/raylib-go/tree/master/examples)
[![Build Status](https://git.terah.dev/UnrealXR/raylib-go/actions/workflows/build.yml/badge.svg)](https://git.terah.dev/UnrealXR/raylib-go/actions)
[![GoDoc](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/raylib?status.svg)](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/raylib)
[![Go Report Card](https://goreportcard.com/badge/git.terah.dev/UnrealXR/raylib-go/raylib)](https://goreportcard.com/report/git.terah.dev/UnrealXR/raylib-go/raylib)
[![Examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://git.terah.dev/UnrealXR/raylib-go/src/branch/master/examples)
Golang bindings for [raylib](http://www.raylib.com/), a simple and easy-to-use library to enjoy 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).
@ -23,7 +25,7 @@ It is also possible to use raylib-go without cgo (Windows only; see requirements
##### macOS
On macOS you need Xcode or Command Line Tools for Xcode.
On macOS, you need Xcode or Command Line Tools for Xcode (if you have `brew` installed, you already have this).
##### Windows
@ -39,22 +41,28 @@ To remove console window, build with `-ldflags "-H=windowsgui"`.
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.
As of November 15, 2023, raylib 5.0 is the required version.
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 example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example).
[Android example](https://git.terah.dev/UnrealXR/raylib-go/tree/master/examples/others/android/example).
##### Wasm
For web bindings, refer to [Raylib-Go-Wasm](https://github.com/BrownNPC/Raylib-Go-Wasm); it should be largely compatible with this repository.
### Installation
go get -v -u github.com/gen2brain/raylib-go/raylib
go get -v -u git.terah.dev/UnrealXR/raylib-go/raylib
### 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
* `opengl43` - uses OpenGL 4.3 backend
@ -63,17 +71,18 @@ It is also possible to build the DLL yourself. You can find more info at [raylib
* `es2` - uses OpenGL ES 2.0 backend (can be used to link against [Google's ANGLE](https://github.com/google/angle))
* `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 on [GoDoc](https://godoc.org/github.com/gen2brain/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/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.
### Example
```go
package main
import rl "github.com/gen2brain/raylib-go/raylib"
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
func main() {
rl.InitWindow(800, 450, "raylib [core] example - basic window")
@ -92,7 +101,7 @@ func main() {
}
```
Check more [examples](https://github.com/gen2brain/raylib-go/tree/master/examples) organized by raylib modules.
Check more [examples](https://git.terah.dev/UnrealXR/raylib-go/tree/master/examples) organized by raylib modules.
### Cross-compile (Linux)
@ -122,4 +131,4 @@ basic_window: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|
### License
raylib-go is licensed under an unmodified zlib/libpng license. View [LICENSE](https://github.com/gen2brain/raylib-go/blob/master/LICENSE).
raylib-go is licensed under an unmodified zlib/libpng license. View [LICENSE](https://git.terah.dev/UnrealXR/raylib-go/blob/master/LICENSE).

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -1,4 +1,4 @@
## easings [![GoDoc](https://godoc.org/github.com/gen2brain/raylib-go/easings?status.svg)](https://godoc.org/github.com/gen2brain/raylib-go/easings)
## easings [![GoDoc](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/easings?status.svg)](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/easings)
Useful easing functions for values animation.

View file

@ -1,3 +1,3 @@
module github.com/gen2brain/raylib-go/easings
module git.terah.dev/UnrealXR/raylib-go/easings
go 1.21

View file

@ -18,7 +18,7 @@ import (
"fmt"
"math"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
const maxCircles = 64

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
rl.InitAudioDevice()

View file

@ -5,7 +5,7 @@ import (
"math"
"time"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -12,7 +12,7 @@
********************************************************************************************/
package main
import rl "github.com/gen2brain/raylib-go/raylib"
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
const (
screenWidth = 800

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
var (

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
/*******************************************************************************************
*
* raylib [core] example - 2d camera mouse zoom

View file

@ -1,6 +1,6 @@
package main
import rl "github.com/gen2brain/raylib-go/raylib"
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
const (
screenWidth = 800

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
var (

View file

@ -3,7 +3,7 @@ package main
import (
"os"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const colorCount = 23

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
var (

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,6 +1,6 @@
package main
import "github.com/gen2brain/raylib-go/raylib"
import "git.terah.dev/UnrealXR/raylib-go/raylib"
func main() {
rl.SetConfigFlags(rl.FlagVsyncHint)

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const screenW = int32(1280)

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
/*******************************************************************************************

View file

@ -31,7 +31,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -4,7 +4,7 @@ import (
"fmt"
"time"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
var (
maxGestureStrings int = 20
)

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
var (

View file

@ -4,7 +4,7 @@ import (
"fmt"
"math"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const screenW = int32(1280)

View file

@ -17,7 +17,7 @@ import (
"fmt"
"os"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -15,7 +15,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -16,7 +16,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -4,7 +4,7 @@ import (
"fmt"
"image/color"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,6 +1,6 @@
package main
import rl "github.com/gen2brain/raylib-go/raylib"
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
const (
screenWidth = 850

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,9 +3,9 @@ package main
import (
"strings"
"github.com/gen2brain/raylib-go/easings"
"github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/easings"
"git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -18,7 +18,7 @@ package main
import (
"math"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -4,8 +4,6 @@ import (
"fmt"
"os"
"runtime"
"github.com/gen2brain/raylib-go/raylib"
)
const (

View file

@ -4,7 +4,7 @@ import (
"math/rand"
"time"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

174
examples/games/pong/main.go Normal file
View file

@ -0,0 +1,174 @@
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()
}

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
const (
snakeLength = 256
squareSize = 31

View file

@ -2,19 +2,19 @@ module examples
go 1.21
replace github.com/gen2brain/raylib-go/raylib => ../raylib
replace git.terah.dev/UnrealXR/raylib-go/raylib => ../raylib
replace github.com/gen2brain/raylib-go/raygui => ../raygui
replace git.terah.dev/UnrealXR/raylib-go/raygui => ../raygui
replace github.com/gen2brain/raylib-go/easings => ../easings
replace git.terah.dev/UnrealXR/raylib-go/easings => ../easings
replace github.com/gen2brain/raylib-go/physics => ../physics
replace git.terah.dev/UnrealXR/raylib-go/physics => ../physics
require (
github.com/gen2brain/raylib-go/easings v0.0.0-00010101000000-000000000000
github.com/gen2brain/raylib-go/physics v0.0.0-00010101000000-000000000000
github.com/gen2brain/raylib-go/raygui v0.0.0-00010101000000-000000000000
github.com/gen2brain/raylib-go/raylib v0.0.0-20241202103652-5d50abe7c65b
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
)

View file

@ -3,8 +3,8 @@ package main
import (
"fmt"
gui "github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,8 +3,8 @@ package main
import (
"fmt"
gui "github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
/*******************************************************************************************

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,8 +3,8 @@ package main
import (
"fmt"
gui "github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
/*******************************************************************************************

View file

@ -3,8 +3,8 @@ package main
import (
"fmt"
gui "github.com/gen2brain/raylib-go/raygui"
rl "github.com/gen2brain/raylib-go/raylib"
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
/*******************************************************************************************

View file

@ -21,9 +21,7 @@
package main
import (
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (
@ -76,9 +74,8 @@ func main() {
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++ {
framePose := unsafe.Slice(anims[0].FramePoses, anims[0].FrameCount)
trans := unsafe.Slice(framePose[animFrameCount], model.BoneCount)
rl.DrawCube(trans[i].Translation, 0.2, 0.2, 0.2, rl.Red)
pose := anims[0].GetFramePose(animFrameCount, int(i))
rl.DrawCube(pose.Translation, 0.2, 0.2, 0.2, rl.Red)
}
rl.DrawGrid(10, 1)

View file

@ -12,7 +12,7 @@
********************************************************************************************/package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,7 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View file

@ -0,0 +1,256 @@
/*******************************************************************************************
*
* 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)
}

View file

@ -2,8 +2,8 @@
*
* raylib [models] example - first person maze
*
* This example has been created using raylib-go v0.0.0-20220104071325-2f072dc2d259 (https://github.com/gen2brain/raylib-go)
* raylib-go is licensed under an unmodified zlib/libpng license (https://github.com/gen2brain/raylib-go/blob/master/LICENSE)
* 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
@ -13,7 +13,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,9 +1,5 @@
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {
@ -62,7 +62,7 @@ func main() {
rl.EndMode3D()
rl.DrawText("current animation number: "+fmt.Sprint(animIndex), 10, 10, 10, rl.Black)
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()

View file

@ -3,7 +3,7 @@ package main
import (
//"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -19,9 +19,7 @@
package main
import (
"unsafe"
"github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (
@ -116,9 +114,8 @@ func main() {
if drawSkeleton {
modelBones := model.GetBones()
modelPoses := model.GetBindPose()
animBones := unsafe.Slice(anims[animID].Bones, anims[animID].BoneCount)
animPoses := unsafe.Slice(anims[animID].FramePoses, anims[animID].FrameCount)
transforms := unsafe.Slice(animPoses[animFrameCounter], anims[animID].BoneCount)
anim := anims[animID]
animBones := anim.GetBones()
for bone := 0; bone < int(model.BoneCount)-1; bone++ {
if !animPlaying || animsCount == 0 {
// Display the bind-pose skeleton
@ -128,9 +125,11 @@ func main() {
}
} else {
// // Display the frame-pose skeleton
rl.DrawCube(transforms[bone].Translation, 0.05, 0.05, 0.05, rl.Red)
pos := anim.GetFramePose(animFrameCounter, bone).Translation
rl.DrawCube(pos, 0.05, 0.05, 0.05, rl.Red)
if animBones[bone].Parent >= 0 {
rl.DrawLine3D(transforms[bone].Translation, transforms[animBones[bone].Parent].Translation, rl.Red)
endPos := anim.GetFramePose(animFrameCounter, int(animBones[bone].Parent)).Translation
rl.DrawLine3D(pos, endPos, rl.Red)
}
}
}

View file

@ -3,7 +3,7 @@ package main
import (
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -19,7 +19,7 @@ import (
"math"
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (
@ -122,7 +122,7 @@ func main() {
cursorColor := rl.White
// Get ray and test against objects
// See issue : https://github.com/gen2brain/raylib-go/issues/457
// See issue : https://git.terah.dev/UnrealXR/raylib-go/issues/457
//ray = rl.GetScreenToWorldRay(rl.GetMousePosition(), camera)
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)

View file

@ -5,7 +5,7 @@ import (
"slices"
"unsafe"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
var supportedFileTypes = []string{

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -0,0 +1,155 @@
/*******************************************************************************************
*
* raylib [models] example - rlgl module usage with push/pop matrix transformations
*
* NOTE: This example uses [rlgl] module functionality (pseudo-OpenGL 1.1 style coding)
*
* 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) 2018-2024 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
package main
import (
"math"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (
screenWidth = 800
screenHeight = 450
sunRadius = 4.0
earthRadius = 0.6
moonRadius = 0.16
earthOrbitRadius = 8.0
moonOrbitRadius = 1.5
rings, slices = 16, 16
)
func main() {
// Initialization
title := "raylib [models] example - rlgl module usage with push/pop matrix transformations"
rl.InitWindow(screenWidth, screenHeight, title)
// Define the camera to look into our 3d world
camera := rl.Camera{
Position: rl.Vector3{
X: 16.0,
Y: 16.0,
Z: 16.0,
}, // Camera position
Target: rl.Vector3{}, // Camera looking at point
Up: rl.Vector3{Y: 1.0}, // Camera up vector (rotation towards target)
Fovy: 45.0, // Camera field-of-view Y
Projection: rl.CameraPerspective, // Camera projection type
}
var rotationSpeed float32 = 0.2 // General system rotation speed
var earthRotation float32 // Rotation of earth around itself (days) in degrees
var earthOrbitRotation float32 // Rotation of earth around the Sun (years) in degrees
var moonRotation float32 // Rotation of moon around itself
var moonOrbitRotation float32 // Rotation of moon around earth in degrees
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.CameraOrbital)
earthRotation += 5.0 * rotationSpeed
earthOrbitRotation += 365 / 360.0 * (5.0 * rotationSpeed) * rotationSpeed
moonRotation += 2.0 * rotationSpeed
moonOrbitRotation += 8.0 * rotationSpeed
// Draw
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.BeginMode3D(camera)
rl.PushMatrix()
rl.Scalef(sunRadius, sunRadius, sunRadius) // Scale Sun
DrawSphereBasic(rl.Gold) // Draw the Sun
rl.PopMatrix()
rl.PushMatrix()
rl.Rotatef(earthOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Earth orbit around Sun
rl.Translatef(earthOrbitRadius, 0.0, 0.0) // Translation for Earth orbit
rl.PushMatrix()
rl.Rotatef(earthRotation, 0.25, 1.0, 0.0) // Rotation for Earth itself
rl.Scalef(earthRadius, earthRadius, earthRadius) // Scale Earth
DrawSphereBasic(rl.Blue) // Draw the Earth
rl.PopMatrix()
rl.Rotatef(moonOrbitRotation, 0.0, 1.0, 0.0) // Rotation for Moon orbit around Earth
rl.Translatef(moonOrbitRadius, 0.0, 0.0) // Translation for Moon orbit
rl.Rotatef(moonRotation, 0.0, 1.0, 0.0) // Rotation for Moon itself
rl.Scalef(moonRadius, moonRadius, moonRadius) // Scale Moon
DrawSphereBasic(rl.LightGray) // Draw the Moon
rl.PopMatrix()
// Some reference elements (not affected by previous matrix transformations)
rl.DrawCircle3D(rl.Vector3{}, earthOrbitRadius, rl.NewVector3(1, 0, 0), 90.0, rl.Fade(rl.Red, 0.5))
rl.DrawGrid(20, 1.0)
rl.EndMode3D()
rl.DrawText("EARTH ORBITING AROUND THE SUN!", 400, 10, 20, rl.Maroon)
rl.DrawFPS(10, 10)
rl.EndDrawing()
}
// De-Initialization
rl.CloseWindow() // Close window and OpenGL context
}
// DrawSphereBasic draws a sphere without any matrix transformation
// NOTE: Sphere is drawn in world position ( 0, 0, 0 ) with radius 1.0f
func DrawSphereBasic(color rl.Color) {
// Make sure there is enough space in the internal render batch
// buffer to store all required vertex, batch is reset if required
rl.CheckRenderBatchLimit((rings + 2) * slices * 6)
rl.Begin(rl.Triangles)
rl.Color4ub(color.R, color.G, color.B, color.A)
for ring := int32(0); ring < (rings + 2); ring++ {
for slice := int32(0); slice < slices; slice++ {
rl.Vertex3f(getCoords(ring, slice))
rl.Vertex3f(getCoords(ring+1, slice+1))
rl.Vertex3f(getCoords(ring+1, slice))
rl.Vertex3f(getCoords(ring, slice))
rl.Vertex3f(getCoords(ring, slice+1))
rl.Vertex3f(getCoords(ring+1, slice+1))
}
}
rl.End()
}
func getCoords(ring, slice int32) (x, y, z float32) {
ringF := float64(ring)
sliceF := float64(slice)
// Calculate angels
alpha := rl.Deg2rad * (270 + (180/(float64(rings)+1))*ringF)
beta := rl.Deg2rad * (sliceF * 360 / float64(slices))
// Calculate coords
x = float32(math.Cos(alpha) * math.Sin(beta))
y = float32(math.Sin(alpha))
z = float32(math.Cos(alpha) * math.Cos(beta))
return x, y, z
}

View file

@ -5,7 +5,7 @@ import (
"path/filepath"
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -3,7 +3,7 @@ package main
import (
"math"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -0,0 +1,113 @@
/*******************************************************************************************
*
* raylib [models] example - Plane rotations (yaw, pitch, roll)
*
* Example originally created with raylib 1.8, last time updated with raylib 4.0
*
* Example contributed by Berni (@Berni8k) 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 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
package main
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
const (
screenWidth = 800
screenHeight = 450
)
func main() {
//SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI)
title := "raylib [models] example - plane rotations (yaw, pitch, roll)"
rl.InitWindow(screenWidth, screenHeight, title)
camera := rl.Camera{
Position: rl.Vector3{
Y: 50.0,
Z: -120.0,
}, // Camera position perspective
Target: rl.Vector3{}, // Camera looking at point
Up: rl.Vector3{Y: 1.0}, // Camera up vector (rotation towards target)
Fovy: 30.0, // Camera field-of-view Y
Projection: rl.CameraPerspective, // Camera type
}
model := rl.LoadModel("plane.obj") // Load model
texture := rl.LoadTexture("plane_diffuse.png") // Load model texture
rl.SetMaterialTexture(model.Materials, rl.MapDiffuse, texture) // Set map diffuse texture
var pitch, roll, yaw float32
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
// Plane pitch (x-axis) controls
pitch = controlPlane(pitch, 0.6, rl.KeyDown, rl.KeyUp)
// Plane yaw (y-axis) controls
roll = controlPlane(roll, 1.0, rl.KeyLeft, rl.KeyRight)
// Plane roll (z-axis) controls
yaw = controlPlane(yaw, 1.0, rl.KeyA, rl.KeyS)
// Transformation matrix for rotations
rotationV := rl.Vector3{
X: rl.Deg2rad * pitch,
Y: rl.Deg2rad * yaw,
Z: rl.Deg2rad * roll,
}
model.Transform = rl.MatrixRotateXYZ(rotationV)
// Draw
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
// Draw 3D model (recommended to draw 3D always before 2D)
rl.BeginMode3D(camera)
// Draw 3d model with texture
rl.DrawModel(model, rl.Vector3{Y: -8.0}, 1.0, rl.White)
rl.DrawGrid(10, 10.0)
rl.EndMode3D()
// Draw controls info
rl.DrawRectangle(30, 370, 260, 70, rl.Fade(rl.Green, 0.5))
rl.DrawRectangleLines(30, 370, 260, 70, rl.Fade(rl.DarkGreen, 0.5))
rl.DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 380, 10, rl.DarkGray)
rl.DrawText("Roll controlled with: KEY_LEFT / KEY_RIGHT", 40, 400, 10, rl.DarkGray)
rl.DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 420, 10, rl.DarkGray)
rl.DrawText("(c) WWI Plane Model created by GiaHanLam", screenWidth-240, screenHeight-20, 10, rl.DarkGray)
rl.EndDrawing()
}
// De-Initialization
rl.UnloadModel(model) // Unload model data
rl.UnloadTexture(texture) // Unload texture data
rl.CloseWindow() // Close window and OpenGL context
}
func controlPlane(ctrl, value float32, key1, key2 int32) float32 {
if rl.IsKeyDown(key1) {
ctrl -= value
} else if rl.IsKeyDown(key2) {
ctrl += value
} else {
if ctrl > 0.0 {
ctrl -= value / 2
} else if ctrl < 0.0 {
ctrl += value / 2
}
}
return ctrl
}

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 804 KiB

View file

@ -20,12 +20,12 @@
)
:COMPILE
@echo compiling for platform %FL%
@echo compiling for platform %FL% and architecture %GOARCH%
@set CGO_CFLAGS="-I%ANDROID_SYSROOT%/usr/include -I%ANDROID_SYSROOT%/usr/include/%TRIPLE% --sysroot=%ANDROID_SYSROOT% -D__ANDROID_API__=%ANDROID_API%"
@set CGO_LDFLAGS="-L%ANDROID_SYSROOT%/usr/lib/%TRIPLE%/%ANDROID_API% -L%ANDROID_TOOLCHAIN%/%TRIPLE%/lib --sysroot=%ANDROID_SYSROOT%"
@set CGO_ENABLED=1
@set GOOS=android
@set GOARCH=arm
@set GOARCH=%GOARCH%
@go build -buildmode=c-shared -ldflags="-s -w -extldflags=-Wl,-soname,lib%LIBRARY_NAME%.so" -o=android/libs/%FL%/lib%LIBRARY_NAME%.so
@EXIT /B
@ -48,21 +48,21 @@
@set GOARCH=arm
@CALL:COMPILE )
@IF %TARGET_ARCH% == "arm64-v8a" (
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
@set CC="aarch64-linux-android%ANDROID_API%-clang"
@set TRIPLE=aarch64-linux-android
@set FL=arm64-v8a
@set GOARCH=arm64
@CALL:COMPILE )
@IF %TARGET_ARCH% == "x86" (
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
@set CC="i686-linux-android%ANDROID_API%-clang"
@set TRIPLE=i686-linux-android
@set FL=x86
@set GOARCH=arm
@set GOARCH=386
@CALL:COMPILE )
@IF %TARGET_ARCH% == "x86_64" (
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
@set CC="x86_64-linux-android%ANDROID_API%-clang"
@set TRIPLE=x86_64-linux-android
@set FL=x86_64
@set GOARCH=arm64
@set GOARCH=amd64
@CALL:COMPILE )
@EXIT /B

View file

@ -4,7 +4,7 @@ import (
"os"
"runtime"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
// Game states

View file

@ -3,9 +3,13 @@ package main
import (
"fmt"
"github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
// This is the maximum amount of elements (quads) per batch
// NOTE: This value is defined in [rlgl] module and can be changed there
const maxBatchElements = 8192
// Bunny type
type Bunny struct {
Position rl.Vector2
@ -14,15 +18,14 @@ type Bunny struct {
}
func main() {
screenWidth := int32(1280)
screenHeight := int32(960)
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
rl.InitWindow(screenWidth, screenHeight, "raylib [others] example - bunnymark")
texture := rl.LoadTexture("wabbit_alpha.png")
bunnies := make([]*Bunny, 0)
bunniesCount := 0
rl.SetTargetFPS(60)
@ -33,11 +36,11 @@ func main() {
for i := 0; i < 100; i++ {
b := &Bunny{}
b.Position = rl.GetMousePosition()
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0
b.Speed.X = float32(rl.GetRandomValue(-250, 250)) / 60.0
b.Speed.Y = float32(rl.GetRandomValue(-250, 250)) / 60.0
b.Color = rl.NewColor(uint8(rl.GetRandomValue(50, 240)), uint8(rl.GetRandomValue(80, 240)), uint8(rl.GetRandomValue(100, 240)), 255)
bunnies = append(bunnies, b)
bunniesCount++
}
}
@ -46,11 +49,11 @@ func main() {
b.Position.X += b.Speed.X
b.Position.Y += b.Speed.Y
if (b.Position.X > float32(screenWidth)) || (b.Position.X < 0) {
if ((b.Position.X + float32(texture.Width/2)) > float32(screenWidth)) || ((b.Position.X + float32(texture.Width/2)) < 0) {
b.Speed.X *= -1
}
if (b.Position.Y > float32(screenHeight)) || (b.Position.Y < 0) {
if ((b.Position.Y + float32(texture.Height/2)) > float32(screenHeight)) || ((b.Position.Y + float32(texture.Height/2-40)) < 0) {
b.Speed.Y *= -1
}
}
@ -60,18 +63,20 @@ func main() {
rl.ClearBackground(rl.RayWhite)
for _, b := range bunnies {
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and
// batching buffer starts being filled again; before launching the draw call,
// updated vertex data from internal buffer is send to GPU... it seems it generates
// a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), rl.RayWhite)
// NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
// a draw call is launched and buffer starts being filled again;
// before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
// Process of sending data is costly and it could happen that GPU data has not been completely
// processed for drawing while new data is tried to be sent (updating current in-use buffers)
// it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
rl.DrawTexture(texture, int32(b.Position.X), int32(b.Position.Y), b.Color)
}
rl.DrawRectangle(0, 0, screenWidth, 40, rl.LightGray)
rl.DrawText("raylib bunnymark", 10, 10, 20, rl.DarkGray)
rl.DrawText(fmt.Sprintf("bunnies: %d", bunniesCount), 400, 10, 20, rl.Red)
rl.DrawRectangle(0, 0, screenWidth, 40, rl.Black)
rl.DrawText(fmt.Sprintf("bunnies: %d", len(bunnies)), 120, 10, 20, rl.Green)
rl.DrawText(fmt.Sprintf("batched draw calls: %d", 1+len(bunnies)/maxBatchElements), 320, 10, 20, rl.Maroon)
rl.DrawFPS(260, 10)
rl.DrawFPS(10, 10)
rl.EndDrawing()
}

View file

@ -3,7 +3,7 @@ package main
import (
"log"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -4,8 +4,6 @@ import (
"math"
"math/rand"
"github.com/gen2brain/raylib-go/raylib"
box2d "github.com/neguse/go-box2d-lite/box2dlite"
)

View file

@ -5,7 +5,7 @@ import (
"math"
"math/rand"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
"github.com/jakecoffman/cp"
)

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/gen2brain/raylib-go/physics"
rl "github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/physics"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/gen2brain/raylib-go/physics"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/physics"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,8 +1,7 @@
package main
import (
"github.com/gen2brain/raylib-go/physics"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/physics"
)
const (

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/gen2brain/raylib-go/physics"
"github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/physics"
"git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -1,8 +1,8 @@
package main
import (
"github.com/gen2brain/raylib-go/physics"
rl "github.com/gen2brain/raylib-go/raylib"
"git.terah.dev/UnrealXR/raylib-go/physics"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const (

View file

@ -4,7 +4,7 @@ import (
"fmt"
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
type LightType int32

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -4,7 +4,7 @@ import (
"fmt"
"unsafe"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
type LightType int32

View file

@ -4,7 +4,7 @@ import (
"fmt"
"math"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
const MAX_INSTANCES = 100000

View file

@ -3,7 +3,7 @@ package main
import (
"fmt"
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -1,7 +1,7 @@
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {

View file

@ -0,0 +1,296 @@
#version 330
#define MAX_LIGHTS 4
#define LIGHT_DIRECTIONAL 0
#define LIGHT_POINT 1
#define LIGHT_SPOT 2
#define PI 3.14159265358979323846
struct Light{
int enabled;
int type;
float enargy;
float cutOff ;
float outerCutOff;
float constant;
float linear ;
float quadratic ;
float shiny ;
float specularStr;
vec3 position;
vec3 direction;
vec3 lightColor;
};
// Input vertex attributes (from vertex shader)
in vec3 fragPosition;
in vec2 fragTexCoord;
in vec4 fragColor;
in vec3 fragNormal;
in vec4 shadowPos;
in mat3 TBN;
// Output fragment color
out vec4 finalColor;
// mask
uniform sampler2D mask;
uniform int frame;
// Input uniform values
uniform int numOfLights = 4;
uniform sampler2D albedoMap;
uniform sampler2D mraMap;
uniform sampler2D normalMap;
uniform sampler2D emissiveMap; // r: Hight g:emissive
// Input uniform values
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D flashlight;
uniform vec4 colDiffuse;
uniform vec2 tiling = vec2(0.5);
uniform vec2 offset ;
uniform vec2 tilingFlashlight = vec2(0.5);
uniform vec2 offsetFlashlight ;
uniform int useTexAlbedo =1;
uniform int useTexNormal = 0;
uniform int useTexMRA =1;
uniform int useTexEmissive =1;
uniform vec4 albedoColor ;
uniform vec4 emissiveColor ;
uniform float normalValue =0.5;
uniform float metallicValue =0.4;
uniform float roughnessValue =0;
uniform float aoValue =0.8;
uniform float emissivePower ;
// Input lighting values
uniform Light lights[MAX_LIGHTS];
uniform vec3 viewPos;
uniform vec3 ambientColor = vec3(1,1,1);
uniform float ambientStrength = 0.2;
uniform float ambient = 0.03;
uniform float fogDensity;
vec3 CalcDirLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic);
vec3 CalcPointLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic);
vec3 CalcSpotLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic);
// Reflectivity in range 0.0 to 1.0
// NOTE: Reflectivity is increased when surface view at larger angle
vec3 SchlickFresnel(float hDotV,vec3 refl)
{
return refl + (1.0 - refl)*pow(1.0 - hDotV, 5.0);
}
float GgxDistribution(float nDotH,float roughness)
{
float a = roughness * roughness * roughness * roughness;
float d = nDotH * nDotH * (a - 1.0) + 1.0;
d = PI * d * d;
return a / max(d,0.0000001);
}
float GeomSmith(float nDotV,float nDotL,float roughness)
{
float r = roughness + 1.0;
float k = r*r / 8.0;
float ik = 1.0 - k;
float ggx1 = nDotV/(nDotV*ik + k);
float ggx2 = nDotL/(nDotL*ik + k);
return ggx1*ggx2;
}
vec3 ComputePBR()
{
vec3 albedo = texture(albedoMap,vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y)).rgb;
albedo = vec3(albedoColor.x*albedo.x, albedoColor.y*albedo.y, albedoColor.z*albedo.z);
float metallic = clamp(metallicValue, 0.0, 1.0);
float roughness = clamp(roughnessValue, 0.0, 1.0);
float ao = clamp(aoValue, 0.0, 1.0);
if (useTexMRA == 1)
{
vec4 mra = texture(mraMap, vec2(fragTexCoord.x*tiling.x + offset.x, fragTexCoord.y*tiling.y + offset.y))*useTexMRA;
metallic = clamp(mra.r + metallicValue, 0.04, 1.0);
roughness = clamp(mra.g + roughnessValue, 0.04, 1.0);
ao = (mra.b + aoValue)*0.5;
}
vec3 N = normalize(fragNormal);
if (useTexNormal == 1)
{
N = texture(normalMap, vec2(fragTexCoord.x*tiling.x + offset.y, fragTexCoord.y*tiling.y + offset.y)).rgb;
N = normalize(N*2.0 - 1.0);
N = normalize(N*TBN);
}
vec3 V = normalize(viewPos - fragPosition);
vec3 emissive = vec3(0);
emissive = (texture(emissiveMap, vec2(fragTexCoord.x*tiling.x+offset.x, fragTexCoord.y*tiling.y+offset.y)).rgb).g * emissiveColor.rgb*emissivePower * useTexEmissive;
// return N;//vec3(metallic,metallic,metallic);
// if dia-electric use base reflectivity of 0.04 otherwise ut is a metal use albedo as base reflectivity
vec3 baseRefl = mix(vec3(0.04), albedo.rgb, metallic);
vec3 lightAccum = vec3(0.0); // Acumulate lighting lum
vec3 norm=N;
vec3 viewDir=V;
vec3 result = vec3(0.0);
for (int i = 0; i < MAX_LIGHTS; i++){
if(lights[i].enabled == 1){
if(lights[i].type == LIGHT_DIRECTIONAL){
result += CalcDirLight(lights[i],norm,viewDir,albedo,baseRefl,roughness,metallic);
}
if(lights[i].type == LIGHT_POINT){
result += CalcPointLight(lights[i],norm,viewDir,albedo,baseRefl,roughness,metallic);
}
if(lights[i].type == LIGHT_SPOT){
result += CalcSpotLight(lights[i],norm,viewDir,albedo,baseRefl,roughness,metallic);
}
}
}
vec3 ambientFinal = (ambientColor + albedo)*ambient*0.5;
return ambientFinal+result*ao + emissive;
}
void main()
{
vec3 color = ComputePBR();
// HDR tonemapping
color = pow(color, color + vec3(1.0));
// // Gamma correction
// color = pow(color, vec3(1.0/2.5));
// Fog calculation
float dist = length(viewPos - fragPosition);
// these could be parameters...
const vec4 fogColor = vec4(0.5, 0.5, 0.5, 1.0);
// Exponential fog
float fogFactor = 1.0/exp((dist*fogDensity)*(dist*fogDensity));
fogFactor = clamp(fogFactor, 0.0, 1.0);
finalColor = mix(fogColor,vec4(color,1.0), fogFactor);
}
vec3 CalcDirLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic)
{
vec3 L = normalize(-light.direction);
float diff=max(dot(normal,L),0.0);
vec3 diffuse=light.lightColor*diff*vec3(texture(texture0,fragTexCoord));
vec3 H = normalize(diffuse + L);
// Cook-Torrance BRDF distribution function
float nDotV = max(dot(normal,viewDir), 0.0000001);
float nDotL = max(dot(normal,L), 0.0000001);
float hDotV = max(dot(H,viewDir), 0.0);
float nDotH = max(dot(normal,H), 0.0);
float D = GgxDistribution(nDotH, roughness); // Larger the more micro-facets aligned to H
float G = GeomSmith(nDotV, nDotL, roughness); // Smaller the more micro-facets shadow
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
// Difuse and spec light can't be above 1.0
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
vec3 kD = vec3(1.0) - F;
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
kD *= 1.0 - metallic;
// Angle of light has impact on result
return ((kD*albedo.rgb/PI + spec)*nDotL)*light.enabled;
}
vec3 CalcPointLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic)
{
vec3 L = normalize(light.position - fragPosition);
vec3 H = normalize(viewDir + L);
float distance=length(light.position-fragPosition);
float attenuation=light.enargy/(light.constant+light.linear*distance+light.quadratic*(distance*distance));
vec3 radiance = light.lightColor.rgb*light.enargy*attenuation;
// Cook-Torrance BRDF distribution function
float nDotV = max(dot(normal,viewDir), 0.0000001);
float nDotL = max(dot(normal,L), 0.0000001);
float hDotV = max(dot(H,viewDir), 0.0);
float nDotH = max(dot(normal,H), 0.0);
float D = GgxDistribution(nDotH, roughness); // Larger the more micro-facets aligned to H
float G = GeomSmith(nDotV, nDotL, roughness); // Smaller the more micro-facets shadow
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
// Difuse and spec light can't be above 1.0
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
vec3 kD = vec3(1.0) - F;
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
kD *= 1.0 - metallic;
// Angle of light has impact on result
return ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*light.enabled ;
}
vec3 CalcSpotLight(Light light,vec3 normal,vec3 viewDir,vec3 albedo,vec3 baseRefl,float roughness,float metallic){
vec3 L = normalize(light.position - fragPosition);
float theta=dot(L,normalize(-light.direction));
float epsilon=cos(radians(light.cutOff))-cos(radians(light.outerCutOff));
float intensity=smoothstep(0.0,1.0,(theta-cos(radians(light.outerCutOff)))/epsilon);//clamp((theta-cos(radians(light.outerCutOff)))/epsilon,0.0,1.0);
intensity*= length(vec3(texture(flashlight,vec2(fragTexCoord.x*tilingFlashlight.x + offsetFlashlight.y, fragTexCoord.y*tilingFlashlight.y + offsetFlashlight.y)).rgb));
float diff=max(dot(normal,L),0.0);
vec3 H = light.lightColor*diff*vec3(texture(texture0,fragTexCoord));
float distance=length(light.position-fragPosition);
float attenuation=light.enargy/(light.constant+light.linear*distance+light.quadratic*(distance*distance));
vec3 radiance = light.lightColor.rgb*light.enargy*attenuation;
H*=intensity;
// Cook-Torrance BRDF distribution function
float nDotV = max(dot(normal,viewDir), 0.0000001);
float nDotL = max(dot(normal,L), 0.0000001);
float hDotV = max(dot(H,viewDir), 0.0);
float nDotH = max(dot(normal,H), 0.0);
float D = GgxDistribution(nDotH, roughness); // Larger the more micro-facets aligned to H
float G = GeomSmith(nDotV, nDotL, roughness); // Smaller the more micro-facets shadow
vec3 F = SchlickFresnel(hDotV, baseRefl); // Fresnel proportion of specular reflectance
vec3 spec = (D*G*F)/(4.0*nDotV*nDotL);
spec*=intensity;
// Difuse and spec light can't be above 1.0
// kD = 1.0 - kS diffuse component is equal 1.0 - spec comonent
vec3 kD = vec3(1.0) - F;
// Mult kD by the inverse of metallnes, only non-metals should have diffuse light
kD *= 1.0 - metallic;
// Angle of light has impact on result
return ((kD*albedo.rgb/PI + spec)*radiance*nDotL)*light.enabled;
}

View file

@ -0,0 +1,50 @@
#version 330
// Input vertex attributes
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
in vec3 vertexTangent;
in vec4 vertexColor;
// Input uniform values
uniform mat4 mvp;
uniform mat4 matModel;
uniform mat4 matNormal;
uniform vec3 lightPos;
uniform vec4 difColor;
// Output vertex attributes (to fragment shader)
out vec3 fragPosition;
out vec2 fragTexCoord;
out vec2 fragTexCoord2;
out vec4 fragColor;
out vec3 fragNormal;
out mat3 TBN;
const float normalOffset = 0.1;
void main()
{
// Compute binormal from vertex normal and tangent
vec3 vertexBinormal = cross(vertexNormal, vertexTangent);
// Compute fragment normal based on normal transformations
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
// Compute fragment position based on model transformations
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0f));
fragTexCoord = vertexTexCoord;
fragNormal = normalize(normalMatrix*vertexNormal);
vec3 fragTangent = normalize(normalMatrix*vertexTangent);
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal)*fragNormal);
vec3 fragBinormal = normalize(normalMatrix*vertexBinormal);
fragBinormal = cross(fragNormal, fragTangent);
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
// Calculate final vertex position
gl_Position = mvp*vec4(vertexPosition, 1.0);
}

View file

@ -0,0 +1,213 @@
package main
import (
"fmt"
"unsafe"
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
type LightType int32
const (
LightTypeDirectional LightType = iota
LightTypePoint
LightTypeSpot
)
type Light struct {
Shader rl.Shader
combineStatus bool
lightType LightType
position rl.Vector3
direction rl.Vector3
lightColor rl.Color
enabled int32
enargy float32
cutOff float32
outerCutOff float32
constant float32
linear float32
quadratic float32
shiny float32
specularStr float32
// shader locations
enabledLoc int32
typeLoc int32
posLoc int32
dirLoc int32
colorLoc int32
viewPosLoc int32
enargyLoc int32
cutOffLoc int32
outerCutOffLoc int32
constantLoc int32
linearLoc int32
quadraticLoc int32
shinyLoc int32
specularStrLoc int32
}
var MaxLights = 5
var lightCount = 0
func (lt *Light) NewLight(
lightType LightType,
position, direction rl.Vector3,
color rl.Color,
enargy float32, shader *rl.Shader) Light {
light := Light{
Shader: *shader,
}
if lightCount < MaxLights {
light.enabled = 1
light.lightType = lightType
light.position = position
light.direction = direction
light.lightColor = color
light.enargy = enargy
light.cutOff = 12.5
light.outerCutOff = 17.5
light.constant = 1.0
light.linear = 0.09
light.quadratic = 0.032
light.shiny = 32.0
light.specularStr = 0.9
light.enabledLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].enabled", lightCount))
light.typeLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].type", lightCount))
light.posLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].position", lightCount))
light.dirLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].direction", lightCount))
light.colorLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].lightColor", lightCount))
light.enargyLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].enargy", lightCount))
light.cutOffLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].cutOff", lightCount))
light.outerCutOffLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].outerCutOff", lightCount))
light.constantLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].constant", lightCount))
light.linearLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].linear", lightCount))
light.quadraticLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].quadratic", lightCount))
light.shinyLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].shiny", lightCount))
light.specularStrLoc = rl.GetShaderLocation(*shader, fmt.Sprintf("lights[%d].specularStr", lightCount))
light.UpdateValues()
lightCount++
}
return light
}
func (lt *Light) UpdateValues() {
// Send to shader light enabled state and type
rl.SetShaderValue(lt.Shader, lt.enabledLoc, unsafe.Slice((*float32)(unsafe.Pointer(&lt.enabled)), 4), rl.ShaderUniformInt)
rl.SetShaderValue(lt.Shader, lt.typeLoc, unsafe.Slice((*float32)(unsafe.Pointer(&lt.lightType)), 4), rl.ShaderUniformInt)
// Send to shader light position values
rl.SetShaderValue(lt.Shader, lt.posLoc, []float32{lt.position.X, lt.position.Y, lt.position.Z}, rl.ShaderUniformVec3)
// Send to shader light direction values
rl.SetShaderValue(lt.Shader, lt.dirLoc, []float32{lt.direction.X, lt.direction.Y, lt.direction.Z}, rl.ShaderUniformVec3)
// Send to shader light color values
rl.SetShaderValue(lt.Shader, lt.colorLoc,
[]float32{float32(lt.lightColor.R) / 255, float32(lt.lightColor.G) / 255, float32(lt.lightColor.B) / 255},
rl.ShaderUniformVec3)
// Send to shader light enargy values
rl.SetShaderValue(lt.Shader, lt.enargyLoc, []float32{lt.enargy}, rl.ShaderUniformFloat)
// Send to shader light spot values
rl.SetShaderValue(lt.Shader, lt.cutOffLoc, []float32{lt.cutOff}, rl.ShaderUniformFloat)
rl.SetShaderValue(lt.Shader, lt.outerCutOffLoc, []float32{lt.outerCutOff}, rl.ShaderUniformFloat)
// Send to shader light pointLight values
rl.SetShaderValue(lt.Shader, lt.constantLoc, []float32{lt.constant}, rl.ShaderUniformFloat)
rl.SetShaderValue(lt.Shader, lt.linearLoc, []float32{lt.linear}, rl.ShaderUniformFloat)
rl.SetShaderValue(lt.Shader, lt.quadraticLoc, []float32{lt.quadratic}, rl.ShaderUniformFloat)
// Send to shader light shiness values
rl.SetShaderValue(lt.Shader, lt.shinyLoc, []float32{lt.shiny}, rl.ShaderUniformFloat)
rl.SetShaderValue(lt.Shader, lt.specularStrLoc, []float32{lt.specularStr}, rl.ShaderUniformFloat)
}
// if you want more 5 light in the light.fs change #define MAX_LIGHTS "your number"
func (lt *Light) SetMaxLight(max int) {
MaxLights = max
}
func (lt *Light) SetConfigSpotLight(light *Light, cutOff, outerCutOff float32) {
light.cutOff = cutOff
light.outerCutOff = outerCutOff
light.UpdateValues()
}
func (lt *Light) SetConfigPointLight(light *Light, constant, linear, quadratic float32) {
light.constant = constant
light.linear = linear
light.quadratic = quadratic
light.UpdateValues()
}
func (lt *Light) SetConfigShiness(light *Light, shiny, specularStr float32) {
light.shiny = shiny
light.specularStr = specularStr
light.UpdateValues()
}
func (lt *Light) SetMaterialTexture(materials []*rl.Material, texture []*rl.Texture2D) {
for index, material := range materials {
rl.SetMaterialTexture(material, rl.MapDiffuse, *texture[index])
}
}
func (lt *Light) SetFlashlightTexture(materials []*rl.Material, texure *rl.Texture2D) {
lt.Shader.UpdateLocation(rl.ShaderLocMapOcclusion, rl.GetShaderLocation(lt.Shader, "flashlight"))
for _, material := range materials {
rl.SetMaterialTexture(material, rl.MapOcclusion, *texure)
}
}
func (lt *Light) Init(ambientStrength float32, ambientColor rl.Vector3) {
if !lt.combineStatus {
lt.configShader()
}
lt.viewPosLoc = rl.GetShaderLocation(lt.Shader, "viewPos")
rl.SetShaderValue(lt.Shader, rl.GetShaderLocation(lt.Shader, "ambientColor"), []float32{ambientColor.X, ambientColor.Y, ambientColor.Z}, rl.ShaderUniformVec3)
rl.SetShaderValue(lt.Shader, rl.GetShaderLocation(lt.Shader, "ambientStrength"), []float32{ambientStrength}, rl.ShaderUniformFloat)
}
func (lt *Light) DisableLight(light *Light) {
light.enabled *= -1
light.UpdateValues()
}
func (lt *Light) EnableLight(light *Light) {
light.enabled = 1
light.UpdateValues()
}
func (lt *Light) DrawSpherelight(light *Light) {
if light.enabled == 1 {
rl.DrawSphereEx(light.position, 0.2, 8, 8, light.lightColor)
} else {
rl.DrawSphereWires(light.position, 0.2, 8, 8, rl.Fade(light.lightColor, 0.3))
}
}
func (lt *Light) UpdateReflect(cameraPos rl.Vector3) {
rl.SetShaderValue(lt.Shader, lt.viewPosLoc, []float32{cameraPos.X, cameraPos.Y, cameraPos.Z}, rl.ShaderUniformVec3)
}
func (lt *Light) configShader() {
lt.Shader = rl.LoadShader("pbr.vs", "./pbr.fs")
}
// exce before init or set manually
func (lt *Light) SetCombineShader(CombineShader *rl.Shader) {
lt.combineStatus = true
lt.Shader = *CombineShader
}
func (lt *Light) Unload() {
rl.UnloadShader(lt.Shader)
}

View file

@ -0,0 +1,83 @@
package main
import (
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
)
func main() {
screenWidth := int32(900)
screenHeight := int32(500)
rl.SetConfigFlags(rl.FlagMsaa4xHint) //ENABLE 4X MSAA IF AVAILABLE
rl.InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic pbr")
car := rl.LoadModel("./models/old_car_new.glb")
plane := rl.LoadModel("./models/plane.glb")
cam := rl.Camera3D{}
cam.Fovy = 45
cam.Position = rl.Vector3{2, 2, 8}
cam.Projection = rl.CameraPerspective
cam.Up = rl.Vector3{0, 1, 0}
shader := rl.LoadShader("./glsl330/pbr.vs", "./glsl330/pbr.fs")
l := Light{}
l.SetCombineShader(&shader)
l.Init(0.0, rl.Vector3{1, 1, 1})
l1 := l.NewLight(LightTypePoint, rl.Vector3{-1, 1, -2}, rl.Vector3{}, rl.Yellow, 4, &l.Shader)
l2 := l.NewLight(LightTypePoint, rl.Vector3{2, 1, 1}, rl.Vector3{}, rl.Green, 3.3, &l.Shader)
l3 := l.NewLight(LightTypePoint, rl.Vector3{-2, 1, 1}, rl.Vector3{}, rl.Red, 8.3, &l.Shader)
l4 := l.NewLight(LightTypePoint, rl.Vector3{1, 1, -2}, rl.Vector3{}, rl.Blue, 2, &l.Shader)
p := PhysicRender{}
p.SetCombineShader(&shader)
p.Init()
p.UseTexAlbedo()
p.UseTexMRA()
p.UseTexNormal()
p.UseTexEmissive()
car.GetMaterials()[0].Shader = shader
p.AlbedoColorModel(&car, rl.White)
p.MetallicValue(0.0)
p.RoughnessValue(0)
p.EmissivePower(0.0)
p.AoValue(0.0)
p.NormalValue(0.2)
p.EmissiveColor(rl.NewColor(255, 162, 0, 255))
p.TextureMapAlbedo(&car.GetMaterials()[0], rl.LoadTexture("models/old_car_d.png"))
p.TextureMapMetalness(&car.GetMaterials()[0], rl.LoadTexture("models/old_car_mra.png"))
p.TextureMapNormal(&car.GetMaterials()[0], rl.LoadTexture("models/old_car_n.png"))
rl.SetMaterialTexture(&car.GetMaterials()[0], rl.MapEmission, rl.LoadTexture("models/old_car_e.png"))
p.SetTiling(rl.NewVector2(1, 1))
plane.GetMaterials()[0].Shader = shader
p.TextureMapAlbedo(&plane.GetMaterials()[0], rl.LoadTexture("./models/road_a.png"))
p.TextureMapNormal(&plane.GetMaterials()[0], rl.LoadTexture("./models/road_n.png"))
p.TextureMapMetalness(&plane.GetMaterials()[0], rl.LoadTexture("./models/road_mra.png"))
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.UpdateCamera(&cam, rl.CameraOrbital)
p.UpadteByCamera(cam.Position)
rl.BeginDrawing()
rl.DrawFPS(10, 20)
rl.ClearBackground(rl.Gray)
rl.BeginMode3D(cam)
rl.DrawModel(car, rl.Vector3{0, 0.01, 0}, 0.25, rl.RayWhite)
rl.DrawModel(plane, rl.Vector3{0, 0, 0}, 5, rl.RayWhite)
l.DrawSpherelight(&l1)
l.DrawSpherelight(&l2)
l.DrawSpherelight(&l3)
l.DrawSpherelight(&l4)
rl.EndMode3D()
rl.EndDrawing()
}
rl.CloseWindow()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Some files were not shown because too many files have changed in this diff Show more