Compare commits
No commits in common. "master" and "raylib/v0.55.0" have entirely different histories.
master
...
raylib/v0.
275 changed files with 23975 additions and 29194 deletions
143
.github/workflows/build.yml
vendored
Normal file
143
.github/workflows/build.yml
vendored
Normal file
|
@ -0,0 +1,143 @@
|
|||
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
|
37
README.md
37
README.md
|
@ -1,14 +1,12 @@
|
|||

|
||||

|
||||
## raylib-go
|
||||
[](https://git.terah.dev/UnrealXR/raylib-go/actions)
|
||||
[](https://godoc.org/git.terah.dev/UnrealXR/raylib-go/raylib)
|
||||
[](https://goreportcard.com/report/git.terah.dev/UnrealXR/raylib-go/raylib)
|
||||
[](https://git.terah.dev/UnrealXR/raylib-go/src/branch/master/examples)
|
||||
[](https://github.com/gen2brain/raylib-go/actions)
|
||||
[](https://godoc.org/github.com/gen2brain/raylib-go/raylib)
|
||||
[](https://goreportcard.com/report/github.com/gen2brain/raylib-go/raylib)
|
||||
[](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.
|
||||
|
||||
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).
|
||||
|
@ -25,7 +23,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 (if you have `brew` installed, you already have this).
|
||||
On macOS you need Xcode or Command Line Tools for Xcode.
|
||||
|
||||
##### Windows
|
||||
|
||||
|
@ -41,28 +39,22 @@ 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://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.
|
||||
|
||||
[Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/others/android/example).
|
||||
|
||||
### Installation
|
||||
|
||||
go get -v -u git.terah.dev/UnrealXR/raylib-go/raylib
|
||||
go get -v -u github.com/gen2brain/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
|
||||
|
@ -71,18 +63,17 @@ For web bindings, refer to [Raylib-Go-Wasm](https://github.com/BrownNPC/Raylib-G
|
|||
* `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/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). 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 "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
import rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
func main() {
|
||||
rl.InitWindow(800, 450, "raylib [core] example - basic window")
|
||||
|
@ -101,7 +92,7 @@ func main() {
|
|||
}
|
||||
```
|
||||
|
||||
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)
|
||||
|
||||
|
@ -131,4 +122,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://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).
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1 KiB |
|
@ -1,4 +1,4 @@
|
|||
## 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.
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module git.terah.dev/UnrealXR/raylib-go/easings
|
||||
module github.com/gen2brain/raylib-go/easings
|
||||
|
||||
go 1.21
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const maxCircles = 64
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - music playing (streaming)")
|
||||
rl.InitAudioDevice()
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"math"
|
||||
"time"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
********************************************************************************************/
|
||||
package main
|
||||
|
||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
import rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
const (
|
||||
screenWidth = 800
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [core] example - 2d camera mouse zoom
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
import rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
const (
|
||||
screenWidth = 800
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"os"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const colorCount = 23
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
import "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
import "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
func main() {
|
||||
rl.SetConfigFlags(rl.FlagVsyncHint)
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const screenW = int32(1280)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rl.InitWindow(800, 450, "raylib [core] example - color selection (collision detection)")
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
/*******************************************************************************************
|
||||
|
|
|
@ -31,7 +31,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
maxGestureStrings int = 20
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const screenW = int32(1280)
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -15,7 +15,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -16,7 +16,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"image/color"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
import rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
import rl "github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
const (
|
||||
screenWidth = 850
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,9 +3,9 @@ package main
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"git.terah.dev/UnrealXR/raylib-go/easings"
|
||||
"git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/easings"
|
||||
"github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -18,7 +18,7 @@ package main
|
|||
import (
|
||||
"math"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"math/rand"
|
||||
"time"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -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
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
snakeLength = 256
|
||||
squareSize = 31
|
||||
|
|
|
@ -2,19 +2,19 @@ module examples
|
|||
|
||||
go 1.21
|
||||
|
||||
replace git.terah.dev/UnrealXR/raylib-go/raylib => ../raylib
|
||||
replace github.com/gen2brain/raylib-go/raylib => ../raylib
|
||||
|
||||
replace git.terah.dev/UnrealXR/raylib-go/raygui => ../raygui
|
||||
replace github.com/gen2brain/raylib-go/raygui => ../raygui
|
||||
|
||||
replace git.terah.dev/UnrealXR/raylib-go/easings => ../easings
|
||||
replace github.com/gen2brain/raylib-go/easings => ../easings
|
||||
|
||||
replace git.terah.dev/UnrealXR/raylib-go/physics => ../physics
|
||||
replace github.com/gen2brain/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/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
|
||||
github.com/jakecoffman/cp v1.2.1
|
||||
github.com/neguse/go-box2d-lite v0.0.0-20170921151050-5d8ed9b7272b
|
||||
)
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
gui "github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
gui "github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
/*******************************************************************************************
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
gui "github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
/*******************************************************************************************
|
||||
|
|
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
gui "git.terah.dev/UnrealXR/raylib-go/raygui"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
gui "github.com/gen2brain/raylib-go/raygui"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
/*******************************************************************************************
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"unsafe"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -74,8 +76,9 @@ 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++ {
|
||||
pose := anims[0].GetFramePose(animFrameCount, int(i))
|
||||
rl.DrawCube(pose.Translation, 0.2, 0.2, 0.2, rl.Red)
|
||||
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)
|
||||
}
|
||||
rl.DrawGrid(10, 1)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
********************************************************************************************/package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
Binary file not shown.
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)
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
*
|
||||
* 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)
|
||||
* 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)
|
||||
*
|
||||
* 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 "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -62,7 +62,7 @@ func main() {
|
|||
|
||||
rl.EndMode3D()
|
||||
|
||||
rl.DrawText(fmt.Sprintf("current animation: %s [%d]", animPlaying.GetName(), animIndex), 10, 10, 10, rl.Black)
|
||||
rl.DrawText("current animation number: "+fmt.Sprint(animIndex), 10, 10, 10, rl.Black)
|
||||
rl.DrawText("UP/DOWN ARROW KEYS CHANGE ANIMATION", 10, 30, 10, rl.Black)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
//"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -114,8 +116,9 @@ func main() {
|
|||
if drawSkeleton {
|
||||
modelBones := model.GetBones()
|
||||
modelPoses := model.GetBindPose()
|
||||
anim := anims[animID]
|
||||
animBones := anim.GetBones()
|
||||
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)
|
||||
for bone := 0; bone < int(model.BoneCount)-1; bone++ {
|
||||
if !animPlaying || animsCount == 0 {
|
||||
// Display the bind-pose skeleton
|
||||
|
@ -125,11 +128,9 @@ func main() {
|
|||
}
|
||||
} else {
|
||||
// // Display the frame-pose skeleton
|
||||
pos := anim.GetFramePose(animFrameCounter, bone).Translation
|
||||
rl.DrawCube(pos, 0.05, 0.05, 0.05, rl.Red)
|
||||
rl.DrawCube(transforms[bone].Translation, 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.DrawLine3D(transforms[bone].Translation, transforms[animBones[bone].Parent].Translation, rl.Red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"unsafe"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
"math"
|
||||
"unsafe"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -122,7 +122,7 @@ func main() {
|
|||
cursorColor := rl.White
|
||||
|
||||
// Get ray and test against objects
|
||||
// See issue : https://git.terah.dev/UnrealXR/raylib-go/issues/457
|
||||
// See issue : https://github.com/gen2brain/raylib-go/issues/457
|
||||
//ray = rl.GetScreenToWorldRay(rl.GetMousePosition(), camera)
|
||||
ray = rl.GetMouseRay(rl.GetMousePosition(), camera)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"slices"
|
||||
"unsafe"
|
||||
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
var supportedFileTypes = []string{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,155 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* 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
|
||||
}
|
|
@ -5,7 +5,7 @@ import (
|
|||
"path/filepath"
|
||||
"unsafe"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"math"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,113 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* 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.
Before Width: | Height: | Size: 804 KiB |
|
@ -20,12 +20,12 @@
|
|||
)
|
||||
|
||||
:COMPILE
|
||||
@echo compiling for platform %FL% and architecture %GOARCH%
|
||||
@echo compiling for platform %FL%
|
||||
@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=%GOARCH%
|
||||
@set GOARCH=arm
|
||||
@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="aarch64-linux-android%ANDROID_API%-clang"
|
||||
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
|
||||
@set TRIPLE=aarch64-linux-android
|
||||
@set FL=arm64-v8a
|
||||
@set GOARCH=arm64
|
||||
@CALL:COMPILE )
|
||||
@IF %TARGET_ARCH% == "x86" (
|
||||
@set CC="i686-linux-android%ANDROID_API%-clang"
|
||||
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
|
||||
@set TRIPLE=i686-linux-android
|
||||
@set FL=x86
|
||||
@set GOARCH=386
|
||||
@set GOARCH=arm
|
||||
@CALL:COMPILE )
|
||||
@IF %TARGET_ARCH% == "x86_64" (
|
||||
@set CC="x86_64-linux-android%ANDROID_API%-clang"
|
||||
@set CC="armv7a-linux-androideabi%ANDROID_API%-clang"
|
||||
@set TRIPLE=x86_64-linux-android
|
||||
@set FL=x86_64
|
||||
@set GOARCH=amd64
|
||||
@set GOARCH=arm64
|
||||
@CALL:COMPILE )
|
||||
@EXIT /B
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"os"
|
||||
"runtime"
|
||||
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// Game states
|
||||
|
|
|
@ -3,13 +3,9 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/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
|
||||
|
@ -18,14 +14,15 @@ type Bunny struct {
|
|||
}
|
||||
|
||||
func main() {
|
||||
screenWidth := int32(800)
|
||||
screenHeight := int32(450)
|
||||
screenWidth := int32(1280)
|
||||
screenHeight := int32(960)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [others] example - bunnymark")
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [core] example - Bunnymark")
|
||||
|
||||
texture := rl.LoadTexture("wabbit_alpha.png")
|
||||
|
||||
bunnies := make([]*Bunny, 0)
|
||||
bunniesCount := 0
|
||||
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
|
@ -36,11 +33,11 @@ func main() {
|
|||
for i := 0; i < 100; i++ {
|
||||
b := &Bunny{}
|
||||
b.Position = rl.GetMousePosition()
|
||||
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)
|
||||
b.Speed.X = float32(rl.GetRandomValue(250, 500)) / 60.0
|
||||
b.Speed.Y = float32(rl.GetRandomValue(250, 500)-500) / 60.0
|
||||
|
||||
bunnies = append(bunnies, b)
|
||||
bunniesCount++
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,11 +46,11 @@ func main() {
|
|||
b.Position.X += b.Speed.X
|
||||
b.Position.Y += b.Speed.Y
|
||||
|
||||
if ((b.Position.X + float32(texture.Width/2)) > float32(screenWidth)) || ((b.Position.X + float32(texture.Width/2)) < 0) {
|
||||
if (b.Position.X > float32(screenWidth)) || (b.Position.X < 0) {
|
||||
b.Speed.X *= -1
|
||||
}
|
||||
|
||||
if ((b.Position.Y + float32(texture.Height/2)) > float32(screenHeight)) || ((b.Position.Y + float32(texture.Height/2-40)) < 0) {
|
||||
if (b.Position.Y > float32(screenHeight)) || (b.Position.Y < 0) {
|
||||
b.Speed.Y *= -1
|
||||
}
|
||||
}
|
||||
|
@ -63,20 +60,18 @@ func main() {
|
|||
rl.ClearBackground(rl.RayWhite)
|
||||
|
||||
for _, b := range bunnies {
|
||||
// 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)
|
||||
// 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)
|
||||
}
|
||||
|
||||
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.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.DrawFPS(10, 10)
|
||||
rl.DrawFPS(260, 10)
|
||||
|
||||
rl.EndDrawing()
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"log"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"math"
|
||||
"math/rand"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
|
||||
box2d "github.com/neguse/go-box2d-lite/box2dlite"
|
||||
)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"math"
|
||||
"math/rand"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
"github.com/jakecoffman/cp"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/physics"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/physics"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/physics"
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/physics"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/physics"
|
||||
"github.com/gen2brain/raylib-go/physics"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/physics"
|
||||
"git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/physics"
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.terah.dev/UnrealXR/raylib-go/physics"
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
"github.com/gen2brain/raylib-go/physics"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type LightType int32
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
type LightType int32
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const MAX_INSTANCES = 100000
|
||||
|
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
rl "git.terah.dev/UnrealXR/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,296 +0,0 @@
|
|||
#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;
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -1,213 +0,0 @@
|
|||
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(<.enabled)), 4), rl.ShaderUniformInt)
|
||||
rl.SetShaderValue(lt.Shader, lt.typeLoc, unsafe.Slice((*float32)(unsafe.Pointer(<.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)
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
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.
Before Width: | Height: | Size: 1.6 MiB |
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue