Merge branch 'master' of github.com:raysan5/raylib
6
.github/workflows/build_android.yml
vendored
|
|
@ -84,8 +84,10 @@ jobs:
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.RELEASE_NAME }}.tar.gz
|
name: ${{ env.RELEASE_NAME }}
|
||||||
path: ./build/${{ env.RELEASE_NAME }}.tar.gz
|
path: |
|
||||||
|
./build/${{ env.RELEASE_NAME }}
|
||||||
|
!./build/${{ env.RELEASE_NAME }}.tar.gz
|
||||||
|
|
||||||
- name: Upload Artifact to Release
|
- name: Upload Artifact to Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
|
|
||||||
6
.github/workflows/build_linux.yml
vendored
|
|
@ -114,8 +114,10 @@ jobs:
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.RELEASE_NAME }}.tar.gz
|
name: ${{ env.RELEASE_NAME }}
|
||||||
path: ./build/${{ env.RELEASE_NAME }}.tar.gz
|
path: |
|
||||||
|
./build/${{ env.RELEASE_NAME }}
|
||||||
|
!./build/${{ env.RELEASE_NAME }}.tar.gz
|
||||||
|
|
||||||
- name: Upload Artifact to Release
|
- name: Upload Artifact to Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
|
|
||||||
6
.github/workflows/build_macos.yml
vendored
|
|
@ -101,8 +101,10 @@ jobs:
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.RELEASE_NAME }}.tar.gz
|
name: ${{ env.RELEASE_NAME }}
|
||||||
path: ./build/${{ env.RELEASE_NAME }}.tar.gz
|
path: |
|
||||||
|
./build/${{ env.RELEASE_NAME }}
|
||||||
|
!./build/${{ env.RELEASE_NAME }}.tar.gz
|
||||||
|
|
||||||
- name: Upload Artifact to Release
|
- name: Upload Artifact to Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
|
|
||||||
6
.github/workflows/build_webassembly.yml
vendored
|
|
@ -71,8 +71,10 @@ jobs:
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.RELEASE_NAME }}.zip
|
name: ${{ env.RELEASE_NAME }}
|
||||||
path: ./build/${{ env.RELEASE_NAME }}.zip
|
path: |
|
||||||
|
./build/${{ env.RELEASE_NAME }}
|
||||||
|
!./build/${{ env.RELEASE_NAME }}.zip
|
||||||
|
|
||||||
- name: Upload Artifact to Release
|
- name: Upload Artifact to Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
|
|
||||||
6
.github/workflows/build_windows.yml
vendored
|
|
@ -142,8 +142,10 @@ jobs:
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: ${{ env.RELEASE_NAME }}.zip
|
name: ${{ env.RELEASE_NAME }}
|
||||||
path: ./build/${{ env.RELEASE_NAME }}.zip
|
path: |
|
||||||
|
./build/${{ env.RELEASE_NAME }}
|
||||||
|
!./build/${{ env.RELEASE_NAME }}.zip
|
||||||
|
|
||||||
- name: Upload Artifact to Release
|
- name: Upload Artifact to Release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [claw-raylib](https://github.com/bohonghuang/claw-raylib) | **auto** | [Common Lisp](https://common-lisp.net) | Apache-2.0 |
|
| [claw-raylib](https://github.com/bohonghuang/claw-raylib) | **auto** | [Common Lisp](https://common-lisp.net) | Apache-2.0 |
|
||||||
| [raylib](https://github.com/fosskers/raylib) | 5.5 | [Common Lisp](https://common-lisp.net) | MPL-2.0 |
|
| [raylib](https://github.com/fosskers/raylib) | 5.5 | [Common Lisp](https://common-lisp.net) | MPL-2.0 |
|
||||||
| [chez-raylib](https://github.com/Yunoinsky/chez-raylib) | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme) | GPLv3 |
|
| [chez-raylib](https://github.com/Yunoinsky/chez-raylib) | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme) | GPLv3 |
|
||||||
|
| [chicken-raylib](https://github.com/meowstr/chicken-raylib) | 5.5 | [CHICKEN Scheme](https://wiki.call-cc.org) | MIT |
|
||||||
| [CLIPSraylib](https://github.com/mrryanjohnston/CLIPSraylib) | **auto** | [CLIPS](https://www.clipsrules.net/) | MIT |
|
| [CLIPSraylib](https://github.com/mrryanjohnston/CLIPSraylib) | **auto** | [CLIPS](https://www.clipsrules.net/) | MIT |
|
||||||
| [raylib-cr](https://github.com/sol-vin/raylib-cr) | 4.6-dev (5e1a81) | [Crystal](https://crystal-lang.org) | Apache-2.0 |
|
| [raylib-cr](https://github.com/sol-vin/raylib-cr) | 4.6-dev (5e1a81) | [Crystal](https://crystal-lang.org) | Apache-2.0 |
|
||||||
| [ray-cyber](https://github.com/fubark/ray-cyber) | **5.0** | [Cyber](https://cyberscript.dev) | MIT |
|
| [ray-cyber](https://github.com/fubark/ray-cyber) | **5.0** | [Cyber](https://cyberscript.dev) | MIT |
|
||||||
|
|
@ -28,6 +29,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [bindbc-raylib3](https://github.com/o3o/bindbc-raylib3) | **5.0** | [D](https://dlang.org) | BSL-1.0 |
|
| [bindbc-raylib3](https://github.com/o3o/bindbc-raylib3) | **5.0** | [D](https://dlang.org) | BSL-1.0 |
|
||||||
| [dray](https://github.com/redthing1/dray) | **5.0** | [D](https://dlang.org) | Apache-2.0 |
|
| [dray](https://github.com/redthing1/dray) | **5.0** | [D](https://dlang.org) | Apache-2.0 |
|
||||||
| [raylib-d](https://github.com/schveiguy/raylib-d) | **5.5** | [D](https://dlang.org) | Zlib |
|
| [raylib-d](https://github.com/schveiguy/raylib-d) | **5.5** | [D](https://dlang.org) | Zlib |
|
||||||
|
| [DenoRaylib550](https://github.com/JJLDonley/DenoRaylib550) | **5.5** | [Deno](https://deno.land) | MIT |
|
||||||
| [rayex](https://github.com/shiryel/rayex) | 3.7 | [elixir](https://elixir-lang.org) | Apache-2.0 |
|
| [rayex](https://github.com/shiryel/rayex) | 3.7 | [elixir](https://elixir-lang.org) | Apache-2.0 |
|
||||||
| [raylib-elle](https://github.com/acquitelol/elle/blob/rewrite/std/raylib.le) | **5.5** | [Elle](https://github.com/acquitelol/elle) | GPL-3.0 |
|
| [raylib-elle](https://github.com/acquitelol/elle/blob/rewrite/std/raylib.le) | **5.5** | [Elle](https://github.com/acquitelol/elle) | GPL-3.0 |
|
||||||
| [raylib-factor](https://github.com/factor/factor/blob/master/extra/raylib/raylib.factor) | 4.5 | [Factor](https://factorcode.org) | BSD |
|
| [raylib-factor](https://github.com/factor/factor/blob/master/extra/raylib/raylib.factor) | 4.5 | [Factor](https://factorcode.org) | BSD |
|
||||||
|
|
@ -61,7 +63,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [raylib_odin_bindings](https://github.com/Deathbat2190/raylib_odin_bindings) | 4.0-dev | [Odin](https://odin-lang.org) | MIT |
|
| [raylib_odin_bindings](https://github.com/Deathbat2190/raylib_odin_bindings) | 4.0-dev | [Odin](https://odin-lang.org) | MIT |
|
||||||
| [raylib-ocaml](https://github.com/tjammer/raylib-ocaml) | **5.0** | [OCaml](https://ocaml.org) | MIT |
|
| [raylib-ocaml](https://github.com/tjammer/raylib-ocaml) | **5.0** | [OCaml](https://ocaml.org) | MIT |
|
||||||
| [TurboRaylib](https://github.com/turborium/TurboRaylib) | 4.5 | [Object Pascal](https://en.wikipedia.org/wiki/Object_Pascal) | MIT |
|
| [TurboRaylib](https://github.com/turborium/TurboRaylib) | 4.5 | [Object Pascal](https://en.wikipedia.org/wiki/Object_Pascal) | MIT |
|
||||||
| [Ray4Laz](https://github.com/GuvaCode/Ray4Laz) | **5.5** | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib |
|
| [Ray4Laz](https://github.com/GuvaCode/Ray4Laz) | **5.5** | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal)/[Delphi](https://en.wikipedia.org/wiki/Delphi_(software)) | Zlib |
|
||||||
| [Raylib.4.0.Pascal](https://github.com/sysrpl/Raylib.4.0.Pascal) | 4.0 | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib |
|
| [Raylib.4.0.Pascal](https://github.com/sysrpl/Raylib.4.0.Pascal) | 4.0 | [Free Pascal](https://en.wikipedia.org/wiki/Free_Pascal) | Zlib |
|
||||||
| [pyraylib](https://github.com/Ho011/pyraylib) | 3.7 | [Python](https://www.python.org) | Zlib |
|
| [pyraylib](https://github.com/Ho011/pyraylib) | 3.7 | [Python](https://www.python.org) | Zlib |
|
||||||
| [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi) | **5.5** | [Python](https://www.python.org) | EPL-2.0 |
|
| [raylib-python-cffi](https://github.com/electronstudio/raylib-python-cffi) | **5.5** | [Python](https://www.python.org) | EPL-2.0 |
|
||||||
|
|
@ -76,7 +78,6 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [raylib-rs](https://github.com/raylib-rs/raylib-rs) | **5.5** | [Rust](https://www.rust-lang.org) | Zlib |
|
| [raylib-rs](https://github.com/raylib-rs/raylib-rs) | **5.5** | [Rust](https://www.rust-lang.org) | Zlib |
|
||||||
| [raylib-ruby](https://github.com/wilsonsilva/raylib-ruby) | 4.5 | [Ruby](https://www.ruby-lang.org) | Zlib |
|
| [raylib-ruby](https://github.com/wilsonsilva/raylib-ruby) | 4.5 | [Ruby](https://www.ruby-lang.org) | Zlib |
|
||||||
| [Relib](https://github.com/RedCubeDev-ByteSpace/Relib) | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | **???** |
|
| [Relib](https://github.com/RedCubeDev-ByteSpace/Relib) | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | **???** |
|
||||||
| [ringraylib5](https://github.com/ring-lang/ring/tree/master/extensions/ringraylib5) | **5.0** | [Ring](https://ring-lang.github.io/) | **???** |
|
|
||||||
| [racket-raylib](https://github.com/eutro/racket-raylib) | **5.5** | [Racket](https://racket-lang.org) | MIT/Apache-2.0 |
|
| [racket-raylib](https://github.com/eutro/racket-raylib) | **5.5** | [Racket](https://racket-lang.org) | MIT/Apache-2.0 |
|
||||||
| [raylib-swift](https://github.com/STREGAsGate/Raylib) | 4.0 | [Swift](https://swift.org) | MIT |
|
| [raylib-swift](https://github.com/STREGAsGate/Raylib) | 4.0 | [Swift](https://swift.org) | MIT |
|
||||||
| [raylib-scopes](https://github.com/salotz/raylib-scopes) | auto | [Scopes](http://scopes.rocks) | MIT |
|
| [raylib-scopes](https://github.com/salotz/raylib-scopes) | auto | [Scopes](http://scopes.rocks) | MIT |
|
||||||
|
|
@ -85,6 +86,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [raylib-v](https://github.com/vlang/raylib) | 5.5 | [V](https://vlang.io) | MIT/Unlicense |
|
| [raylib-v](https://github.com/vlang/raylib) | 5.5 | [V](https://vlang.io) | MIT/Unlicense |
|
||||||
| [raylib.v](https://github.com/irishgreencitrus/raylib.v) | 4.2 | [V](https://vlang.io) | Zlib |
|
| [raylib.v](https://github.com/irishgreencitrus/raylib.v) | 4.2 | [V](https://vlang.io) | Zlib |
|
||||||
| [raylib-vapi](https://github.com/lxmcf/raylib-vapi) | **5.0** | [Vala](https://vala.dev) | Zlib |
|
| [raylib-vapi](https://github.com/lxmcf/raylib-vapi) | **5.0** | [Vala](https://vala.dev) | Zlib |
|
||||||
|
| [raylib-wave](https://github.com/wavefnd/raylib-wave) | **auto** |[Wave](http://wave-lang.dev) | Zlib |
|
||||||
| [raylib-wren](https://github.com/TSnake41/raylib-wren) | 4.5 | [Wren](http://wren.io) | ISC |
|
| [raylib-wren](https://github.com/TSnake41/raylib-wren) | 4.5 | [Wren](http://wren.io) | ISC |
|
||||||
| [raylib-zig](https://github.com/raylib-zig/raylib-zig) | **5.6-dev** | [Zig](https://ziglang.org) | MIT |
|
| [raylib-zig](https://github.com/raylib-zig/raylib-zig) | **5.6-dev** | [Zig](https://ziglang.org) | MIT |
|
||||||
| [raylib.zig](https://github.com/ryupold/raylib.zig) | **5.1-dev** | [Zig](https://ziglang.org) | MIT |
|
| [raylib.zig](https://github.com/ryupold/raylib.zig) | **5.1-dev** | [Zig](https://ziglang.org) | MIT |
|
||||||
|
|
@ -93,6 +95,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [raylib-sunder](https://github.com/ashn-dot-dev/raylib-sunder) | **auto** | [Sunder](https://github.com/ashn-dot-dev/sunder) | 0BSD |
|
| [raylib-sunder](https://github.com/ashn-dot-dev/raylib-sunder) | **auto** | [Sunder](https://github.com/ashn-dot-dev/sunder) | 0BSD |
|
||||||
| [raylib-bqn](https://github.com/Brian-ED/raylib-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
|
| [raylib-bqn](https://github.com/Brian-ED/raylib-bqn) | **5.0** | [BQN](https://mlochbaum.github.io/BQN) | MIT |
|
||||||
| [rayjs](https://github.com/mode777/rayjs) | 4.6-dev | [QuickJS](https://bellard.org/quickjs) | MIT |
|
| [rayjs](https://github.com/mode777/rayjs) | 4.6-dev | [QuickJS](https://bellard.org/quickjs) | MIT |
|
||||||
|
| [rayjule](https://github.com/SabeDoesThings/rayjule) | **5.5** | [Jule](https://jule.dev/) | MIT |
|
||||||
| [raylib-raku](https://github.com/vushu/raylib-raku) | **auto** | [Raku](https://www.raku.org) | Artistic License 2.0 |
|
| [raylib-raku](https://github.com/vushu/raylib-raku) | **auto** | [Raku](https://www.raku.org) | Artistic License 2.0 |
|
||||||
| [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | **5.5-dev** | [Lean4](https://lean-lang.org) | BSD-3-Clause |
|
| [Raylib.lean](https://github.com/KislyjKisel/Raylib.lean) | **5.5-dev** | [Lean4](https://lean-lang.org) | BSD-3-Clause |
|
||||||
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
|
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
|
||||||
|
|
@ -101,6 +104,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [fnl-raylib](https://github.com/0riginaln0/fnl-raylib) | **5.5** | [Fennel](https://fennel-lang.org/) | MIT |
|
| [fnl-raylib](https://github.com/0riginaln0/fnl-raylib) | **5.5** | [Fennel](https://fennel-lang.org/) | MIT |
|
||||||
| [Rayua](https://github.com/uiua-lang/rayua) | **5.5** | [Uiua](https://www.uiua.org/) | **???** |
|
| [Rayua](https://github.com/uiua-lang/rayua) | **5.5** | [Uiua](https://www.uiua.org/) | **???** |
|
||||||
|
|
||||||
|
|
||||||
### Utility Wrapers
|
### Utility Wrapers
|
||||||
|
|
||||||
These are utility wrappers for specific languages, they are not required to use raylib in the language but may adapt the raylib API to be more inline with the language's paradigm.
|
These are utility wrappers for specific languages, they are not required to use raylib in the language but may adapt the raylib API to be more inline with the language's paradigm.
|
||||||
|
|
|
||||||
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
Copyright (c) 2013-2026 Ramon Santamaria (@raysan5)
|
||||||
|
|
||||||
This software is provided "as-is", without any express or implied warranty. In no event
|
This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
will the authors be held liable for any damages arising from the use of this software.
|
will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
<a href="https://github.com/raysan5/raylib/graphs/contributors">
|
<a href="https://github.com/raysan5/raylib/graphs/contributors">
|
||||||
<img src="https://contrib.rocks/image?repo=raysan5/raylib&max=500&columns=20&anon=1" />
|
<img src="https://contrib.rocks/image?repo=raysan5/raylib&max=800&columns=24&anon=0" />
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
license
|
license
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@ _Current version of raylib is complete and functional but there is always room f
|
||||||
|
|
||||||
**raylib 5.x**
|
**raylib 5.x**
|
||||||
- [ ] `rcore`: Support additional platforms: iOS, consoles?
|
- [ ] `rcore`: Support additional platforms: iOS, consoles?
|
||||||
- [ ] `rcore_web`: Avoid GLFW dependency, functionality can be directly implemented using emscripten SDK
|
- [x] `rcore_web`: Avoid GLFW dependency, functionality can be directly implemented using emscripten SDK
|
||||||
- [ ] `rlgl`: Review GLSL shaders naming conventions for consistency
|
- [ ] `rlgl`: Review GLSL shaders naming conventions for consistency
|
||||||
- [ ] `textures`: Improve compressed textures support, loading and saving
|
- [ ] `textures`: Improve compressed textures support, loading and saving
|
||||||
- [ ] `rmodels`: Improve 3d objects loading, specially animations (obj, gltf)
|
- [ ] `rmodels`: Improve 3d objects loading, specially animations (obj, gltf)
|
||||||
- [ ] `raudio`: Implement miniaudio high-level provided features
|
- [ ] `raudio`: Implement miniaudio high-level provided features
|
||||||
- [ ] `examples`: Review all examples, add more and better code explanations
|
- [x] `examples`: Review all examples, add more and better code explanations
|
||||||
- [ ] Software renderer backend? Maybe using `Image` provided API
|
- [x] Software renderer backend? Maybe using `Image` provided API
|
||||||
|
|
||||||
**raylib 4.x**
|
**raylib 4.x**
|
||||||
- [x] Split core module into separate platforms?
|
- [x] Split core module into separate platforms?
|
||||||
|
|
|
||||||
18
SECURITY.md
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Most considerations of errors and defects can be handled using the project Issues and/or Discussions.
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 6.0.x | :white_check_mark: |
|
||||||
|
| < 5.5 | :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
Discovered vulnerability can be directly reported using the project Issues and/or Discussions.
|
||||||
|
|
||||||
|
_TODO: Tell them where to go, how often they can expect to get an update on a
|
||||||
|
reported vulnerability, what to expect if the vulnerability is accepted or
|
||||||
|
declined, etc._
|
||||||
26
build.zig
|
|
@ -2,7 +2,7 @@ const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
/// Minimum supported version of Zig
|
/// Minimum supported version of Zig
|
||||||
const min_ver = "0.15.1";
|
const min_ver = "0.16.0-dev.2349+204fa8959";
|
||||||
|
|
||||||
const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str;
|
const emccOutputDir = "zig-out" ++ std.fs.path.sep_str ++ "htmlout" ++ std.fs.path.sep_str;
|
||||||
const emccOutputFile = "index.html";
|
const emccOutputFile = "index.html";
|
||||||
|
|
@ -197,7 +197,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
}
|
}
|
||||||
|
|
||||||
var c_source_files: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 2);
|
var c_source_files: std.ArrayList([]const u8) = try .initCapacity(b.allocator, 2);
|
||||||
c_source_files.appendSliceAssumeCapacity(&.{ "src/rcore.c", "src/utils.c" });
|
c_source_files.appendSliceAssumeCapacity(&.{"src/rcore.c"});
|
||||||
|
|
||||||
if (options.rshapes) {
|
if (options.rshapes) {
|
||||||
try c_source_files.append(b.allocator, "src/rshapes.c");
|
try c_source_files.append(b.allocator, "src/rshapes.c");
|
||||||
|
|
@ -348,7 +348,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
.freebsd, .openbsd, .netbsd, .dragonfly => {
|
||||||
try c_source_files.append(b.allocator, "rglfw.c");
|
try c_source_files.append(b.allocator, "src/rglfw.c");
|
||||||
raylib.root_module.linkSystemLibrary("GL", .{});
|
raylib.root_module.linkSystemLibrary("GL", .{});
|
||||||
raylib.root_module.linkSystemLibrary("rt", .{});
|
raylib.root_module.linkSystemLibrary("rt", .{});
|
||||||
raylib.root_module.linkSystemLibrary("dl", .{});
|
raylib.root_module.linkSystemLibrary("dl", .{});
|
||||||
|
|
@ -448,7 +448,7 @@ pub const Options = struct {
|
||||||
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
|
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
|
||||||
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
|
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
|
||||||
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
|
.config = b.option([]const u8, "config", "Compile with custom define macros overriding config.h") orelse &.{},
|
||||||
.android_ndk = b.option([]const u8, "android_ndk", "specify path to android ndk") orelse std.process.getEnvVarOwned(b.allocator, "ANDROID_NDK_HOME") catch "",
|
.android_ndk = b.option([]const u8, "android_ndk", "specify path to android ndk") orelse b.graph.environ_map.get("ANDROID_NDK_HOME") orelse "",
|
||||||
.android_api_version = b.option([]const u8, "android_api_version", "specify target android API level") orelse defaults.android_api_version,
|
.android_api_version = b.option([]const u8, "android_api_version", "specify target android API level") orelse defaults.android_api_version,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -523,15 +523,17 @@ fn addExamples(
|
||||||
) !*std.Build.Step {
|
) !*std.Build.Step {
|
||||||
const all = b.step(module, "All " ++ module ++ " examples");
|
const all = b.step(module, "All " ++ module ++ " examples");
|
||||||
const module_subpath = b.pathJoin(&.{ "examples", module });
|
const module_subpath = b.pathJoin(&.{ "examples", module });
|
||||||
var dir = try std.fs.cwd().openDir(b.pathFromRoot(module_subpath), .{ .iterate = true });
|
|
||||||
defer dir.close();
|
var dir = try std.Io.Dir.cwd().openDir(b.graph.io, b.pathFromRoot(module_subpath), .{ .iterate = true });
|
||||||
|
defer dir.close(b.graph.io);
|
||||||
|
|
||||||
var iter = dir.iterate();
|
var iter = dir.iterate();
|
||||||
while (try iter.next()) |entry| {
|
while (try iter.next(b.graph.io)) |entry| {
|
||||||
if (entry.kind != .file) continue;
|
if (entry.kind != .file) continue;
|
||||||
const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
|
const extension_idx = std.mem.lastIndexOf(u8, entry.name, ".c") orelse continue;
|
||||||
const name = entry.name[0..extension_idx];
|
const name = entry.name[0..extension_idx];
|
||||||
const path = b.pathJoin(&.{ module_subpath, entry.name });
|
const filename = try std.fmt.allocPrint(b.allocator, "{s}.c", .{name});
|
||||||
|
const path = b.pathJoin(&.{ module_subpath, filename });
|
||||||
|
|
||||||
// zig's mingw headers do not include pthread.h
|
// zig's mingw headers do not include pthread.h
|
||||||
if (std.mem.eql(u8, "core_loading_thread", name) and target.result.os.tag == .windows) continue;
|
if (std.mem.eql(u8, "core_loading_thread", name) and target.result.os.tag == .windows) continue;
|
||||||
|
|
@ -553,12 +555,11 @@ fn addExamples(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (std.mem.eql(u8, name, "rlgl_standalone")) {
|
if (std.mem.eql(u8, name, "rlgl_standalone")) {
|
||||||
//TODO: Make rlgl_standalone example work
|
exe_mod.addIncludePath(b.path("src"));
|
||||||
continue;
|
exe_mod.addIncludePath(b.path("src/external/glfw/include"));
|
||||||
}
|
}
|
||||||
if (std.mem.eql(u8, name, "raylib_opengl_interop")) {
|
if (std.mem.eql(u8, name, "raylib_opengl_interop")) {
|
||||||
//TODO: Make raylib_opengl_interop example work
|
exe_mod.addIncludePath(b.path("src/external"));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{ .optimize = optimize });
|
const emcc_flags = emsdk.emccDefaultFlags(b.allocator, .{ .optimize = optimize });
|
||||||
|
|
@ -650,6 +651,7 @@ fn addExamples(
|
||||||
all.dependOn(&install_cmd.step);
|
all.dependOn(&install_cmd.step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,12 @@ if (${PLATFORM} MATCHES "Desktop")
|
||||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
find_package(OpenGL QUIET)
|
find_package(OpenGL QUIET)
|
||||||
set(LIBS_PRIVATE ${OPENGL_LIBRARIES} winmm)
|
set(LIBS_PRIVATE ${OPENGL_LIBRARIES} winmm)
|
||||||
|
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "QNX")
|
||||||
|
set(GRAPHICS "GRAPHICS_API_OPENGL_ES2")
|
||||||
|
find_library(GLESV2 GLESv2)
|
||||||
|
find_library(EGL EGL)
|
||||||
|
set(LIBS_PUBLIC m)
|
||||||
|
set(LIBS_PRIVATE ${GLESV2} ${EGL} atomic pthread dl)
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
find_library(pthread NAMES pthread)
|
find_library(pthread NAMES pthread)
|
||||||
find_package(OpenGL QUIET)
|
find_package(OpenGL QUIET)
|
||||||
|
|
@ -143,6 +149,24 @@ elseif ("${PLATFORM}" MATCHES "SDL")
|
||||||
endif()
|
endif()
|
||||||
elseif ("${PLATFORM}" MATCHES "RGFW")
|
elseif ("${PLATFORM}" MATCHES "RGFW")
|
||||||
set(PLATFORM_CPP "PLATFORM_DESKTOP_RGFW")
|
set(PLATFORM_CPP "PLATFORM_DESKTOP_RGFW")
|
||||||
|
|
||||||
|
if (APPLE)
|
||||||
|
find_library(COCOA Cocoa)
|
||||||
|
find_library(OPENGL OpenGL)
|
||||||
|
|
||||||
|
set(LIBS_PRIVATE ${COCOA} ${OPENGL})
|
||||||
|
elseif (WIN32)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
set(LIBS_PRIVATE ${OPENGL_LIBRARIES} gdi32)
|
||||||
|
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "QNX")
|
||||||
|
message(FATAL_ERROR "RGFW platform does not support QNX. Use PLATFORM=Desktop or PLATFORM=SDL instead.")
|
||||||
|
elseif (UNIX)
|
||||||
|
find_package(X11 REQUIRED)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
|
set(LIBS_PRIVATE ${X11_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||||
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
if (NOT ${OPENGL_VERSION} MATCHES "OFF")
|
if (NOT ${OPENGL_VERSION} MATCHES "OFF")
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
# > PLATFORM_ANDROID:
|
# > PLATFORM_ANDROID:
|
||||||
# - Android (ARM, ARM64)
|
# - Android (ARM, ARM64)
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
# Copyright (c) 2013-2026 Ramon Santamaria (@raysan5)
|
||||||
#
|
#
|
||||||
# This software is provided "as-is", without any express or implied warranty. In no event
|
# This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
# will the authors be held liable for any damages arising from the use of this software.
|
# will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
@ -205,15 +205,17 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
|
ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
|
||||||
MAKE = mingw32-make
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
|
MAKE = mingw32-make
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
|
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
MAKE = mingw32-make
|
MAKE = mingw32-make
|
||||||
else
|
else
|
||||||
EMMAKE != type emmake
|
EMMAKE := $(shell command -v emmake)
|
||||||
ifneq (, $(EMMAKE))
|
ifneq (, $(EMMAKE))
|
||||||
MAKE = emmake make
|
MAKE = $(EMMAKE) make
|
||||||
else
|
else
|
||||||
MAKE = mingw32-make
|
MAKE = mingw32-make
|
||||||
endif
|
endif
|
||||||
|
|
@ -391,14 +393,14 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_GLFW)
|
||||||
# NOTE: Required packages: libegl1-mesa-dev
|
# NOTE: Required packages: libegl1-mesa-dev
|
||||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||||
|
|
||||||
# On X11 requires also below libraries
|
# On Wayland, additional libraries requires
|
||||||
LDLIBS += -lX11
|
|
||||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
|
||||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
|
||||||
|
|
||||||
# On Wayland windowing system, additional libraries requires
|
|
||||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||||
|
else
|
||||||
|
# On X11, additional libraries required
|
||||||
|
LDLIBS += -lX11
|
||||||
|
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||||
|
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||||
endif
|
endif
|
||||||
# Explicit link to libc
|
# Explicit link to libc
|
||||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||||
|
|
@ -437,15 +439,16 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_DESKTOP_SDL)
|
||||||
# NOTE: Required packages: libegl1-mesa-dev
|
# NOTE: Required packages: libegl1-mesa-dev
|
||||||
LDLIBS = -lraylib $(SDL_LIBRARIES) -lGL -lm -lpthread -ldl -lrt
|
LDLIBS = -lraylib $(SDL_LIBRARIES) -lGL -lm -lpthread -ldl -lrt
|
||||||
|
|
||||||
# On X11 requires also below libraries
|
# On X11, addition libraries required
|
||||||
LDLIBS += -lX11
|
LDLIBS += -lX11
|
||||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||||
|
|
||||||
# On Wayland windowing system, additional libraries requires
|
# On Wayland, additional libraries requires
|
||||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Explicit link to libc
|
# Explicit link to libc
|
||||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||||
LDLIBS += -lc
|
LDLIBS += -lc
|
||||||
|
|
@ -542,6 +545,7 @@ CORE = \
|
||||||
core/core_input_mouse_wheel \
|
core/core_input_mouse_wheel \
|
||||||
core/core_input_multitouch \
|
core/core_input_multitouch \
|
||||||
core/core_input_virtual_controls \
|
core/core_input_virtual_controls \
|
||||||
|
core/core_keyboard_testbed \
|
||||||
core/core_monitor_detector \
|
core/core_monitor_detector \
|
||||||
core/core_random_sequence \
|
core/core_random_sequence \
|
||||||
core/core_random_values \
|
core/core_random_values \
|
||||||
|
|
@ -557,6 +561,7 @@ CORE = \
|
||||||
core/core_window_flags \
|
core/core_window_flags \
|
||||||
core/core_window_letterbox \
|
core/core_window_letterbox \
|
||||||
core/core_window_should_close \
|
core/core_window_should_close \
|
||||||
|
core/core_window_web \
|
||||||
core/core_world_screen
|
core/core_world_screen
|
||||||
|
|
||||||
SHAPES = \
|
SHAPES = \
|
||||||
|
|
@ -574,7 +579,9 @@ SHAPES = \
|
||||||
shapes/shapes_easings_ball \
|
shapes/shapes_easings_ball \
|
||||||
shapes/shapes_easings_box \
|
shapes/shapes_easings_box \
|
||||||
shapes/shapes_easings_rectangles \
|
shapes/shapes_easings_rectangles \
|
||||||
|
shapes/shapes_easings_testbed \
|
||||||
shapes/shapes_following_eyes \
|
shapes/shapes_following_eyes \
|
||||||
|
shapes/shapes_hilbert_curve \
|
||||||
shapes/shapes_kaleidoscope \
|
shapes/shapes_kaleidoscope \
|
||||||
shapes/shapes_lines_bezier \
|
shapes/shapes_lines_bezier \
|
||||||
shapes/shapes_lines_drawing \
|
shapes/shapes_lines_drawing \
|
||||||
|
|
@ -605,6 +612,7 @@ TEXTURES = \
|
||||||
textures/textures_bunnymark \
|
textures/textures_bunnymark \
|
||||||
textures/textures_cellular_automata \
|
textures/textures_cellular_automata \
|
||||||
textures/textures_fog_of_war \
|
textures/textures_fog_of_war \
|
||||||
|
textures/textures_framebuffer_rendering \
|
||||||
textures/textures_gif_player \
|
textures/textures_gif_player \
|
||||||
textures/textures_image_channel \
|
textures/textures_image_channel \
|
||||||
textures/textures_image_drawing \
|
textures/textures_image_drawing \
|
||||||
|
|
@ -649,6 +657,8 @@ TEXT = \
|
||||||
text/text_writing_anim
|
text/text_writing_anim
|
||||||
|
|
||||||
MODELS = \
|
MODELS = \
|
||||||
|
models/models_animation_blending \
|
||||||
|
models/models_animation_bone_blending \
|
||||||
models/models_animation_gpu_skinning \
|
models/models_animation_gpu_skinning \
|
||||||
models/models_animation_playing \
|
models/models_animation_playing \
|
||||||
models/models_basic_voxel \
|
models/models_basic_voxel \
|
||||||
|
|
@ -701,6 +711,7 @@ SHADERS = \
|
||||||
shaders/shaders_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching_rendering \
|
shaders/shaders_raymarching_rendering \
|
||||||
|
shaders/shaders_rlgl_compute \
|
||||||
shaders/shaders_rounded_rectangle \
|
shaders/shaders_rounded_rectangle \
|
||||||
shaders/shaders_shadowmap_rendering \
|
shaders/shaders_shadowmap_rendering \
|
||||||
shaders/shaders_shapes_textures \
|
shaders/shaders_shapes_textures \
|
||||||
|
|
@ -722,14 +733,6 @@ AUDIO = \
|
||||||
audio/audio_sound_positioning \
|
audio/audio_sound_positioning \
|
||||||
audio/audio_spectrum_visualizer \
|
audio/audio_spectrum_visualizer \
|
||||||
audio/audio_stream_effects
|
audio/audio_stream_effects
|
||||||
|
|
||||||
OTHERS = \
|
|
||||||
others/easings_testbed \
|
|
||||||
others/embedded_files_loading \
|
|
||||||
others/raylib_opengl_interop \
|
|
||||||
others/rlgl_compute_shader \
|
|
||||||
others/rlgl_standalone \
|
|
||||||
others/web_basic_window
|
|
||||||
#EXAMPLES_LIST_END
|
#EXAMPLES_LIST_END
|
||||||
|
|
||||||
# Define processes to execute
|
# Define processes to execute
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
# > PLATFORM_ANDROID:
|
# > PLATFORM_ANDROID:
|
||||||
# - Android (ARM, ARM64)
|
# - Android (ARM, ARM64)
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
# Copyright (c) 2013-2026 Ramon Santamaria (@raysan5)
|
||||||
#
|
#
|
||||||
# This software is provided "as-is", without any express or implied warranty. In no event
|
# This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
# will the authors be held liable for any damages arising from the use of this software.
|
# will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
|
@ -208,12 +208,12 @@ ifeq ($(TARGET_PLATFORM),PLATFORM_ANDROID)
|
||||||
MAKE = mingw32-make
|
MAKE = mingw32-make
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
|
ifeq ($(TARGET_PLATFORM),$(filter $(TARGET_PLATFORM),PLATFORM_WEB PLATFORM_WEB_RGFW))
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
MAKE = mingw32-make
|
MAKE = mingw32-make
|
||||||
else
|
else
|
||||||
EMMAKE != type emmake
|
EMMAKE := $(shell command -v emmake)
|
||||||
ifneq (, $(EMMAKE))
|
ifneq (, $(EMMAKE))
|
||||||
MAKE = emmake make
|
MAKE = $(EMMAKE) make
|
||||||
else
|
else
|
||||||
MAKE = mingw32-make
|
MAKE = mingw32-make
|
||||||
endif
|
endif
|
||||||
|
|
@ -530,6 +530,7 @@ CORE = \
|
||||||
core/core_input_mouse_wheel \
|
core/core_input_mouse_wheel \
|
||||||
core/core_input_multitouch \
|
core/core_input_multitouch \
|
||||||
core/core_input_virtual_controls \
|
core/core_input_virtual_controls \
|
||||||
|
core/core_keyboard_testbed \
|
||||||
core/core_monitor_detector \
|
core/core_monitor_detector \
|
||||||
core/core_random_sequence \
|
core/core_random_sequence \
|
||||||
core/core_random_values \
|
core/core_random_values \
|
||||||
|
|
@ -545,6 +546,7 @@ CORE = \
|
||||||
core/core_window_flags \
|
core/core_window_flags \
|
||||||
core/core_window_letterbox \
|
core/core_window_letterbox \
|
||||||
core/core_window_should_close \
|
core/core_window_should_close \
|
||||||
|
core/core_window_web \
|
||||||
core/core_world_screen
|
core/core_world_screen
|
||||||
|
|
||||||
SHAPES = \
|
SHAPES = \
|
||||||
|
|
@ -562,7 +564,9 @@ SHAPES = \
|
||||||
shapes/shapes_easings_ball \
|
shapes/shapes_easings_ball \
|
||||||
shapes/shapes_easings_box \
|
shapes/shapes_easings_box \
|
||||||
shapes/shapes_easings_rectangles \
|
shapes/shapes_easings_rectangles \
|
||||||
|
shapes/shapes_easings_testbed \
|
||||||
shapes/shapes_following_eyes \
|
shapes/shapes_following_eyes \
|
||||||
|
shapes/shapes_hilbert_curve \
|
||||||
shapes/shapes_kaleidoscope \
|
shapes/shapes_kaleidoscope \
|
||||||
shapes/shapes_lines_bezier \
|
shapes/shapes_lines_bezier \
|
||||||
shapes/shapes_lines_drawing \
|
shapes/shapes_lines_drawing \
|
||||||
|
|
@ -593,6 +597,7 @@ TEXTURES = \
|
||||||
textures/textures_bunnymark \
|
textures/textures_bunnymark \
|
||||||
textures/textures_cellular_automata \
|
textures/textures_cellular_automata \
|
||||||
textures/textures_fog_of_war \
|
textures/textures_fog_of_war \
|
||||||
|
textures/textures_framebuffer_rendering \
|
||||||
textures/textures_gif_player \
|
textures/textures_gif_player \
|
||||||
textures/textures_image_channel \
|
textures/textures_image_channel \
|
||||||
textures/textures_image_drawing \
|
textures/textures_image_drawing \
|
||||||
|
|
@ -637,6 +642,8 @@ TEXT = \
|
||||||
text/text_writing_anim
|
text/text_writing_anim
|
||||||
|
|
||||||
MODELS = \
|
MODELS = \
|
||||||
|
models/models_animation_blending \
|
||||||
|
models/models_animation_bone_blending \
|
||||||
models/models_animation_gpu_skinning \
|
models/models_animation_gpu_skinning \
|
||||||
models/models_animation_playing \
|
models/models_animation_playing \
|
||||||
models/models_basic_voxel \
|
models/models_basic_voxel \
|
||||||
|
|
@ -689,6 +696,7 @@ SHADERS = \
|
||||||
shaders/shaders_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching_rendering \
|
shaders/shaders_raymarching_rendering \
|
||||||
|
shaders/shaders_rlgl_compute \
|
||||||
shaders/shaders_rounded_rectangle \
|
shaders/shaders_rounded_rectangle \
|
||||||
shaders/shaders_shadowmap_rendering \
|
shaders/shaders_shadowmap_rendering \
|
||||||
shaders/shaders_shapes_textures \
|
shaders/shaders_shapes_textures \
|
||||||
|
|
@ -818,6 +826,9 @@ core/core_input_multitouch: core/core_input_multitouch.c
|
||||||
core/core_input_virtual_controls: core/core_input_virtual_controls.c
|
core/core_input_virtual_controls: core/core_input_virtual_controls.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
core/core_keyboard_testbed: core/core_keyboard_testbed.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
core/core_monitor_detector: core/core_monitor_detector.c
|
core/core_monitor_detector: core/core_monitor_detector.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
|
@ -865,6 +876,9 @@ core/core_window_letterbox: core/core_window_letterbox.c
|
||||||
core/core_window_should_close: core/core_window_should_close.c
|
core/core_window_should_close: core/core_window_should_close.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
core/core_window_web: core/core_window_web.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
core/core_world_screen: core/core_world_screen.c
|
core/core_world_screen: core/core_world_screen.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
|
@ -911,9 +925,15 @@ shapes/shapes_easings_box: shapes/shapes_easings_box.c
|
||||||
shapes/shapes_easings_rectangles: shapes/shapes_easings_rectangles.c
|
shapes/shapes_easings_rectangles: shapes/shapes_easings_rectangles.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
shapes/shapes_easings_testbed: shapes/shapes_easings_testbed.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
shapes/shapes_following_eyes: shapes/shapes_following_eyes.c
|
shapes/shapes_following_eyes: shapes/shapes_following_eyes.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
shapes/shapes_hilbert_curve: shapes/shapes_hilbert_curve.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
shapes/shapes_kaleidoscope: shapes/shapes_kaleidoscope.c
|
shapes/shapes_kaleidoscope: shapes/shapes_kaleidoscope.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
|
@ -1005,6 +1025,9 @@ textures/textures_cellular_automata: textures/textures_cellular_automata.c
|
||||||
textures/textures_fog_of_war: textures/textures_fog_of_war.c
|
textures/textures_fog_of_war: textures/textures_fog_of_war.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
textures/textures_framebuffer_rendering: textures/textures_framebuffer_rendering.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
textures/textures_gif_player: textures/textures_gif_player.c
|
textures/textures_gif_player: textures/textures_gif_player.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file textures/resources/scarfy_run.gif@resources/scarfy_run.gif
|
--preload-file textures/resources/scarfy_run.gif@resources/scarfy_run.gif
|
||||||
|
|
@ -1176,6 +1199,18 @@ text/text_writing_anim: text/text_writing_anim.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
# Compile MODELS examples
|
# Compile MODELS examples
|
||||||
|
models/models_animation_blending: models/models_animation_blending.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
|
--preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb \
|
||||||
|
--preload-file models/resources/shaders/glsl100/skinning.vs@resources/shaders/glsl100/skinning.vs \
|
||||||
|
--preload-file models/resources/shaders/glsl100/skinning.fs@resources/shaders/glsl100/skinning.fs
|
||||||
|
|
||||||
|
models/models_animation_bone_blending: models/models_animation_bone_blending.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
|
--preload-file models/resources/models/gltf/greenman.glb@resources/models/gltf/greenman.glb \
|
||||||
|
--preload-file models/resources/shaders/glsl100/skinning.vs@resources/shaders/glsl100/skinning.vs \
|
||||||
|
--preload-file models/resources/shaders/glsl100/skinning.fs@resources/shaders/glsl100/skinning.fs
|
||||||
|
|
||||||
models/models_animation_gpu_skinning: models/models_animation_gpu_skinning.c
|
models/models_animation_gpu_skinning: models/models_animation_gpu_skinning.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file models/resources/models/gltf/greenman.glb@resources/models/gltf/greenman.glb \
|
--preload-file models/resources/models/gltf/greenman.glb@resources/models/gltf/greenman.glb \
|
||||||
|
|
@ -1367,15 +1402,15 @@ shaders/shaders_fog_rendering: shaders/shaders_fog_rendering.c
|
||||||
shaders/shaders_game_of_life: shaders/shaders_game_of_life.c
|
shaders/shaders_game_of_life: shaders/shaders_game_of_life.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file shaders/resources/shaders/glsl100/game_of_life.fs@resources/shaders/glsl100/game_of_life.fs \
|
--preload-file shaders/resources/shaders/glsl100/game_of_life.fs@resources/shaders/glsl100/game_of_life.fs \
|
||||||
--preload-file shaders/resources/game_of_life/acorn.png@resources/game_of_life/acorn.png \
|
--preload-file shaders/resources/game_of_life/r_pentomino.png@resources/game_of_life/r_pentomino.png \
|
||||||
--preload-file shaders/resources/game_of_life/breeder.png@resources/game_of_life/breeder.png \
|
|
||||||
--preload-file shaders/resources/game_of_life/glider.png@resources/game_of_life/glider.png \
|
--preload-file shaders/resources/game_of_life/glider.png@resources/game_of_life/glider.png \
|
||||||
--preload-file shaders/resources/game_of_life/glider_gun.png@resources/game_of_life/glider_gun.png \
|
--preload-file shaders/resources/game_of_life/acorn.png@resources/game_of_life/acorn.png \
|
||||||
|
--preload-file shaders/resources/game_of_life/spaceships.png@resources/game_of_life/spaceships.png \
|
||||||
|
--preload-file shaders/resources/game_of_life/still_lifes.png@resources/game_of_life/still_lifes.png \
|
||||||
--preload-file shaders/resources/game_of_life/oscillators.png@resources/game_of_life/oscillators.png \
|
--preload-file shaders/resources/game_of_life/oscillators.png@resources/game_of_life/oscillators.png \
|
||||||
--preload-file shaders/resources/game_of_life/puffer_train.png@resources/game_of_life/puffer_train.png \
|
--preload-file shaders/resources/game_of_life/puffer_train.png@resources/game_of_life/puffer_train.png \
|
||||||
--preload-file shaders/resources/game_of_life/r_pentomino.png@resources/game_of_life/r_pentomino.png \
|
--preload-file shaders/resources/game_of_life/glider_gun.png@resources/game_of_life/glider_gun.png \
|
||||||
--preload-file shaders/resources/game_of_life/spaceships.png@resources/game_of_life/spaceships.png \
|
--preload-file shaders/resources/game_of_life/breeder.png@resources/game_of_life/breeder.png
|
||||||
--preload-file shaders/resources/game_of_life/still_lifes.png@resources/game_of_life/still_lifes.png
|
|
||||||
|
|
||||||
shaders/shaders_hot_reloading: shaders/shaders_hot_reloading.c
|
shaders/shaders_hot_reloading: shaders/shaders_hot_reloading.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
|
|
@ -1449,6 +1484,9 @@ shaders/shaders_raymarching_rendering: shaders/shaders_raymarching_rendering.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file shaders/resources/shaders/glsl100/raymarching.fs@resources/shaders/glsl100/raymarching.fs
|
--preload-file shaders/resources/shaders/glsl100/raymarching.fs@resources/shaders/glsl100/raymarching.fs
|
||||||
|
|
||||||
|
shaders/shaders_rlgl_compute: shaders/shaders_rlgl_compute.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
shaders/shaders_rounded_rectangle: shaders/shaders_rounded_rectangle.c
|
shaders/shaders_rounded_rectangle: shaders/shaders_rounded_rectangle.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file shaders/resources/shaders/glsl100/base.vs@resources/shaders/glsl100/base.vs \
|
--preload-file shaders/resources/shaders/glsl100/base.vs@resources/shaders/glsl100/base.vs \
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ You may find it easier to use than other toolchains, especially when it comes to
|
||||||
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
|
- `zig build [module]` to compile all examples for a module (e.g. `zig build core`)
|
||||||
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
|
- `zig build [example]` to compile _and run_ a particular example (e.g. `zig build core_basic_window`)
|
||||||
|
|
||||||
## EXAMPLES COLLECTION [TOTAL: 205]
|
## EXAMPLES COLLECTION [TOTAL: 207]
|
||||||
|
|
||||||
### category: core [47]
|
### category: core [49]
|
||||||
|
|
||||||
Examples using raylib [core](../src/rcore.c) module platform functionality: window creation, inputs, drawing modes and system functionality.
|
Examples using raylib [core](../src/rcore.c) module platform functionality: window creation, inputs, drawing modes and system functionality.
|
||||||
|
|
||||||
|
|
@ -69,11 +69,13 @@ Examples using raylib [core](../src/rcore.c) module platform functionality: wind
|
||||||
| [core_directory_files](core/core_directory_files.c) | <img src="core/core_directory_files.png" alt="core_directory_files" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Hugo ARNAL](https://github.com/hugoarnal) |
|
| [core_directory_files](core/core_directory_files.c) | <img src="core/core_directory_files.png" alt="core_directory_files" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Hugo ARNAL](https://github.com/hugoarnal) |
|
||||||
| [core_highdpi_testbed](core/core_highdpi_testbed.c) | <img src="core/core_highdpi_testbed.png" alt="core_highdpi_testbed" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_highdpi_testbed](core/core_highdpi_testbed.c) | <img src="core/core_highdpi_testbed.png" alt="core_highdpi_testbed" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_screen_recording](core/core_screen_recording.c) | <img src="core/core_screen_recording.png" alt="core_screen_recording" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_screen_recording](core/core_screen_recording.c) | <img src="core/core_screen_recording.png" alt="core_screen_recording" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_clipboard_text](core/core_clipboard_text.c) | <img src="core/core_clipboard_text.png" alt="core_clipboard_text" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ananth S](https://github.com/Ananth1839) |
|
| [core_clipboard_text](core/core_clipboard_text.c) | <img src="core/core_clipboard_text.png" alt="core_clipboard_text" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ananth S](https://github.com/Ananth1839) |
|
||||||
| [core_text_file_loading](core/core_text_file_loading.c) | <img src="core/core_text_file_loading.png" alt="core_text_file_loading" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Aanjishnu Bhattacharyya](https://github.com/NimComPoo-04) |
|
| [core_text_file_loading](core/core_text_file_loading.c) | <img src="core/core_text_file_loading.png" alt="core_text_file_loading" width="80"> | ⭐☆☆☆ | 5.5 | 5.6 | [Aanjishnu Bhattacharyya](https://github.com/NimComPoo-04) |
|
||||||
| [core_compute_hash](core/core_compute_hash.c) | <img src="core/core_compute_hash.png" alt="core_compute_hash" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_compute_hash](core/core_compute_hash.c) | <img src="core/core_compute_hash.png" alt="core_compute_hash" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
|
| [core_keyboard_testbed](core/core_keyboard_testbed.c) | <img src="core/core_keyboard_testbed.png" alt="core_keyboard_testbed" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
|
| [core_window_web](core/core_window_web.c) | <img src="core/core_window_web.png" alt="core_window_web" width="80"> | ⭐☆☆☆ | 1.3 | 5.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
|
|
||||||
### category: shapes [38]
|
### category: shapes [40]
|
||||||
|
|
||||||
Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module.
|
Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module.
|
||||||
|
|
||||||
|
|
@ -117,8 +119,10 @@ Examples using raylib shapes drawing functionality, provided by raylib [shapes](
|
||||||
| [shapes_rlgl_triangle](shapes/shapes_rlgl_triangle.c) | <img src="shapes/shapes_rlgl_triangle.png" alt="shapes_rlgl_triangle" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Robin](https://github.com/RobinsAviary) |
|
| [shapes_rlgl_triangle](shapes/shapes_rlgl_triangle.c) | <img src="shapes/shapes_rlgl_triangle.png" alt="shapes_rlgl_triangle" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [Robin](https://github.com/RobinsAviary) |
|
||||||
| [shapes_ball_physics](shapes/shapes_ball_physics.c) | <img src="shapes/shapes_ball_physics.png" alt="shapes_ball_physics" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
| [shapes_ball_physics](shapes/shapes_ball_physics.c) | <img src="shapes/shapes_ball_physics.png" alt="shapes_ball_physics" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
||||||
| [shapes_penrose_tile](shapes/shapes_penrose_tile.c) | <img src="shapes/shapes_penrose_tile.png" alt="shapes_penrose_tile" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
| [shapes_penrose_tile](shapes/shapes_penrose_tile.c) | <img src="shapes/shapes_penrose_tile.png" alt="shapes_penrose_tile" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
||||||
|
| [shapes_hilbert_curve](shapes/shapes_hilbert_curve.c) | <img src="shapes/shapes_hilbert_curve.png" alt="shapes_hilbert_curve" width="80"> | ⭐⭐⭐☆ | 5.6 | 5.6 | [Hamza RAHAL](https://github.com/hmz-rhl) |
|
||||||
|
| [shapes_easings_testbed](shapes/shapes_easings_testbed.c) | <img src="shapes/shapes_easings_testbed.png" alt="shapes_easings_testbed" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Juan Miguel López](https://github.com/flashback-fx) |
|
||||||
|
|
||||||
### category: textures [29]
|
### category: textures [30]
|
||||||
|
|
||||||
Examples using raylib textures functionality, including image/textures loading/generation and drawing, provided by raylib [textures](../src/rtextures.c) module.
|
Examples using raylib textures functionality, including image/textures loading/generation and drawing, provided by raylib [textures](../src/rtextures.c) module.
|
||||||
|
|
||||||
|
|
@ -153,6 +157,7 @@ Examples using raylib textures functionality, including image/textures loading/g
|
||||||
| [textures_textured_curve](textures/textures_textured_curve.c) | <img src="textures/textures_textured_curve.png" alt="textures_textured_curve" width="80"> | ⭐⭐⭐☆ | 4.5 | 4.5 | [Jeffery Myers](https://github.com/JeffM2501) |
|
| [textures_textured_curve](textures/textures_textured_curve.c) | <img src="textures/textures_textured_curve.png" alt="textures_textured_curve" width="80"> | ⭐⭐⭐☆ | 4.5 | 4.5 | [Jeffery Myers](https://github.com/JeffM2501) |
|
||||||
| [textures_sprite_stacking](textures/textures_sprite_stacking.c) | <img src="textures/textures_sprite_stacking.png" alt="textures_sprite_stacking" width="80"> | ⭐⭐☆☆ | 5.6-dev | 6.0 | [Robin](https://github.com/RobinsAviary) |
|
| [textures_sprite_stacking](textures/textures_sprite_stacking.c) | <img src="textures/textures_sprite_stacking.png" alt="textures_sprite_stacking" width="80"> | ⭐⭐☆☆ | 5.6-dev | 6.0 | [Robin](https://github.com/RobinsAviary) |
|
||||||
| [textures_cellular_automata](textures/textures_cellular_automata.c) | <img src="textures/textures_cellular_automata.png" alt="textures_cellular_automata" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Jordi Santonja](https://github.com/JordSant) |
|
| [textures_cellular_automata](textures/textures_cellular_automata.c) | <img src="textures/textures_cellular_automata.png" alt="textures_cellular_automata" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Jordi Santonja](https://github.com/JordSant) |
|
||||||
|
| [textures_framebuffer_rendering](textures/textures_framebuffer_rendering.c) | <img src="textures/textures_framebuffer_rendering.png" alt="textures_framebuffer_rendering" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Jack Boakes](https://github.com/jackboakes) |
|
||||||
|
|
||||||
### category: text [16]
|
### category: text [16]
|
||||||
|
|
||||||
|
|
@ -177,7 +182,7 @@ Examples using raylib text functionality, including sprite fonts loading/generat
|
||||||
| [text_words_alignment](text/text_words_alignment.c) | <img src="text/text_words_alignment.png" alt="text_words_alignment" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [JP Mortiboys](https://github.com/themushroompirates) |
|
| [text_words_alignment](text/text_words_alignment.c) | <img src="text/text_words_alignment.png" alt="text_words_alignment" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [JP Mortiboys](https://github.com/themushroompirates) |
|
||||||
| [text_strings_management](text/text_strings_management.c) | <img src="text/text_strings_management.png" alt="text_strings_management" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
| [text_strings_management](text/text_strings_management.c) | <img src="text/text_strings_management.png" alt="text_strings_management" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [David Buzatto](https://github.com/davidbuzatto) |
|
||||||
|
|
||||||
### category: models [27]
|
### category: models [29]
|
||||||
|
|
||||||
Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib [models](../src/rmodels.c) module.
|
Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib [models](../src/rmodels.c) module.
|
||||||
|
|
||||||
|
|
@ -210,8 +215,10 @@ Examples using raylib models functionality, including models loading/generation
|
||||||
| [models_rotating_cube](models/models_rotating_cube.c) | <img src="models/models_rotating_cube.png" alt="models_rotating_cube" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) |
|
| [models_rotating_cube](models/models_rotating_cube.c) | <img src="models/models_rotating_cube.png" alt="models_rotating_cube" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Jopestpe](https://github.com/jopestpe) |
|
||||||
| [models_decals](models/models_decals.c) | <img src="models/models_decals.png" alt="models_decals" width="80"> | ⭐⭐⭐⭐️ | 5.6-dev | 5.6-dev | [JP Mortiboys](https://github.com/themushroompirates) |
|
| [models_decals](models/models_decals.c) | <img src="models/models_decals.png" alt="models_decals" width="80"> | ⭐⭐⭐⭐️ | 5.6-dev | 5.6-dev | [JP Mortiboys](https://github.com/themushroompirates) |
|
||||||
| [models_directional_billboard](models/models_directional_billboard.c) | <img src="models/models_directional_billboard.png" alt="models_directional_billboard" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6 | [Robin](https://github.com/RobinsAviary) |
|
| [models_directional_billboard](models/models_directional_billboard.c) | <img src="models/models_directional_billboard.png" alt="models_directional_billboard" width="80"> | ⭐⭐☆☆ | 5.6-dev | 5.6 | [Robin](https://github.com/RobinsAviary) |
|
||||||
|
| [models_animation_bone_blending](models/models_animation_bone_blending.c) | <img src="models/models_animation_bone_blending.png" alt="models_animation_bone_blending" width="80"> | ⭐⭐⭐⭐️ | 5.5 | 5.5 | [dmitrii-brand](https://github.com/dmitrii-brand) |
|
||||||
|
| [models_animation_blending](models/models_animation_blending.c) | <img src="models/models_animation_blending.png" alt="models_animation_blending" width="80"> | ☆☆☆☆ | 5.5 | 5.6-dev | [Kirandeep](https://github.com/Kirandeep-Singh-Khehra) |
|
||||||
|
|
||||||
### category: shaders [33]
|
### category: shaders [34]
|
||||||
|
|
||||||
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.c) module.
|
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.c) module.
|
||||||
|
|
||||||
|
|
@ -250,6 +257,7 @@ Examples using raylib shaders functionality, including shaders loading, paramete
|
||||||
| [shaders_rounded_rectangle](shaders/shaders_rounded_rectangle.c) | <img src="shaders/shaders_rounded_rectangle.png" alt="shaders_rounded_rectangle" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.5 | [Anstro Pleuton](https://github.com/anstropleuton) |
|
| [shaders_rounded_rectangle](shaders/shaders_rounded_rectangle.c) | <img src="shaders/shaders_rounded_rectangle.png" alt="shaders_rounded_rectangle" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.5 | [Anstro Pleuton](https://github.com/anstropleuton) |
|
||||||
| [shaders_depth_rendering](shaders/shaders_depth_rendering.c) | <img src="shaders/shaders_depth_rendering.png" alt="shaders_depth_rendering" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [Luís Almeida](https://github.com/luis605) |
|
| [shaders_depth_rendering](shaders/shaders_depth_rendering.c) | <img src="shaders/shaders_depth_rendering.png" alt="shaders_depth_rendering" width="80"> | ⭐⭐⭐☆ | 5.6-dev | 5.6-dev | [Luís Almeida](https://github.com/luis605) |
|
||||||
| [shaders_game_of_life](shaders/shaders_game_of_life.c) | <img src="shaders/shaders_game_of_life.png" alt="shaders_game_of_life" width="80"> | ⭐⭐⭐☆ | 5.6 | 5.6 | [Jordi Santonja](https://github.com/JordSant) |
|
| [shaders_game_of_life](shaders/shaders_game_of_life.c) | <img src="shaders/shaders_game_of_life.png" alt="shaders_game_of_life" width="80"> | ⭐⭐⭐☆ | 5.6 | 5.6 | [Jordi Santonja](https://github.com/JordSant) |
|
||||||
|
| [shaders_rlgl_compute](shaders/shaders_rlgl_compute.c) | <img src="shaders/shaders_rlgl_compute.png" alt="shaders_rlgl_compute" width="80"> | ⭐⭐⭐⭐️ | 4.0 | 4.0 | [Teddy Astie](https://github.com/tsnake41) |
|
||||||
|
|
||||||
### category: audio [9]
|
### category: audio [9]
|
||||||
|
|
||||||
|
|
@ -267,18 +275,5 @@ Examples using raylib audio functionality, including sound/music loading and pla
|
||||||
| [audio_sound_positioning](audio/audio_sound_positioning.c) | <img src="audio/audio_sound_positioning.png" alt="audio_sound_positioning" width="80"> | ⭐⭐☆☆ | 5.5 | 5.5 | [Le Juez Victor](https://github.com/Bigfoot71) |
|
| [audio_sound_positioning](audio/audio_sound_positioning.c) | <img src="audio/audio_sound_positioning.png" alt="audio_sound_positioning" width="80"> | ⭐⭐☆☆ | 5.5 | 5.5 | [Le Juez Victor](https://github.com/Bigfoot71) |
|
||||||
| [audio_spectrum_visualizer](audio/audio_spectrum_visualizer.c) | <img src="audio/audio_spectrum_visualizer.png" alt="audio_spectrum_visualizer" width="80"> | ⭐⭐⭐☆ | 6.0 | 5.6-dev | [IANN](https://github.com/meisei4) |
|
| [audio_spectrum_visualizer](audio/audio_spectrum_visualizer.c) | <img src="audio/audio_spectrum_visualizer.png" alt="audio_spectrum_visualizer" width="80"> | ⭐⭐⭐☆ | 6.0 | 5.6-dev | [IANN](https://github.com/meisei4) |
|
||||||
|
|
||||||
### category: others [6]
|
|
||||||
|
|
||||||
Examples showing raylib misc functionality that does not fit in other categories, like standalone modules usage or examples integrating external libraries.
|
|
||||||
|
|
||||||
| example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |
|
|
||||||
|-----------|--------|:-------------------:|:------------------:|:-----------------------:|:----------------------|
|
|
||||||
| [rlgl_standalone](others/rlgl_standalone.c) | <img src="others/rlgl_standalone.png" alt="rlgl_standalone" width="80"> | ⭐⭐⭐⭐️ | 1.6 | 4.0 | [Ramon Santamaria](https://github.com/raysan5) |
|
|
||||||
| [rlgl_compute_shader](others/rlgl_compute_shader.c) | <img src="others/rlgl_compute_shader.png" alt="rlgl_compute_shader" width="80"> | ⭐⭐⭐⭐️ | 4.0 | 4.0 | [Teddy Astie](https://github.com/tsnake41) |
|
|
||||||
| [easings_testbed](others/easings_testbed.c) | <img src="others/easings_testbed.png" alt="easings_testbed" width="80"> | ⭐⭐⭐☆ | 2.5 | 3.0 | [Juan Miguel López](https://github.com/flashback-fx) |
|
|
||||||
| [raylib_opengl_interop](others/raylib_opengl_interop.c) | <img src="others/raylib_opengl_interop.png" alt="raylib_opengl_interop" width="80"> | ⭐⭐⭐⭐️ | 3.8 | 4.0 | [Stephan Soller](https://github.com/arkanis) |
|
|
||||||
| [embedded_files_loading](others/embedded_files_loading.c) | <img src="others/embedded_files_loading.png" alt="embedded_files_loading" width="80"> | ⭐⭐☆☆ | 3.0 | 3.5 | [Kristian Holmgren](https://github.com/defutura) |
|
|
||||||
| [web_basic_window](others/web_basic_window.c) | <img src="others/web_basic_window.png" alt="web_basic_window" width="80"> | ⭐☆☆☆ | 5.6-dev | 5.6-dev | [Ramon Santamaria](https://github.com/raysan5) |
|
|
||||||
|
|
||||||
Some example missing? As always, contributions are welcome, feel free to send new examples!
|
Some example missing? As always, contributions are welcome, feel free to send new examples!
|
||||||
Here is an [examples template](examples_template.c) with instructions to start with!
|
Here is an [examples template](examples_template.c) with instructions to start with!
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ int main(void)
|
||||||
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
|
DrawText("LEFT-RIGHT for PAN CONTROL", 320, 74, 10, DARKBLUE);
|
||||||
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
|
DrawRectangle(300, 100, 200, 12, LIGHTGRAY);
|
||||||
DrawRectangleLines(300, 100, 200, 12, GRAY);
|
DrawRectangleLines(300, 100, 200, 12, GRAY);
|
||||||
DrawRectangle(300 + (pan + 1.0)/2.0f*200 - 5, 92, 10, 28, DARKGRAY);
|
DrawRectangle((int)(300 + (pan + 1.0f)/2.0f*200 - 5), 92, 10, 28, DARKGRAY);
|
||||||
|
|
||||||
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
|
DrawRectangle(200, 200, 400, 12, LIGHTGRAY);
|
||||||
DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON);
|
DrawRectangle(200, 200, (int)(timePlayed*400.0f), 12, MAROON);
|
||||||
|
|
@ -125,7 +125,7 @@ int main(void)
|
||||||
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
|
DrawText("UP-DOWN for VOLUME CONTROL", 320, 334, 10, DARKGREEN);
|
||||||
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
|
DrawRectangle(300, 360, 200, 12, LIGHTGRAY);
|
||||||
DrawRectangleLines(300, 360, 200, 12, GRAY);
|
DrawRectangleLines(300, 360, 200, 12, GRAY);
|
||||||
DrawRectangle(300 + volume*200 - 5, 352, 10, 28, DARKGRAY);
|
DrawRectangle((int)(300 + volume*200 - 5), 352, 10, 28, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ int main(void)
|
||||||
.z = 5.0f*sinf(th)
|
.z = 5.0f*sinf(th)
|
||||||
};
|
};
|
||||||
|
|
||||||
SetSoundPosition(camera, sound, spherePos, 20.0f);
|
SetSoundPosition(camera, sound, spherePos, 1.0f);
|
||||||
|
|
||||||
if (!IsSoundPlaying(sound)) PlaySound(sound);
|
if (!IsSoundPlaying(sound)) PlaySound(sound);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ int main(void)
|
||||||
.tapbackPos = 0.01f
|
.tapbackPos = 0.01f
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t wavCursor = 0;
|
int wavCursor = 0;
|
||||||
const short *wavPCM16 = wav.data;
|
const short *wavPCM16 = wav.data;
|
||||||
|
|
||||||
short chunkSamples[AUDIO_STREAM_RING_BUFFER_SIZE] = { 0 };
|
short chunkSamples[AUDIO_STREAM_RING_BUFFER_SIZE] = { 0 };
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -148,10 +148,11 @@ int main(void)
|
||||||
DrawText("Controls:", 20, 20, 10, BLACK);
|
DrawText("Controls:", 20, 20, 10, BLACK);
|
||||||
DrawText("- Right/Left to move", 40, 40, 10, DARKGRAY);
|
DrawText("- Right/Left to move", 40, 40, 10, DARKGRAY);
|
||||||
DrawText("- Space to jump", 40, 60, 10, DARKGRAY);
|
DrawText("- Space to jump", 40, 60, 10, DARKGRAY);
|
||||||
DrawText("- Mouse Wheel to Zoom in-out, R to reset zoom", 40, 80, 10, DARKGRAY);
|
DrawText("- Mouse Wheel to Zoom in-out", 40, 80, 10, DARKGRAY);
|
||||||
DrawText("- C to change camera mode", 40, 100, 10, DARKGRAY);
|
DrawText("- R to reset position + zoom", 40, 100, 10, DARKGRAY);
|
||||||
DrawText("Current camera mode:", 20, 120, 10, BLACK);
|
DrawText("- C to change camera mode", 40, 120, 10, DARKGRAY);
|
||||||
DrawText(cameraDescriptions[cameraOption], 40, 140, 10, DARKGRAY);
|
DrawText("Current camera mode:", 20, 140, 10, BLACK);
|
||||||
|
DrawText(cameraDescriptions[cameraOption], 40, 160, 10, DARKGRAY);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -226,10 +227,10 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
|
||||||
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
|
||||||
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, *camera);
|
||||||
|
|
||||||
if (max.x < width) camera->offset.x = width - (max.x - width/2);
|
if (max.x < width) camera->offset.x = width - (max.x - (float)width/2);
|
||||||
if (max.y < height) camera->offset.y = height - (max.y - height/2);
|
if (max.y < height) camera->offset.y = height - (max.y - (float)height/2);
|
||||||
if (min.x > 0) camera->offset.x = width/2 - min.x;
|
if (min.x > 0) camera->offset.x = (float)width/2 - min.x;
|
||||||
if (min.y > 0) camera->offset.y = height/2 - min.y;
|
if (min.y > 0) camera->offset.y = (float)height/2 - min.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *envItems, int envItemsLength, float delta, int width, int height)
|
||||||
|
|
|
||||||
|
|
@ -225,10 +225,10 @@ int main(void)
|
||||||
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, camera);
|
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, camera);
|
||||||
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, camera);
|
Vector2 min = GetWorldToScreen2D((Vector2){ minX, minY }, camera);
|
||||||
|
|
||||||
if (max.x < screenWidth) camera.offset.x = screenWidth - (max.x - screenWidth/2);
|
if (max.x < screenWidth) camera.offset.x = screenWidth - (max.x - (float)screenWidth/2);
|
||||||
if (max.y < screenHeight) camera.offset.y = screenHeight - (max.y - screenHeight/2);
|
if (max.y < screenHeight) camera.offset.y = screenHeight - (max.y - (float)screenHeight/2);
|
||||||
if (min.x > 0) camera.offset.x = screenWidth/2 - min.x;
|
if (min.x > 0) camera.offset.x = (float)screenWidth/2 - min.x;
|
||||||
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
|
if (min.y > 0) camera.offset.y = (float)screenHeight/2 - min.y;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Events management
|
// Events management
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,18 @@ int main(void)
|
||||||
char directory[MAX_FILEPATH_SIZE] = { 0 };
|
char directory[MAX_FILEPATH_SIZE] = { 0 };
|
||||||
strcpy(directory, GetWorkingDirectory());
|
strcpy(directory, GetWorkingDirectory());
|
||||||
|
|
||||||
FilePathList files = LoadDirectoryFiles(directory);
|
// Load file-paths on current working directory
|
||||||
|
// NOTE: LoadDirectoryFiles() loads files and directories by default,
|
||||||
|
// use LoadDirectoryFilesEx() for custom filters and recursive directories loading
|
||||||
|
//FilePathList files = LoadDirectoryFiles(directory);
|
||||||
|
FilePathList files = LoadDirectoryFilesEx(directory, ".png;.c", false);
|
||||||
|
|
||||||
int btnBackPressed = false;
|
int btnBackPressed = false;
|
||||||
|
|
||||||
|
int listScrollIndex = 0;
|
||||||
|
int listItemActive = -1;
|
||||||
|
int listItemFocused = -1;
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -62,28 +70,16 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText(directory, 100, 40, 20, DARKGRAY);
|
btnBackPressed = GuiButton((Rectangle){ 40.0f, 10.0f, 48, 28 }, "<");
|
||||||
|
|
||||||
btnBackPressed = GuiButton((Rectangle){ 40.0f, 38.0f, 48, 24 }, "<");
|
GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetFont().baseSize*2);
|
||||||
|
GuiLabel((Rectangle){ 40 + 48 + 10, 10, 700, 28 }, directory);
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_SIZE, GuiGetFont().baseSize);
|
||||||
|
|
||||||
for (int i = 0; i < (int)files.count; i++)
|
GuiSetStyle(LISTVIEW, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
|
||||||
{
|
GuiSetStyle(LISTVIEW, TEXT_PADDING, 40);
|
||||||
Color color = Fade(LIGHTGRAY, 0.3f);
|
GuiListViewEx((Rectangle){ 0, 50, GetScreenWidth(), GetScreenHeight() - 50 },
|
||||||
|
files.paths, files.count, &listScrollIndex, &listItemActive, &listItemFocused);
|
||||||
if (!IsPathFile(files.paths[i]) && DirectoryExists(files.paths[i]))
|
|
||||||
{
|
|
||||||
if (GuiButton((Rectangle){0.0f, 85.0f + 40.0f*(float)i, screenWidth, 40}, ""))
|
|
||||||
{
|
|
||||||
TextCopy(directory, files.paths[i]);
|
|
||||||
UnloadDirectoryFiles(files);
|
|
||||||
files = LoadDirectoryFiles(directory);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawRectangle(0, 85 + 40*i, screenWidth, 40, color);
|
|
||||||
DrawText(GetFileName(files.paths[i]), 120, 100 + 40*i, 10, GRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,13 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
|
||||||
|
|
||||||
Vector2 scaleDpi = GetWindowScaleDPI();
|
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||||
Vector2 mousePos = GetMousePosition();
|
Vector2 mousePos = GetMousePosition();
|
||||||
int currentMonitor = GetCurrentMonitor();
|
int currentMonitor = GetCurrentMonitor();
|
||||||
|
Vector2 windowPos = GetWindowPosition();
|
||||||
|
|
||||||
int gridSpacing = 40; // Grid spacing in pixels
|
int gridSpacing = 40; // Grid spacing in pixels
|
||||||
|
|
||||||
|
|
@ -47,8 +48,10 @@ int main(void)
|
||||||
mousePos = GetMousePosition();
|
mousePos = GetMousePosition();
|
||||||
currentMonitor = GetCurrentMonitor();
|
currentMonitor = GetCurrentMonitor();
|
||||||
scaleDpi = GetWindowScaleDPI();
|
scaleDpi = GetWindowScaleDPI();
|
||||||
|
windowPos = GetWindowPosition();
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE)) ToggleBorderlessWindowed();
|
if (IsKeyPressed(KEY_SPACE)) ToggleBorderlessWindowed();
|
||||||
|
if (IsKeyPressed(KEY_F)) ToggleFullscreen();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -58,12 +61,12 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Draw grid
|
// Draw grid
|
||||||
for (int h = 0; h < 20; h++)
|
for (int h = 0; h < GetScreenHeight()/gridSpacing + 1; h++)
|
||||||
{
|
{
|
||||||
DrawText(TextFormat("%02i", h*gridSpacing), 4, h*gridSpacing - 4, 10, GRAY);
|
DrawText(TextFormat("%02i", h*gridSpacing), 4, h*gridSpacing - 4, 10, GRAY);
|
||||||
DrawLine(24, h*gridSpacing, GetScreenWidth(), h*gridSpacing, LIGHTGRAY);
|
DrawLine(24, h*gridSpacing, GetScreenWidth(), h*gridSpacing, LIGHTGRAY);
|
||||||
}
|
}
|
||||||
for (int v = 0; v < 40; v++)
|
for (int v = 0; v < GetScreenWidth()/gridSpacing + 1; v++)
|
||||||
{
|
{
|
||||||
DrawText(TextFormat("%02i", v*gridSpacing), v*gridSpacing - 10, 4, 10, GRAY);
|
DrawText(TextFormat("%02i", v*gridSpacing), v*gridSpacing - 10, 4, 10, GRAY);
|
||||||
DrawLine(v*gridSpacing, 20, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
|
DrawLine(v*gridSpacing, 20, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
|
||||||
|
|
@ -72,9 +75,14 @@ int main(void)
|
||||||
// Draw UI info
|
// Draw UI info
|
||||||
DrawText(TextFormat("CURRENT MONITOR: %i/%i (%ix%i)", currentMonitor + 1, GetMonitorCount(),
|
DrawText(TextFormat("CURRENT MONITOR: %i/%i (%ix%i)", currentMonitor + 1, GetMonitorCount(),
|
||||||
GetMonitorWidth(currentMonitor), GetMonitorHeight(currentMonitor)), 50, 50, 20, DARKGRAY);
|
GetMonitorWidth(currentMonitor), GetMonitorHeight(currentMonitor)), 50, 50, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 90, 20, DARKGRAY);
|
DrawText(TextFormat("WINDOW POSITION: %ix%i", (int)windowPos.x, (int)windowPos.y), 50, 90, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 130, 20, DARKGRAY);
|
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 130, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 170, 20, GRAY);
|
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 170, 20, DARKGRAY);
|
||||||
|
DrawText(TextFormat("SCALE FACTOR: %.2fx%.2f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
|
||||||
|
|
||||||
|
// Draw reference rectangles, top-left and bottom-right corners
|
||||||
|
DrawRectangle(0, 0, 30, 60, RED);
|
||||||
|
DrawRectangle(GetScreenWidth() - 30, GetScreenHeight() - 60, 30, 60, BLUE);
|
||||||
|
|
||||||
// Draw mouse position
|
// Draw mouse position
|
||||||
DrawCircleV(GetMousePosition(), 20, MAROON);
|
DrawCircleV(GetMousePosition(), 20, MAROON);
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 18 KiB |
|
|
@ -117,7 +117,7 @@ int main(void)
|
||||||
|
|
||||||
DrawRectangleV(position, size, releaseAction? BLUE : RED);
|
DrawRectangleV(position, size, releaseAction? BLUE : RED);
|
||||||
|
|
||||||
DrawText((actionSet == 0)? "Current input set: WASD (default)" : "Current input set: Cursor", 10, 10, 20, WHITE);
|
DrawText((actionSet == 0)? "Current input set: WASD (default)" : "Current input set: Arrow keys", 10, 10, 20, WHITE);
|
||||||
DrawText("Use TAB key to toggles Actions keyset", 10, 50, 20, GREEN);
|
DrawText("Use TAB key to toggles Actions keyset", 10, 50, 20, GREEN);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
// NOTE: Gamepad name ID depends on drivers and OS
|
// NOTE: Gamepad name ID depends on drivers and OS
|
||||||
#define XBOX_ALIAS_1 "xbox"
|
#define XBOX_ALIAS_1 "xbox"
|
||||||
#define XBOX_ALIAS_2 "x-box"
|
#define XBOX_ALIAS_2 "x-box"
|
||||||
#define PS_ALIAS "playstation"
|
#define PS_ALIAS_1 "playstation"
|
||||||
|
#define PS_ALIAS_2 "sony"
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
|
|
@ -67,7 +68,7 @@ int main(void)
|
||||||
if (IsKeyPressed(KEY_RIGHT)) gamepad++;
|
if (IsKeyPressed(KEY_RIGHT)) gamepad++;
|
||||||
Vector2 mousePosition = GetMousePosition();
|
Vector2 mousePosition = GetMousePosition();
|
||||||
|
|
||||||
vibrateButton = (Rectangle){ 10, 70 + 20*GetGamepadAxisCount(gamepad) + 20, 75, 24 };
|
vibrateButton = (Rectangle){ 10, 70.0f + 20*GetGamepadAxisCount(gamepad) + 20, 75, 24 };
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(mousePosition, vibrateButton)) SetGamepadVibration(gamepad, 1.0, 1.0, 1.0);
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && CheckCollisionPointRec(mousePosition, vibrateButton)) SetGamepadVibration(gamepad, 1.0, 1.0, 1.0);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -148,7 +149,8 @@ int main(void)
|
||||||
//DrawText(TextFormat("Xbox axis LT: %02.02f", GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_TRIGGER)), 10, 40, 10, BLACK);
|
//DrawText(TextFormat("Xbox axis LT: %02.02f", GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_LEFT_TRIGGER)), 10, 40, 10, BLACK);
|
||||||
//DrawText(TextFormat("Xbox axis RT: %02.02f", GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_RIGHT_TRIGGER)), 10, 60, 10, BLACK);
|
//DrawText(TextFormat("Xbox axis RT: %02.02f", GetGamepadAxisMovement(gamepad, GAMEPAD_AXIS_RIGHT_TRIGGER)), 10, 60, 10, BLACK);
|
||||||
}
|
}
|
||||||
else if (TextFindIndex(TextToLower(GetGamepadName(gamepad)), PS_ALIAS) > -1)
|
else if ((TextFindIndex(TextToLower(GetGamepadName(gamepad)), PS_ALIAS_1) > -1) ||
|
||||||
|
(TextFindIndex(TextToLower(GetGamepadName(gamepad)), PS_ALIAS_2) > -1))
|
||||||
{
|
{
|
||||||
DrawTexture(texPs3Pad, 0, 0, DARKGRAY);
|
DrawTexture(texPs3Pad, 0, 0, DARKGRAY);
|
||||||
|
|
||||||
|
|
@ -262,7 +264,7 @@ int main(void)
|
||||||
|
|
||||||
// Draw vibrate button
|
// Draw vibrate button
|
||||||
DrawRectangleRec(vibrateButton, SKYBLUE);
|
DrawRectangleRec(vibrateButton, SKYBLUE);
|
||||||
DrawText("VIBRATE", vibrateButton.x + 14, vibrateButton.y + 1, 10, DARKGRAY);
|
DrawText("VIBRATE", (int)(vibrateButton.x + 14), (int)(vibrateButton.y + 1), 10, DARKGRAY);
|
||||||
|
|
||||||
if (GetGamepadButtonPressed() != GAMEPAD_BUTTON_UNKNOWN) DrawText(TextFormat("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
|
if (GetGamepadButtonPressed() != GAMEPAD_BUTTON_UNKNOWN) DrawText(TextFormat("DETECTED BUTTON: %i", GetGamepadButtonPressed()), 10, 430, 10, RED);
|
||||||
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
|
else DrawText("DETECTED BUTTON: NONE", 10, 430, 10, GRAY);
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,31 @@ int main(void)
|
||||||
{ padPosition.x, padPosition.y + buttonRadius*1.5f } // Down
|
{ padPosition.x, padPosition.y + buttonRadius*1.5f } // Down
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *buttonLabels[BUTTON_MAX] = {
|
Vector2 arrowTris[4][3] = {
|
||||||
"Y", // Up
|
// Up
|
||||||
"X", // Left
|
{
|
||||||
"B", // Right
|
{ buttonPositions[0].x, buttonPositions[0].y - 12 },
|
||||||
"A" // Down
|
{ buttonPositions[0].x - 9, buttonPositions[0].y + 9 },
|
||||||
|
{ buttonPositions[0].x + 9, buttonPositions[0].y + 9 }
|
||||||
|
},
|
||||||
|
// Left
|
||||||
|
{
|
||||||
|
{ buttonPositions[1].x + 9, buttonPositions[1].y - 9 },
|
||||||
|
{ buttonPositions[1].x - 12, buttonPositions[1].y },
|
||||||
|
{ buttonPositions[1].x + 9, buttonPositions[1].y + 9 }
|
||||||
|
},
|
||||||
|
// Right
|
||||||
|
{
|
||||||
|
{ buttonPositions[2].x + 12, buttonPositions[2].y },
|
||||||
|
{ buttonPositions[2].x - 9, buttonPositions[2].y - 9 },
|
||||||
|
{ buttonPositions[2].x - 9, buttonPositions[2].y + 9 }
|
||||||
|
},
|
||||||
|
// Down
|
||||||
|
{
|
||||||
|
{ buttonPositions[3].x - 9, buttonPositions[3].y - 9 },
|
||||||
|
{ buttonPositions[3].x, buttonPositions[3].y + 12 },
|
||||||
|
{ buttonPositions[3].x + 9, buttonPositions[3].y - 9 }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Color buttonLabelColors[BUTTON_MAX] = {
|
Color buttonLabelColors[BUTTON_MAX] = {
|
||||||
|
|
@ -128,9 +148,12 @@ int main(void)
|
||||||
{
|
{
|
||||||
DrawCircleV(buttonPositions[i], buttonRadius, (i == pressedButton)? DARKGRAY : BLACK);
|
DrawCircleV(buttonPositions[i], buttonRadius, (i == pressedButton)? DARKGRAY : BLACK);
|
||||||
|
|
||||||
DrawText(buttonLabels[i],
|
DrawTriangle(
|
||||||
(int)buttonPositions[i].x - 7, (int)buttonPositions[i].y - 8,
|
arrowTris[i][0],
|
||||||
20, buttonLabelColors[i]);
|
arrowTris[i][1],
|
||||||
|
arrowTris[i][2],
|
||||||
|
buttonLabelColors[i]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("move the player with D-Pad buttons", 10, 10, 20, DARKGRAY);
|
DrawText("move the player with D-Pad buttons", 10, 10, 20, DARKGRAY);
|
||||||
|
|
|
||||||
333
examples/core/core_keyboard_testbed.c
Normal file
|
|
@ -0,0 +1,333 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - keyboard testbed
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
|
*
|
||||||
|
* NOTE: raylib defined keys refer to ENG-US Keyboard layout,
|
||||||
|
* mapping to other layouts is up to the user
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.6, last time updated with raylib 5.6
|
||||||
|
*
|
||||||
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
* BSD-like license that allows static linking with closed source software
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define KEY_REC_SPACING 4 // Space in pixels between key rectangles
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static const char *GetKeyText(int key);
|
||||||
|
static void GuiKeyboardKey(Rectangle bounds, int key);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard testbed");
|
||||||
|
SetExitKey(KEY_NULL); // Avoid exit on KEY_ESCAPE
|
||||||
|
|
||||||
|
// Keyboard line 01
|
||||||
|
int line01KeyWidths[15] = { 0 };
|
||||||
|
for (int i = 0; i < 15; i++) line01KeyWidths[i] = 45;
|
||||||
|
line01KeyWidths[13] = 62; // PRINTSCREEN
|
||||||
|
int line01Keys[15] = {
|
||||||
|
KEY_ESCAPE, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5,
|
||||||
|
KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, KEY_F11,
|
||||||
|
KEY_F12, KEY_PRINT_SCREEN, KEY_PAUSE
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keyboard line 02
|
||||||
|
int line02KeyWidths[15] = { 0 };
|
||||||
|
for (int i = 0; i < 15; i++) line02KeyWidths[i] = 45;
|
||||||
|
line02KeyWidths[0] = 25; // GRAVE
|
||||||
|
line02KeyWidths[13] = 82; // BACKSPACE
|
||||||
|
int line02Keys[15] = {
|
||||||
|
KEY_GRAVE, KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR,
|
||||||
|
KEY_FIVE, KEY_SIX, KEY_SEVEN, KEY_EIGHT, KEY_NINE,
|
||||||
|
KEY_ZERO, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, KEY_DELETE };
|
||||||
|
|
||||||
|
// Keyboard line 03
|
||||||
|
int line03KeyWidths[15] = { 0 };
|
||||||
|
for (int i = 0; i < 15; i++) line03KeyWidths[i] = 45;
|
||||||
|
line03KeyWidths[0] = 50; // TAB
|
||||||
|
line03KeyWidths[13] = 57; // BACKSLASH
|
||||||
|
int line03Keys[15] = {
|
||||||
|
KEY_TAB, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y,
|
||||||
|
KEY_U, KEY_I, KEY_O, KEY_P, KEY_LEFT_BRACKET,
|
||||||
|
KEY_RIGHT_BRACKET, KEY_BACKSLASH, KEY_INSERT
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keyboard line 04
|
||||||
|
int line04KeyWidths[14] = { 0 };
|
||||||
|
for (int i = 0; i < 14; i++) line04KeyWidths[i] = 45;
|
||||||
|
line04KeyWidths[0] = 68; // CAPS
|
||||||
|
line04KeyWidths[12] = 88; // ENTER
|
||||||
|
int line04Keys[14] = {
|
||||||
|
KEY_CAPS_LOCK, KEY_A, KEY_S, KEY_D, KEY_F, KEY_G,
|
||||||
|
KEY_H, KEY_J, KEY_K, KEY_L, KEY_SEMICOLON,
|
||||||
|
KEY_APOSTROPHE, KEY_ENTER, KEY_PAGE_UP
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keyboard line 05
|
||||||
|
int line05KeyWidths[14] = { 0 };
|
||||||
|
for (int i = 0; i < 14; i++) line05KeyWidths[i] = 45;
|
||||||
|
line05KeyWidths[0] = 80; // LSHIFT
|
||||||
|
line05KeyWidths[11] = 76; // RSHIFT
|
||||||
|
int line05Keys[14] = {
|
||||||
|
KEY_LEFT_SHIFT, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B,
|
||||||
|
KEY_N, KEY_M, KEY_COMMA, KEY_PERIOD, /*KEY_MINUS*/
|
||||||
|
KEY_SLASH, KEY_RIGHT_SHIFT, KEY_UP, KEY_PAGE_DOWN
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keyboard line 06
|
||||||
|
int line06KeyWidths[11] = { 0 };
|
||||||
|
for (int i = 0; i < 11; i++) line06KeyWidths[i] = 45;
|
||||||
|
line06KeyWidths[0] = 80; // LCTRL
|
||||||
|
line06KeyWidths[3] = 208; // SPACE
|
||||||
|
line06KeyWidths[7] = 60; // RCTRL
|
||||||
|
int line06Keys[11] = {
|
||||||
|
KEY_LEFT_CONTROL, KEY_LEFT_SUPER, KEY_LEFT_ALT,
|
||||||
|
KEY_SPACE, KEY_RIGHT_ALT, 162, KEY_NULL,
|
||||||
|
KEY_RIGHT_CONTROL, KEY_LEFT, KEY_DOWN, KEY_RIGHT
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector2 keyboardOffset = { 26, 80 };
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
int key = GetKeyPressed(); // Get pressed keycode
|
||||||
|
if (key > 0) TraceLog(LOG_INFO, "KEYBOARD TESTBED: KEY PRESSED: %d", key);
|
||||||
|
|
||||||
|
int ch = GetCharPressed(); // Get pressed char for text input, using OS mapping
|
||||||
|
if (ch > 0) TraceLog(LOG_INFO, "KEYBOARD TESTBED: CHAR PRESSED: %c (%d)", ch, ch);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("KEYBOARD LAYOUT: ENG-US", 26, 38, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
// Keyboard line 01 - 15 keys
|
||||||
|
// ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, IMP, CLOSE
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y, line01KeyWidths[i], 30 }, line01Keys[i]);
|
||||||
|
recOffsetX += line01KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard line 02 - 15 keys
|
||||||
|
// `, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -, =, BACKSPACE, DEL
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + KEY_REC_SPACING, line02KeyWidths[i], 38 }, line02Keys[i]);
|
||||||
|
recOffsetX += line02KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard line 03 - 15 keys
|
||||||
|
// TAB, Q, W, E, R, T, Y, U, I, O, P, [, ], \, INS
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38 + KEY_REC_SPACING*2, line03KeyWidths[i], 38 }, line03Keys[i]);
|
||||||
|
recOffsetX += line03KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard line 04 - 14 keys
|
||||||
|
// MAYUS, A, S, D, F, G, H, J, K, L, ;, ', ENTER, REPAG
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 14; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*2 + KEY_REC_SPACING*3, line04KeyWidths[i], 38 }, line04Keys[i]);
|
||||||
|
recOffsetX += line04KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard line 05 - 14 keys
|
||||||
|
// LSHIFT, Z, X, C, V, B, N, M, ,, ., /, RSHIFT, UP, AVPAG
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 14; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*3 + KEY_REC_SPACING*4, line05KeyWidths[i], 38 }, line05Keys[i]);
|
||||||
|
recOffsetX += line05KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard line 06 - 11 keys
|
||||||
|
// LCTRL, WIN, LALT, SPACE, ALTGR, \, FN, RCTRL, LEFT, DOWN, RIGHT
|
||||||
|
for (int i = 0, recOffsetX = 0; i < 11; i++)
|
||||||
|
{
|
||||||
|
GuiKeyboardKey((Rectangle){ keyboardOffset.x + recOffsetX, keyboardOffset.y + 30 + 38*4 + KEY_REC_SPACING*5, line06KeyWidths[i], 38 }, line06Keys[i]);
|
||||||
|
recOffsetX += line06KeyWidths[i] + KEY_REC_SPACING;
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Get keyboard keycode as text (US keyboard)
|
||||||
|
// NOTE: Mapping for other keyboard layouts can be done here
|
||||||
|
static const char *GetKeyText(int key)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case KEY_APOSTROPHE : return "'"; // Key: '
|
||||||
|
case KEY_COMMA : return ","; // Key: ,
|
||||||
|
case KEY_MINUS : return "-"; // Key: -
|
||||||
|
case KEY_PERIOD : return "."; // Key: .
|
||||||
|
case KEY_SLASH : return "/"; // Key: /
|
||||||
|
case KEY_ZERO : return "0"; // Key: 0
|
||||||
|
case KEY_ONE : return "1"; // Key: 1
|
||||||
|
case KEY_TWO : return "2"; // Key: 2
|
||||||
|
case KEY_THREE : return "3"; // Key: 3
|
||||||
|
case KEY_FOUR : return "4"; // Key: 4
|
||||||
|
case KEY_FIVE : return "5"; // Key: 5
|
||||||
|
case KEY_SIX : return "6"; // Key: 6
|
||||||
|
case KEY_SEVEN : return "7"; // Key: 7
|
||||||
|
case KEY_EIGHT : return "8"; // Key: 8
|
||||||
|
case KEY_NINE : return "9"; // Key: 9
|
||||||
|
case KEY_SEMICOLON : return ";"; // Key: ;
|
||||||
|
case KEY_EQUAL : return "="; // Key: =
|
||||||
|
case KEY_A : return "A"; // Key: A | a
|
||||||
|
case KEY_B : return "B"; // Key: B | b
|
||||||
|
case KEY_C : return "C"; // Key: C | c
|
||||||
|
case KEY_D : return "D"; // Key: D | d
|
||||||
|
case KEY_E : return "E"; // Key: E | e
|
||||||
|
case KEY_F : return "F"; // Key: F | f
|
||||||
|
case KEY_G : return "G"; // Key: G | g
|
||||||
|
case KEY_H : return "H"; // Key: H | h
|
||||||
|
case KEY_I : return "I"; // Key: I | i
|
||||||
|
case KEY_J : return "J"; // Key: J | j
|
||||||
|
case KEY_K : return "K"; // Key: K | k
|
||||||
|
case KEY_L : return "L"; // Key: L | l
|
||||||
|
case KEY_M : return "M"; // Key: M | m
|
||||||
|
case KEY_N : return "N"; // Key: N | n
|
||||||
|
case KEY_O : return "O"; // Key: O | o
|
||||||
|
case KEY_P : return "P"; // Key: P | p
|
||||||
|
case KEY_Q : return "Q"; // Key: Q | q
|
||||||
|
case KEY_R : return "R"; // Key: R | r
|
||||||
|
case KEY_S : return "S"; // Key: S | s
|
||||||
|
case KEY_T : return "T"; // Key: T | t
|
||||||
|
case KEY_U : return "U"; // Key: U | u
|
||||||
|
case KEY_V : return "V"; // Key: V | v
|
||||||
|
case KEY_W : return "W"; // Key: W | w
|
||||||
|
case KEY_X : return "X"; // Key: X | x
|
||||||
|
case KEY_Y : return "Y"; // Key: Y | y
|
||||||
|
case KEY_Z : return "Z"; // Key: Z | z
|
||||||
|
case KEY_LEFT_BRACKET : return "["; // Key: [
|
||||||
|
case KEY_BACKSLASH : return "\\"; // Key: '\'
|
||||||
|
case KEY_RIGHT_BRACKET : return "]"; // Key: ]
|
||||||
|
case KEY_GRAVE : return "`"; // Key: `
|
||||||
|
case KEY_SPACE : return "SPACE"; // Key: Space
|
||||||
|
case KEY_ESCAPE : return "ESC"; // Key: Esc
|
||||||
|
case KEY_ENTER : return "ENTER"; // Key: Enter
|
||||||
|
case KEY_TAB : return "TAB"; // Key: Tab
|
||||||
|
case KEY_BACKSPACE : return "BACK"; // Key: Backspace
|
||||||
|
case KEY_INSERT : return "INS"; // Key: Ins
|
||||||
|
case KEY_DELETE : return "DEL"; // Key: Del
|
||||||
|
case KEY_RIGHT : return "RIGHT"; // Key: Cursor right
|
||||||
|
case KEY_LEFT : return "LEFT"; // Key: Cursor left
|
||||||
|
case KEY_DOWN : return "DOWN"; // Key: Cursor down
|
||||||
|
case KEY_UP : return "UP"; // Key: Cursor up
|
||||||
|
case KEY_PAGE_UP : return "PGUP"; // Key: Page up
|
||||||
|
case KEY_PAGE_DOWN : return "PGDOWN"; // Key: Page down
|
||||||
|
case KEY_HOME : return "HOME"; // Key: Home
|
||||||
|
case KEY_END : return "END"; // Key: End
|
||||||
|
case KEY_CAPS_LOCK : return "CAPS"; // Key: Caps lock
|
||||||
|
case KEY_SCROLL_LOCK : return "LOCK"; // Key: Scroll down
|
||||||
|
case KEY_NUM_LOCK : return "NUMLOCK"; // Key: Num lock
|
||||||
|
case KEY_PRINT_SCREEN : return "PRINTSCR"; // Key: Print screen
|
||||||
|
case KEY_PAUSE : return "PAUSE"; // Key: Pause
|
||||||
|
case KEY_F1 : return "F1"; // Key: F1
|
||||||
|
case KEY_F2 : return "F2"; // Key: F2
|
||||||
|
case KEY_F3 : return "F3"; // Key: F3
|
||||||
|
case KEY_F4 : return "F4"; // Key: F4
|
||||||
|
case KEY_F5 : return "F5"; // Key: F5
|
||||||
|
case KEY_F6 : return "F6"; // Key: F6
|
||||||
|
case KEY_F7 : return "F7"; // Key: F7
|
||||||
|
case KEY_F8 : return "F8"; // Key: F8
|
||||||
|
case KEY_F9 : return "F9"; // Key: F9
|
||||||
|
case KEY_F10 : return "F10"; // Key: F10
|
||||||
|
case KEY_F11 : return "F11"; // Key: F11
|
||||||
|
case KEY_F12 : return "F12"; // Key: F12
|
||||||
|
case KEY_LEFT_SHIFT : return "LSHIFT"; // Key: Shift left
|
||||||
|
case KEY_LEFT_CONTROL : return "LCTRL"; // Key: Control left
|
||||||
|
case KEY_LEFT_ALT : return "LALT"; // Key: Alt left
|
||||||
|
case KEY_LEFT_SUPER : return "WIN"; // Key: Super left
|
||||||
|
case KEY_RIGHT_SHIFT : return "RSHIFT"; // Key: Shift right
|
||||||
|
case KEY_RIGHT_CONTROL : return "RCTRL"; // Key: Control right
|
||||||
|
case KEY_RIGHT_ALT : return "ALTGR"; // Key: Alt right
|
||||||
|
case KEY_RIGHT_SUPER : return "RSUPER"; // Key: Super right
|
||||||
|
case KEY_KB_MENU : return "KBMENU"; // Key: KB menu
|
||||||
|
case KEY_KP_0 : return "KP0"; // Key: Keypad 0
|
||||||
|
case KEY_KP_1 : return "KP1"; // Key: Keypad 1
|
||||||
|
case KEY_KP_2 : return "KP2"; // Key: Keypad 2
|
||||||
|
case KEY_KP_3 : return "KP3"; // Key: Keypad 3
|
||||||
|
case KEY_KP_4 : return "KP4"; // Key: Keypad 4
|
||||||
|
case KEY_KP_5 : return "KP5"; // Key: Keypad 5
|
||||||
|
case KEY_KP_6 : return "KP6"; // Key: Keypad 6
|
||||||
|
case KEY_KP_7 : return "KP7"; // Key: Keypad 7
|
||||||
|
case KEY_KP_8 : return "KP8"; // Key: Keypad 8
|
||||||
|
case KEY_KP_9 : return "KP9"; // Key: Keypad 9
|
||||||
|
case KEY_KP_DECIMAL : return "KPDEC"; // Key: Keypad .
|
||||||
|
case KEY_KP_DIVIDE : return "KPDIV"; // Key: Keypad /
|
||||||
|
case KEY_KP_MULTIPLY : return "KPMUL"; // Key: Keypad *
|
||||||
|
case KEY_KP_SUBTRACT : return "KPSUB"; // Key: Keypad -
|
||||||
|
case KEY_KP_ADD : return "KPADD"; // Key: Keypad +
|
||||||
|
case KEY_KP_ENTER : return "KPENTER"; // Key: Keypad Enter
|
||||||
|
case KEY_KP_EQUAL : return "KPEQU"; // Key: Keypad =
|
||||||
|
default: return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw keyboard key
|
||||||
|
static void GuiKeyboardKey(Rectangle bounds, int key)
|
||||||
|
{
|
||||||
|
if (key == KEY_NULL) DrawRectangleLinesEx(bounds, 2.0f, LIGHTGRAY);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (IsKeyDown(key))
|
||||||
|
{
|
||||||
|
DrawRectangleLinesEx(bounds, 2.0f, MAROON);
|
||||||
|
DrawText(GetKeyText(key), bounds.x + 4, bounds.y + 4, 10, MAROON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawRectangleLinesEx(bounds, 2.0f, DARKGRAY);
|
||||||
|
DrawText(GetKeyText(key), bounds.x + 4, bounds.y + 4, 10, DARKGRAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CheckCollisionPointRec(GetMousePosition(), bounds))
|
||||||
|
{
|
||||||
|
DrawRectangleRec(bounds, Fade(RED, 0.2f));
|
||||||
|
DrawRectangleLinesEx(bounds, 3.0f, RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
examples/core/core_keyboard_testbed.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
|
@ -96,8 +96,6 @@ int main(void)
|
||||||
{
|
{
|
||||||
DrawRectangleRec(rectangles[i].rect, rectangles[i].color);
|
DrawRectangleRec(rectangles[i].rect, rectangles[i].color);
|
||||||
|
|
||||||
DrawText("Press SPACE to shuffle the sequence", 10, screenHeight - 96, 20, BLACK);
|
|
||||||
|
|
||||||
DrawText("Press SPACE to shuffle the current sequence", 10, screenHeight - 96, 20, BLACK);
|
DrawText("Press SPACE to shuffle the current sequence", 10, screenHeight - 96, 20, BLACK);
|
||||||
DrawText("Press UP to add a rectangle and generate a new sequence", 10, screenHeight - 64, 20, BLACK);
|
DrawText("Press UP to add a rectangle and generate a new sequence", 10, screenHeight - 64, 20, BLACK);
|
||||||
DrawText("Press DOWN to remove a rectangle and generate a new sequence", 10, screenHeight - 32, 20, BLACK);
|
DrawText("Press DOWN to remove a rectangle and generate a new sequence", 10, screenHeight - 32, 20, BLACK);
|
||||||
|
|
|
||||||
|
|
@ -112,16 +112,16 @@ int main(void)
|
||||||
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed)
|
if (CheckCollisionPointRec(mousePosition, decreaseResolutionButton) && mousePressed)
|
||||||
{
|
{
|
||||||
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1)%RESOLUTION_COUNT;
|
resolutionIndex = (resolutionIndex + RESOLUTION_COUNT - 1)%RESOLUTION_COUNT;
|
||||||
gameWidth = resolutionList[resolutionIndex].x;
|
gameWidth = (int)resolutionList[resolutionIndex].x;
|
||||||
gameHeight = resolutionList[resolutionIndex].y;
|
gameHeight = (int)resolutionList[resolutionIndex].y;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed)
|
if (CheckCollisionPointRec(mousePosition, increaseResolutionButton) && mousePressed)
|
||||||
{
|
{
|
||||||
resolutionIndex = (resolutionIndex + 1)%RESOLUTION_COUNT;
|
resolutionIndex = (resolutionIndex + 1)%RESOLUTION_COUNT;
|
||||||
gameWidth = resolutionList[resolutionIndex].x;
|
gameWidth = (int)resolutionList[resolutionIndex].x;
|
||||||
gameHeight = resolutionList[resolutionIndex].y;
|
gameHeight = (int)resolutionList[resolutionIndex].y;
|
||||||
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
ResizeRenderSize(viewportType, &screenWidth, &screenHeight, gameWidth, gameHeight, &sourceRect, &destRect, &target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +145,7 @@ int main(void)
|
||||||
// Draw our scene to the render texture
|
// Draw our scene to the render texture
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
DrawCircle(textureMousePosition.x, textureMousePosition.y, 20.0f, LIME);
|
DrawCircleV(textureMousePosition, 20.0f, LIME);
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
|
|
||||||
// Draw render texture to main framebuffer
|
// Draw render texture to main framebuffer
|
||||||
|
|
@ -159,7 +159,7 @@ int main(void)
|
||||||
// Draw info box
|
// Draw info box
|
||||||
Rectangle infoRect = (Rectangle){5, 5, 330, 105};
|
Rectangle infoRect = (Rectangle){5, 5, 330, 105};
|
||||||
DrawRectangleRec(infoRect, Fade(LIGHTGRAY, 0.7f));
|
DrawRectangleRec(infoRect, Fade(LIGHTGRAY, 0.7f));
|
||||||
DrawRectangleLines(infoRect.x, infoRect.y, infoRect.width, infoRect.height, BLUE);
|
DrawRectangleLinesEx(infoRect, 1, BLUE);
|
||||||
|
|
||||||
DrawText(TextFormat("Window Resolution: %d x %d", screenWidth, screenHeight), 15, 15, 10, BLACK);
|
DrawText(TextFormat("Window Resolution: %d x %d", screenWidth, screenHeight), 15, 15, 10, BLACK);
|
||||||
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);
|
DrawText(TextFormat("Game Resolution: %d x %d", gameWidth, gameHeight), 15, 30, 10, BLACK);
|
||||||
|
|
@ -216,7 +216,7 @@ static void KeepAspectCenteredInteger(int screenWidth, int screenHeight, int gam
|
||||||
|
|
||||||
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = (float)(screenHeight/gameHeight);
|
const float resizeRatio = (float)screenHeight/gameHeight;
|
||||||
sourceRect->x = 0.0f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.0f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)(int)(screenWidth/resizeRatio);
|
sourceRect->width = (float)(int)(screenWidth/resizeRatio);
|
||||||
|
|
@ -230,7 +230,7 @@ static void KeepHeightCenteredInteger(int screenWidth, int screenHeight, int gam
|
||||||
|
|
||||||
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
static void KeepWidthCenteredInteger(int screenWidth, int screenHeight, int gameWidth, int gameHeight, Rectangle *sourceRect, Rectangle *destRect)
|
||||||
{
|
{
|
||||||
const float resizeRatio = (float)(screenWidth/gameWidth);
|
const float resizeRatio = (float)screenWidth/gameWidth;
|
||||||
sourceRect->x = 0.0f;
|
sourceRect->x = 0.0f;
|
||||||
sourceRect->y = 0.0f;
|
sourceRect->y = 0.0f;
|
||||||
sourceRect->width = (float)gameWidth;
|
sourceRect->width = (float)gameWidth;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [others] example - basic window
|
* raylib [core] example - window web
|
||||||
*
|
|
||||||
* This example has been adapted to compile for PLATFORM_WEB and PLATFORM_DESKTOP
|
|
||||||
* As you will notice, code structure is slightly different to the other examples
|
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 1.3, last time updated with raylib 5.5
|
* Example originally created with raylib 1.3, last time updated with raylib 5.5
|
||||||
*
|
*
|
||||||
|
* This example has been adapted to compile for PLATFORM_WEB and PLATFORM_DESKTOP
|
||||||
|
* As you will notice, code structure is slightly different to the other examples
|
||||||
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
*
|
*
|
||||||
|
|
@ -40,7 +40,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [others] example - web basic window");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - window web");
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||||
|
|
@ -79,7 +79,7 @@ void UpdateDrawFrame(void)
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
DrawText("Welcome to raylib web structure!", 220, 200, 20, SKYBLUE);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BIN
examples/core/core_window_web.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
|
|
@ -413,7 +413,7 @@ static MsfGifBuffer * msf_compress_frame(void * allocContext, int width, int hei
|
||||||
|
|
||||||
//generate palette
|
//generate palette
|
||||||
typedef struct { uint8_t r, g, b; } Color3;
|
typedef struct { uint8_t r, g, b; } Color3;
|
||||||
Color3 table[256] = { {0} };
|
Color3 table[256] = { { 0 } };
|
||||||
int tableIdx = 1; //we start counting at 1 because 0 is the transparent color
|
int tableIdx = 1; //we start counting at 1 because 0 is the transparent color
|
||||||
//transparent is always last in the table
|
//transparent is always last in the table
|
||||||
tlb[tlbSize-1] = 0;
|
tlb[tlbSize-1] = 0;
|
||||||
|
|
@ -550,7 +550,7 @@ static void msf_free_gif_state(MsfGifState * handle) {
|
||||||
|
|
||||||
int msf_gif_begin(MsfGifState * handle, int width, int height) { MsfTimeFunc
|
int msf_gif_begin(MsfGifState * handle, int width, int height) { MsfTimeFunc
|
||||||
//NOTE: we cannot stomp the entire struct to zero because we must preserve `customAllocatorContext`.
|
//NOTE: we cannot stomp the entire struct to zero because we must preserve `customAllocatorContext`.
|
||||||
MsfCookedFrame empty = {0}; //god I hate MSVC...
|
MsfCookedFrame empty = { 0 }; //god I hate MSVC...
|
||||||
handle->previousFrame = empty;
|
handle->previousFrame = empty;
|
||||||
handle->currentFrame = empty;
|
handle->currentFrame = empty;
|
||||||
handle->width = width;
|
handle->width = width;
|
||||||
|
|
@ -614,7 +614,7 @@ int msf_gif_frame(MsfGifState * handle, uint8_t * pixelData, int centiSecondsPer
|
||||||
}
|
}
|
||||||
|
|
||||||
MsfGifResult msf_gif_end(MsfGifState * handle) { MsfTimeFunc
|
MsfGifResult msf_gif_end(MsfGifState * handle) { MsfTimeFunc
|
||||||
if (!handle->listHead) { MsfGifResult empty = {0}; return empty; }
|
if (!handle->listHead) { MsfGifResult empty = { 0 }; return empty; }
|
||||||
|
|
||||||
//first pass: determine total size
|
//first pass: determine total size
|
||||||
size_t total = 1; //1 byte for trailing marker
|
size_t total = 1; //1 byte for trailing marker
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
#
|
#
|
||||||
# raylib examples list used to generate/update collection
|
# raylib examples list with available .c example files
|
||||||
# examples must be provided as: <example_category>;<example_name>;<example_stars>;<raylib_created_version>;<raylib_last_update_version>;<year_created>;<year_reviewed>;"<example_author_name>";<author_github_user>
|
#
|
||||||
|
# WARNING: List is not ordered by example name but by the display order on web,
|
||||||
|
# so it can not be automatically generated scanning available .c code files, only updated
|
||||||
|
# new examples are added at the end of each category; it's up to the user to reorder them as desired
|
||||||
|
#
|
||||||
|
# examples data is listed as: <example_category>;<example_name>;<example_stars>;<raylib_created_version>;<raylib_last_update_version>;<year_created>;<year_reviewed>;"<example_author_name>";<author_github_user>
|
||||||
#
|
#
|
||||||
# This list is used as the main reference by [rexm] tool for examples collection validation and management
|
# This list is used as the main reference by [rexm] tool for examples collection validation and management
|
||||||
# New examples must be added to this list and any possible rename must be made on this list first
|
|
||||||
#
|
|
||||||
# WARNING: List is not ordered by example name but by the display order on web
|
|
||||||
#
|
#
|
||||||
core;core_basic_window;★☆☆☆;1.0;1.0;2013;2025;"Ramon Santamaria";@raysan5
|
core;core_basic_window;★☆☆☆;1.0;1.0;2013;2025;"Ramon Santamaria";@raysan5
|
||||||
core;core_delta_time;★☆☆☆;5.5;5.6-dev;2025;2025;"Robin";@RobinsAviary
|
core;core_delta_time;★☆☆☆;5.5;5.6-dev;2025;2025;"Robin";@RobinsAviary
|
||||||
|
|
@ -54,6 +56,8 @@ core;core_screen_recording;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santama
|
||||||
core;core_clipboard_text;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ananth S";@Ananth1839
|
core;core_clipboard_text;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ananth S";@Ananth1839
|
||||||
core;core_text_file_loading;★☆☆☆;5.5;5.6;0;0;"Aanjishnu Bhattacharyya";@NimComPoo-04
|
core;core_text_file_loading;★☆☆☆;5.5;5.6;0;0;"Aanjishnu Bhattacharyya";@NimComPoo-04
|
||||||
core;core_compute_hash;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
|
core;core_compute_hash;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Ramon Santamaria";@raysan5
|
||||||
|
core;core_keyboard_testbed;★★☆☆;5.6;5.6;2026;2026;"Ramon Santamaria";@raysan5
|
||||||
|
core;core_window_web;★☆☆☆;1.3;5.5;2015;2025;"Ramon Santamaria";@raysan5
|
||||||
shapes;shapes_basic_shapes;★☆☆☆;1.0;4.2;2014;2025;"Ramon Santamaria";@raysan5
|
shapes;shapes_basic_shapes;★☆☆☆;1.0;4.2;2014;2025;"Ramon Santamaria";@raysan5
|
||||||
shapes;shapes_bouncing_ball;★☆☆☆;2.5;2.5;2013;2025;"Ramon Santamaria";@raysan5
|
shapes;shapes_bouncing_ball;★☆☆☆;2.5;2.5;2013;2025;"Ramon Santamaria";@raysan5
|
||||||
shapes;shapes_bullet_hell;★☆☆☆;5.6;5.6;2025;2025;"Zero";@zerohorsepower
|
shapes;shapes_bullet_hell;★☆☆☆;5.6;5.6;2025;2025;"Zero";@zerohorsepower
|
||||||
|
|
@ -92,6 +96,8 @@ shapes;shapes_rlgl_color_wheel;★★★☆;5.6-dev;5.6-dev;2025;2025;"Robin";@R
|
||||||
shapes;shapes_rlgl_triangle;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Robin";@RobinsAviary
|
shapes;shapes_rlgl_triangle;★★☆☆;5.6-dev;5.6-dev;2025;2025;"Robin";@RobinsAviary
|
||||||
shapes;shapes_ball_physics;★★☆☆;5.6-dev;5.6-dev;2025;2025;"David Buzatto";@davidbuzatto
|
shapes;shapes_ball_physics;★★☆☆;5.6-dev;5.6-dev;2025;2025;"David Buzatto";@davidbuzatto
|
||||||
shapes;shapes_penrose_tile;★★★★;5.5;5.6-dev;2025;2025;"David Buzatto";@davidbuzatto
|
shapes;shapes_penrose_tile;★★★★;5.5;5.6-dev;2025;2025;"David Buzatto";@davidbuzatto
|
||||||
|
shapes;shapes_hilbert_curve;★★★☆;5.6;5.6;2025;2025;"Hamza RAHAL";@hmz-rhl
|
||||||
|
shapes;shapes_easings_testbed;★★★☆;2.5;2.5;2019;2025;"Juan Miguel López";@flashback-fx
|
||||||
textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
textures;textures_logo_raylib;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
||||||
textures;textures_srcrec_dstrec;★★★☆;1.3;1.3;2015;2025;"Ramon Santamaria";@raysan5
|
textures;textures_srcrec_dstrec;★★★☆;1.3;1.3;2015;2025;"Ramon Santamaria";@raysan5
|
||||||
textures;textures_image_drawing;★★☆☆;1.4;1.4;2016;2025;"Ramon Santamaria";@raysan5
|
textures;textures_image_drawing;★★☆☆;1.4;1.4;2016;2025;"Ramon Santamaria";@raysan5
|
||||||
|
|
@ -121,6 +127,7 @@ textures;textures_screen_buffer;★★☆☆;5.5;5.5;2025;2025;"Agnis Aldiņš";
|
||||||
textures;textures_textured_curve;★★★☆;4.5;4.5;2022;2025;"Jeffery Myers";@JeffM2501
|
textures;textures_textured_curve;★★★☆;4.5;4.5;2022;2025;"Jeffery Myers";@JeffM2501
|
||||||
textures;textures_sprite_stacking;★★☆☆;5.6-dev;6.0;2025;2025;"Robin";@RobinsAviary
|
textures;textures_sprite_stacking;★★☆☆;5.6-dev;6.0;2025;2025;"Robin";@RobinsAviary
|
||||||
textures;textures_cellular_automata;★★☆☆;5.6;5.6;2025;2025;"Jordi Santonja";@JordSant
|
textures;textures_cellular_automata;★★☆☆;5.6;5.6;2025;2025;"Jordi Santonja";@JordSant
|
||||||
|
textures;textures_framebuffer_rendering;★★☆☆;5.6;5.6;2026;2026;"Jack Boakes";@jackboakes
|
||||||
text;text_sprite_fonts;★☆☆☆;1.7;3.7;2017;2025;"Ramon Santamaria";@raysan5
|
text;text_sprite_fonts;★☆☆☆;1.7;3.7;2017;2025;"Ramon Santamaria";@raysan5
|
||||||
text;text_font_spritefont;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
text;text_font_spritefont;★☆☆☆;1.0;1.0;2014;2025;"Ramon Santamaria";@raysan5
|
||||||
text;text_font_filters;★★☆☆;1.3;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
text;text_font_filters;★★☆☆;1.3;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
||||||
|
|
@ -164,6 +171,8 @@ models;models_basic_voxel;★★☆☆;5.5;5.5;2025;2025;"Tim Little";@timlittle
|
||||||
models;models_rotating_cube;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe
|
models;models_rotating_cube;★☆☆☆;5.6-dev;5.6-dev;2025;2025;"Jopestpe";@jopestpe
|
||||||
models;models_decals;★★★★;5.6-dev;5.6-dev;2025;2025;"JP Mortiboys";@themushroompirates
|
models;models_decals;★★★★;5.6-dev;5.6-dev;2025;2025;"JP Mortiboys";@themushroompirates
|
||||||
models;models_directional_billboard;★★☆☆;5.6-dev;5.6;2025;2025;"Robin";@RobinsAviary
|
models;models_directional_billboard;★★☆☆;5.6-dev;5.6;2025;2025;"Robin";@RobinsAviary
|
||||||
|
models;models_animation_bone_blending;★★★★;5.5;5.5;2026;2026;"dmitrii-brand";@dmitrii-brand
|
||||||
|
models;models_animation_blending;☆☆☆☆;5.5;5.6-dev;2024;2024;"Kirandeep";@Kirandeep-Singh-Khehra
|
||||||
shaders;shaders_ascii_rendering;★★☆☆;5.5;5.6;2025;2025;"Maicon Santana";@maiconpintoabreu
|
shaders;shaders_ascii_rendering;★★☆☆;5.5;5.6;2025;2025;"Maicon Santana";@maiconpintoabreu
|
||||||
shaders;shaders_basic_lighting;★★★★;3.0;4.2;2019;2025;"Chris Camacho";@chriscamacho
|
shaders;shaders_basic_lighting;★★★★;3.0;4.2;2019;2025;"Chris Camacho";@chriscamacho
|
||||||
shaders;shaders_model_shader;★★☆☆;1.3;3.7;2014;2025;"Ramon Santamaria";@raysan5
|
shaders;shaders_model_shader;★★☆☆;1.3;3.7;2014;2025;"Ramon Santamaria";@raysan5
|
||||||
|
|
@ -197,6 +206,7 @@ shaders;shaders_lightmap_rendering;★★★☆;4.5;4.5;2019;2025;"Jussi Viitala
|
||||||
shaders;shaders_rounded_rectangle;★★★☆;5.5;5.5;2025;2025;"Anstro Pleuton";@anstropleuton
|
shaders;shaders_rounded_rectangle;★★★☆;5.5;5.5;2025;2025;"Anstro Pleuton";@anstropleuton
|
||||||
shaders;shaders_depth_rendering;★★★☆;5.6-dev;5.6-dev;2025;2025;"Luís Almeida";@luis605
|
shaders;shaders_depth_rendering;★★★☆;5.6-dev;5.6-dev;2025;2025;"Luís Almeida";@luis605
|
||||||
shaders;shaders_game_of_life;★★★☆;5.6;5.6;2025;2025;"Jordi Santonja";@JordSant
|
shaders;shaders_game_of_life;★★★☆;5.6;5.6;2025;2025;"Jordi Santonja";@JordSant
|
||||||
|
shaders;shaders_rlgl_compute;★★★★;4.0;4.0;2021;2025;"Teddy Astie";@tsnake41
|
||||||
audio;audio_module_playing;★☆☆☆;1.5;3.5;2016;2025;"Ramon Santamaria";@raysan5
|
audio;audio_module_playing;★☆☆☆;1.5;3.5;2016;2025;"Ramon Santamaria";@raysan5
|
||||||
audio;audio_music_stream;★☆☆☆;1.3;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
audio;audio_music_stream;★☆☆☆;1.3;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
||||||
audio;audio_raw_stream;★★★☆;1.6;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
audio;audio_raw_stream;★★★☆;1.6;4.2;2015;2025;"Ramon Santamaria";@raysan5
|
||||||
|
|
@ -206,9 +216,3 @@ audio;audio_stream_effects;★★★★;4.2;5.0;2022;2025;"Ramon Santamaria";@ra
|
||||||
audio;audio_sound_multi;★★☆☆;5.0;5.0;2023;2025;"Jeffery Myers";@JeffM2501
|
audio;audio_sound_multi;★★☆☆;5.0;5.0;2023;2025;"Jeffery Myers";@JeffM2501
|
||||||
audio;audio_sound_positioning;★★☆☆;5.5;5.5;2025;2025;"Le Juez Victor";@Bigfoot71
|
audio;audio_sound_positioning;★★☆☆;5.5;5.5;2025;2025;"Le Juez Victor";@Bigfoot71
|
||||||
audio;audio_spectrum_visualizer;★★★☆;6.0;5.6-dev;2025;2025;"IANN";@meisei4
|
audio;audio_spectrum_visualizer;★★★☆;6.0;5.6-dev;2025;2025;"IANN";@meisei4
|
||||||
others;rlgl_standalone;★★★★;1.6;4.0;2014;2025;"Ramon Santamaria";@raysan5
|
|
||||||
others;rlgl_compute_shader;★★★★;4.0;4.0;2021;2025;"Teddy Astie";@tsnake41
|
|
||||||
others;easings_testbed;★★★☆;2.5;3.0;2019;2025;"Juan Miguel López";@flashback-fx
|
|
||||||
others;raylib_opengl_interop;★★★★;3.8;4.0;2021;2025;"Stephan Soller";@arkanis
|
|
||||||
others;embedded_files_loading;★★☆☆;3.0;3.5;2020;2025;"Kristian Holmgren";@defutura
|
|
||||||
others;web_basic_window;★☆☆☆;5.6-dev;5.6-dev;2014;2025;"Ramon Santamaria";@raysan5
|
|
||||||
|
|
|
||||||
152
examples/models/models_animation_blending.c
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [models] example - animation blending
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.5, last time updated with raylib 5.6-dev
|
||||||
|
*
|
||||||
|
* Example contributed by Kirandeep (@Kirandeep-Singh-Khehra)
|
||||||
|
*
|
||||||
|
* 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) 2024 Kirandeep (@Kirandeep-Singh-Khehra)
|
||||||
|
*
|
||||||
|
* Note: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
|
||||||
|
* Note: This example uses CPU for updating meshes.
|
||||||
|
* For GPU skinning see comments with 'INFO:'.
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define clamp(x,a,b) ((x < a)? a : (x > b)? b : x)
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#define GLSL_VERSION 330
|
||||||
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
|
#define GLSL_VERSION 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - animation blending");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 8.0f, 8.0f, 8.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
|
// Load gltf model
|
||||||
|
Model characterModel = LoadModel("resources/models/gltf/robot.glb"); // Load character model
|
||||||
|
|
||||||
|
/* INFO: Uncomment this to use GPU skinning
|
||||||
|
// Load skinning shader
|
||||||
|
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||||
|
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||||
|
|
||||||
|
for (int i = 0; i < characterModel.materialCount; i++)
|
||||||
|
{
|
||||||
|
characterModel.materials[i].shader = skinningShader;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Load gltf model animations
|
||||||
|
int animsCount = 0;
|
||||||
|
unsigned int animIndex0 = 0;
|
||||||
|
unsigned int animIndex1 = 0;
|
||||||
|
unsigned int animCurrentFrame = 0;
|
||||||
|
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/robot.glb", &animsCount);
|
||||||
|
|
||||||
|
float blendFactor = 0.5f;
|
||||||
|
|
||||||
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||||
|
|
||||||
|
// Select current animation
|
||||||
|
if (IsKeyPressed(KEY_T)) animIndex0 = (animIndex0 + 1)%animsCount;
|
||||||
|
else if (IsKeyPressed(KEY_G)) animIndex0 = (animIndex0 + animsCount - 1)%animsCount;
|
||||||
|
if (IsKeyPressed(KEY_Y)) animIndex1 = (animIndex1 + 1)%animsCount;
|
||||||
|
else if (IsKeyPressed(KEY_H)) animIndex1 = (animIndex1 + animsCount - 1)%animsCount;
|
||||||
|
|
||||||
|
// Select blend factor
|
||||||
|
if (IsKeyPressed(KEY_U)) blendFactor = clamp(blendFactor - 0.1, 0.0f, 1.0f);
|
||||||
|
else if (IsKeyPressed(KEY_J)) blendFactor = clamp(blendFactor + 0.1, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Update animation
|
||||||
|
animCurrentFrame++;
|
||||||
|
|
||||||
|
// Update bones
|
||||||
|
// Note: Same animation frame index is used below. By default it loops both animations
|
||||||
|
UpdateModelAnimationBonesLerp(characterModel, modelAnimations[animIndex0], animCurrentFrame, modelAnimations[animIndex1], animCurrentFrame, blendFactor);
|
||||||
|
|
||||||
|
// INFO: Comment the following line to use GPU skinning
|
||||||
|
UpdateModelVertsToCurrentBones(characterModel);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
/* INFO: Uncomment this to use GPU skinning
|
||||||
|
// Draw character mesh, pose calculation is done in shader (GPU skinning)
|
||||||
|
for (int i = 0; i < characterModel.meshCount; i++)
|
||||||
|
{
|
||||||
|
DrawMesh(characterModel.meshes[i], characterModel.materials[characterModel.meshMaterial[i]], characterModel.transform);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// INFO: Comment the following line to use GPU skinning
|
||||||
|
DrawModel(characterModel, (Vector3){0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
|
||||||
|
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawText("Use the U/J to adjust blend factor", 10, 10, 20, GRAY);
|
||||||
|
DrawText("Use the T/G to switch first animation", 10, 30, 20, GRAY);
|
||||||
|
DrawText("Use the Y/H to switch second animation", 10, 50, 20, GRAY);
|
||||||
|
DrawText(TextFormat("Animations: %s, %s", modelAnimations[animIndex0].name, modelAnimations[animIndex1].name), 10, 70, 20, BLACK);
|
||||||
|
DrawText(TextFormat("Blend Factor: %f", blendFactor), 10, 86, 20, BLACK);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
|
||||||
|
UnloadModel(characterModel); // Unload model and meshes/material
|
||||||
|
|
||||||
|
// INFO: Uncomment the following line to use GPU skinning
|
||||||
|
// UnloadShader(skinningShader); // Unload GPU skinning shader
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/models/models_animation_blending.png
Normal file
|
After Width: | Height: | Size: 26 KiB |
296
examples/models/models_animation_bone_blending.c
Normal file
|
|
@ -0,0 +1,296 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [models] example - animation bone blending
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★★★] 4/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.5, last time updated with raylib 5.5
|
||||||
|
*
|
||||||
|
* This example demonstrates per-bone animation blending, allowing smooth transitions
|
||||||
|
* between two animations by interpolating bone transforms. This is useful for:
|
||||||
|
* - Blending movement animations (walk/run) with action animations (jump/attack)
|
||||||
|
* - Creating smooth animation transitions
|
||||||
|
* - Layering animations (e.g., upper body attack while lower body walks)
|
||||||
|
*
|
||||||
|
* Example contributed by dmitrii-brand (@dmitrii-brand) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
* NOTE: Due to limitations in the Apple OpenGL driver, this feature does not work on MacOS
|
||||||
|
*
|
||||||
|
* 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) 2026 dmitrii-brand (@dmitrii-brand)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
#include <string.h> // Required for: memcpy()
|
||||||
|
#include <stdlib.h> // Required for: NULL
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#define GLSL_VERSION 330
|
||||||
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
|
#define GLSL_VERSION 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static bool IsUpperBodyBone(const char *boneName);
|
||||||
|
static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int frame1,
|
||||||
|
ModelAnimation *anim2, int frame2, float blendFactor, bool upperBodyBlend);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - animation bone blending");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 5.0f, 5.0f, 5.0f }; // Camera position
|
||||||
|
camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
|
||||||
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
|
// Load gltf model
|
||||||
|
Model characterModel = LoadModel("resources/models/gltf/greenman.glb");
|
||||||
|
|
||||||
|
// Load skinning shader
|
||||||
|
Shader skinningShader = LoadShader(TextFormat("resources/shaders/glsl%i/skinning.vs", GLSL_VERSION),
|
||||||
|
TextFormat("resources/shaders/glsl%i/skinning.fs", GLSL_VERSION));
|
||||||
|
|
||||||
|
characterModel.materials[1].shader = skinningShader;
|
||||||
|
|
||||||
|
// Load gltf model animations
|
||||||
|
int animsCount = 0;
|
||||||
|
ModelAnimation *modelAnimations = LoadModelAnimations("resources/models/gltf/greenman.glb", &animsCount);
|
||||||
|
|
||||||
|
// Log all available animations for debugging
|
||||||
|
TraceLog(LOG_INFO, "Found %d animations:", animsCount);
|
||||||
|
for (int i = 0; i < animsCount; i++)
|
||||||
|
{
|
||||||
|
TraceLog(LOG_INFO, " Animation %d: %s (%d frames)", i, modelAnimations[i].name, modelAnimations[i].frameCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use specific indices: walk/move = 2, attack = 3
|
||||||
|
unsigned int animIndex1 = 2; // Walk/Move animation (index 2)
|
||||||
|
unsigned int animIndex2 = 3; // Attack animation (index 3)
|
||||||
|
unsigned int animCurrentFrame1 = 0;
|
||||||
|
unsigned int animCurrentFrame2 = 0;
|
||||||
|
|
||||||
|
// Validate indices
|
||||||
|
if (animIndex1 >= animsCount) animIndex1 = 0;
|
||||||
|
if (animIndex2 >= animsCount) animIndex2 = (animsCount > 1) ? 1 : 0;
|
||||||
|
|
||||||
|
TraceLog(LOG_INFO, "Using Walk (index %d): %s", animIndex1, modelAnimations[animIndex1].name);
|
||||||
|
TraceLog(LOG_INFO, "Using Attack (index %d): %s", animIndex2, modelAnimations[animIndex2].name);
|
||||||
|
|
||||||
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
bool upperBodyBlend = true; // Toggle: true = upper/lower body blending, false = uniform blending (50/50)
|
||||||
|
|
||||||
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera, CAMERA_THIRD_PERSON);
|
||||||
|
|
||||||
|
// Toggle upper/lower body blending mode (SPACE key)
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) upperBodyBlend = !upperBodyBlend;
|
||||||
|
|
||||||
|
// Update animation frames
|
||||||
|
ModelAnimation anim1 = modelAnimations[animIndex1];
|
||||||
|
ModelAnimation anim2 = modelAnimations[animIndex2];
|
||||||
|
|
||||||
|
animCurrentFrame1 = (animCurrentFrame1 + 1)%anim1.frameCount;
|
||||||
|
animCurrentFrame2 = (animCurrentFrame2 + 1)%anim2.frameCount;
|
||||||
|
|
||||||
|
// Blend the two animations
|
||||||
|
characterModel.transform = MatrixTranslate(position.x, position.y, position.z);
|
||||||
|
// When upperBodyBlend is ON: upper body = attack (1.0), lower body = walk (0.0)
|
||||||
|
// When upperBodyBlend is OFF: uniform blend at 0.5 (50% walk, 50% attack)
|
||||||
|
float blendFactor = upperBodyBlend ? 1.0f : 0.5f;
|
||||||
|
BlendModelAnimationsBones(&characterModel, &anim1, animCurrentFrame1, &anim2, animCurrentFrame2, blendFactor, upperBodyBlend);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
// Draw character mesh, pose calculation is done in shader (GPU skinning)
|
||||||
|
DrawMesh(characterModel.meshes[0], characterModel.materials[1], characterModel.transform);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
// Draw UI
|
||||||
|
DrawText("BONE BLENDING EXAMPLE", 10, 10, 20, DARKGRAY);
|
||||||
|
DrawText(TextFormat("Walk (Animation 2): %s", anim1.name), 10, 35, 10, GRAY);
|
||||||
|
DrawText(TextFormat("Attack (Animation 3): %s", anim2.name), 10, 50, 10, GRAY);
|
||||||
|
DrawText(TextFormat("Mode: %s", upperBodyBlend ? "Upper/Lower Body Blending" : "Uniform Blending"), 10, 65, 10, GRAY);
|
||||||
|
DrawText("SPACE - Toggle blending mode", 10, GetScreenHeight() - 20, 10, DARKGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadModelAnimations(modelAnimations, animsCount); // Unload model animation
|
||||||
|
UnloadModel(characterModel); // Unload model and meshes/material
|
||||||
|
UnloadShader(skinningShader); // Unload GPU skinning shader
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Check if a bone is part of upper body (for selective blending)
|
||||||
|
static bool IsUpperBodyBone(const char *boneName)
|
||||||
|
{
|
||||||
|
// Common upper body bone names (adjust based on your model)
|
||||||
|
if (TextIsEqual(boneName, "spine") || TextIsEqual(boneName, "spine1") || TextIsEqual(boneName, "spine2") ||
|
||||||
|
TextIsEqual(boneName, "chest") || TextIsEqual(boneName, "upperChest") ||
|
||||||
|
TextIsEqual(boneName, "neck") || TextIsEqual(boneName, "head") ||
|
||||||
|
TextIsEqual(boneName, "shoulder") || TextIsEqual(boneName, "shoulder_L") || TextIsEqual(boneName, "shoulder_R") ||
|
||||||
|
TextIsEqual(boneName, "upperArm") || TextIsEqual(boneName, "upperArm_L") || TextIsEqual(boneName, "upperArm_R") ||
|
||||||
|
TextIsEqual(boneName, "lowerArm") || TextIsEqual(boneName, "lowerArm_L") || TextIsEqual(boneName, "lowerArm_R") ||
|
||||||
|
TextIsEqual(boneName, "hand") || TextIsEqual(boneName, "hand_L") || TextIsEqual(boneName, "hand_R") ||
|
||||||
|
TextIsEqual(boneName, "clavicle") || TextIsEqual(boneName, "clavicle_L") || TextIsEqual(boneName, "clavicle_R"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if bone name contains upper body keywords
|
||||||
|
if (strstr(boneName, "spine") != NULL || strstr(boneName, "chest") != NULL ||
|
||||||
|
strstr(boneName, "neck") != NULL || strstr(boneName, "head") != NULL ||
|
||||||
|
strstr(boneName, "shoulder") != NULL || strstr(boneName, "arm") != NULL ||
|
||||||
|
strstr(boneName, "hand") != NULL || strstr(boneName, "clavicle") != NULL)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Blend two animations per-bone with selective upper/lower body blending
|
||||||
|
static void BlendModelAnimationsBones(Model *model, ModelAnimation *anim1, int frame1,
|
||||||
|
ModelAnimation *anim2, int frame2, float blendFactor, bool upperBodyBlend)
|
||||||
|
{
|
||||||
|
// Validate inputs
|
||||||
|
if (anim1->boneCount == 0 || anim1->framePoses == NULL ||
|
||||||
|
anim2->boneCount == 0 || anim2->framePoses == NULL ||
|
||||||
|
model->boneCount == 0 || model->bindPose == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clamp blend factor to [0, 1]
|
||||||
|
blendFactor = fminf(1.0f, fmaxf(0.0f, blendFactor));
|
||||||
|
|
||||||
|
// Ensure frame indices are valid
|
||||||
|
if (frame1 >= anim1->frameCount) frame1 = anim1->frameCount - 1;
|
||||||
|
if (frame2 >= anim2->frameCount) frame2 = anim2->frameCount - 1;
|
||||||
|
if (frame1 < 0) frame1 = 0;
|
||||||
|
if (frame2 < 0) frame2 = 0;
|
||||||
|
|
||||||
|
// Find first mesh with bones
|
||||||
|
int firstMeshWithBones = -1;
|
||||||
|
for (int i = 0; i < model->meshCount; i++)
|
||||||
|
{
|
||||||
|
if (model->meshes[i].boneMatrices)
|
||||||
|
{
|
||||||
|
firstMeshWithBones = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstMeshWithBones == -1) return;
|
||||||
|
|
||||||
|
// Get bone count (use minimum of all to be safe)
|
||||||
|
int boneCount = model->boneCount;
|
||||||
|
if (anim1->boneCount < boneCount) boneCount = anim1->boneCount;
|
||||||
|
if (anim2->boneCount < boneCount) boneCount = anim2->boneCount;
|
||||||
|
|
||||||
|
// Blend each bone
|
||||||
|
for (int boneId = 0; boneId < boneCount; boneId++)
|
||||||
|
{
|
||||||
|
// Determine blend factor for this bone
|
||||||
|
float boneBlendFactor = blendFactor;
|
||||||
|
|
||||||
|
// If upper body blending is enabled, use different blend factors for upper vs lower body
|
||||||
|
if (upperBodyBlend)
|
||||||
|
{
|
||||||
|
const char *boneName = model->bones[boneId].name;
|
||||||
|
bool isUpperBody = IsUpperBodyBone(boneName);
|
||||||
|
|
||||||
|
// Upper body: use anim2 (attack), Lower body: use anim1 (walk)
|
||||||
|
// blendFactor = 0.0 means full anim1 (walk), 1.0 means full anim2 (attack)
|
||||||
|
if (isUpperBody) boneBlendFactor = blendFactor; // Upper body: blend towards anim2 (attack)
|
||||||
|
else boneBlendFactor = 1.0f - blendFactor; // Lower body: blend towards anim1 (walk) - invert the blend
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get transforms from both animations
|
||||||
|
Transform *bindTransform = &model->bindPose[boneId];
|
||||||
|
Transform *anim1Transform = &anim1->framePoses[frame1][boneId];
|
||||||
|
Transform *anim2Transform = &anim2->framePoses[frame2][boneId];
|
||||||
|
|
||||||
|
// Blend the transforms
|
||||||
|
Transform blended;
|
||||||
|
blended.translation = Vector3Lerp(anim1Transform->translation, anim2Transform->translation, boneBlendFactor);
|
||||||
|
blended.rotation = QuaternionSlerp(anim1Transform->rotation, anim2Transform->rotation, boneBlendFactor);
|
||||||
|
blended.scale = Vector3Lerp(anim1Transform->scale, anim2Transform->scale, boneBlendFactor);
|
||||||
|
|
||||||
|
// Convert bind pose to matrix
|
||||||
|
Matrix bindMatrix = MatrixMultiply(MatrixMultiply(
|
||||||
|
MatrixScale(bindTransform->scale.x, bindTransform->scale.y, bindTransform->scale.z),
|
||||||
|
QuaternionToMatrix(bindTransform->rotation)),
|
||||||
|
MatrixTranslate(bindTransform->translation.x, bindTransform->translation.y, bindTransform->translation.z));
|
||||||
|
|
||||||
|
// Convert blended transform to matrix
|
||||||
|
Matrix blendedMatrix = MatrixMultiply(MatrixMultiply(
|
||||||
|
MatrixScale(blended.scale.x, blended.scale.y, blended.scale.z),
|
||||||
|
QuaternionToMatrix(blended.rotation)),
|
||||||
|
MatrixTranslate(blended.translation.x, blended.translation.y, blended.translation.z));
|
||||||
|
|
||||||
|
// Calculate final bone matrix (similar to UpdateModelAnimationBones)
|
||||||
|
model->meshes[firstMeshWithBones].boneMatrices[boneId] = MatrixMultiply(MatrixInvert(bindMatrix), blendedMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy bone matrices to remaining meshes
|
||||||
|
for (int i = firstMeshWithBones + 1; i < model->meshCount; i++)
|
||||||
|
{
|
||||||
|
if (model->meshes[i].boneMatrices)
|
||||||
|
{
|
||||||
|
memcpy(model->meshes[i].boneMatrices,
|
||||||
|
model->meshes[firstMeshWithBones].boneMatrices,
|
||||||
|
model->meshes[i].boneCount*sizeof(model->meshes[i].boneMatrices[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#define WORLD_SIZE 8 // Size of our voxel world (8x8x8 cubes)
|
#define WORLD_SIZE 8 // Size of our voxel world (8x8x8 cubes)
|
||||||
|
|
@ -32,7 +33,7 @@ int main(void)
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - basic voxel");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - basic voxel");
|
||||||
|
|
||||||
DisableCursor(); // Lock mouse to window center
|
DisableCursor(); // Lock mouse to window center
|
||||||
|
|
||||||
// Define the camera to look into our 3d world (first person)
|
// Define the camera to look into our 3d world (first person)
|
||||||
Camera3D camera = { 0 };
|
Camera3D camera = { 0 };
|
||||||
|
|
@ -74,7 +75,7 @@ int main(void)
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
// Cast a ray from the screen center (where crosshair would be)
|
// Cast a ray from the screen center (where crosshair would be)
|
||||||
Vector2 screenCenter = { screenWidth/2.0f, screenHeight/2.0f };
|
Vector2 screenCenter = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||||
Ray ray = GetMouseRay(screenCenter, camera);
|
Ray ray = GetMouseRay(screenCenter, camera);
|
||||||
|
|
||||||
// Check ray collision with all voxels
|
// Check ray collision with all voxels
|
||||||
|
|
@ -135,6 +136,9 @@ int main(void)
|
||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
|
// Draw reference point for raycasting to delete blocks
|
||||||
|
DrawCircle(GetRenderWidth()/2, GetScreenHeight()/2, 4, RED);
|
||||||
|
|
||||||
DrawText("Left-click a voxel to remove it!", 10, 10, 20, DARKGRAY);
|
DrawText("Left-click a voxel to remove it!", 10, 10, 20, DARKGRAY);
|
||||||
DrawText("WASD to move, mouse to look around", 10, 35, 10, GRAY);
|
DrawText("WASD to move, mouse to look around", 10, 35, 10, GRAY);
|
||||||
|
|
||||||
|
|
@ -145,6 +149,7 @@ int main(void)
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModel(cubeModel);
|
UnloadModel(cubeModel);
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 341 KiB After Width: | Height: | Size: 28 KiB |
|
|
@ -45,7 +45,7 @@ static void FreeMeshBuilder(MeshBuilder *mb);
|
||||||
static Mesh BuildMesh(MeshBuilder *mb);
|
static Mesh BuildMesh(MeshBuilder *mb);
|
||||||
static Mesh GenMeshDecal(Model inputModel, Matrix projection, float decalSize, float decalOffset);
|
static Mesh GenMeshDecal(Model inputModel, Matrix projection, float decalSize, float decalOffset);
|
||||||
static Vector3 ClipSegment(Vector3 v0, Vector3 v1, Vector3 p, float s);
|
static Vector3 ClipSegment(Vector3 v0, Vector3 v1, Vector3 p, float s);
|
||||||
#define FreeDecalMeshData() GenMeshDecal((Model){ .meshCount = -1.0f }, (Matrix){ 0 }, 0.0f, 0.0f)
|
static void FreeDecalMeshData(void) { GenMeshDecal((Model){ .meshCount = -1 }, (Matrix){ 0 }, 0.0f, 0.0f); }
|
||||||
static bool GuiButton(Rectangle rec, const char *label);
|
static bool GuiButton(Rectangle rec, const char *label);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
@ -183,7 +183,7 @@ int main(void)
|
||||||
if (showModel) DrawModel(model, (Vector3){0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
|
if (showModel) DrawModel(model, (Vector3){0.0f, 0.0f, 0.0f}, 1.0f, WHITE);
|
||||||
|
|
||||||
// Draw the decal models
|
// Draw the decal models
|
||||||
for (int i = 0; i < decalCount; i++) DrawModel(decalModels[i], (Vector3){0}, 1.0f, WHITE);
|
for (int i = 0; i < decalCount; i++) DrawModel(decalModels[i], (Vector3){ 0 }, 1.0f, WHITE);
|
||||||
|
|
||||||
// If we hit the mesh, draw the box for the decal
|
// If we hit the mesh, draw the box for the decal
|
||||||
if (collision.hit)
|
if (collision.hit)
|
||||||
|
|
@ -191,19 +191,19 @@ int main(void)
|
||||||
Vector3 origin = Vector3Add(collision.point, Vector3Scale(collision.normal, 1.0f));
|
Vector3 origin = Vector3Add(collision.point, Vector3Scale(collision.normal, 1.0f));
|
||||||
Matrix splat = MatrixLookAt(collision.point, origin, (Vector3){0,1,0});
|
Matrix splat = MatrixLookAt(collision.point, origin, (Vector3){0,1,0});
|
||||||
placementCube.transform = MatrixInvert(splat);
|
placementCube.transform = MatrixInvert(splat);
|
||||||
DrawModel(placementCube, (Vector3){0}, 1.0f, Fade(WHITE, 0.5f));
|
DrawModel(placementCube, (Vector3){ 0 }, 1.0f, Fade(WHITE, 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawGrid(10, 10.0f);
|
DrawGrid(10, 10.0f);
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
float yPos = 10;
|
float yPos = 10;
|
||||||
float x0 = GetScreenWidth() - 300;
|
float x0 = GetScreenWidth() - 300.0f;
|
||||||
float x1 = x0 + 100;
|
float x1 = x0 + 100;
|
||||||
float x2 = x1 + 100;
|
float x2 = x1 + 100;
|
||||||
|
|
||||||
DrawText("Vertices", x1, yPos, 10, LIME);
|
DrawText("Vertices", (int)x1, (int)yPos, 10, LIME);
|
||||||
DrawText("Triangles", x2, yPos, 10, LIME);
|
DrawText("Triangles", (int)x2, (int)yPos, 10, LIME);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
|
|
||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
|
|
@ -215,24 +215,24 @@ int main(void)
|
||||||
triangleCount += model.meshes[i].triangleCount;
|
triangleCount += model.meshes[i].triangleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("Main model", x0, yPos, 10, LIME);
|
DrawText("Main model", (int)x0, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", vertexCount), x1, yPos, 10, LIME);
|
DrawText(TextFormat("%d", vertexCount), (int)x1, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", triangleCount), x2, yPos, 10, LIME);
|
DrawText(TextFormat("%d", triangleCount), (int)x2, (int)yPos, 10, LIME);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
|
|
||||||
for (int i = 0; i < decalCount; i++)
|
for (int i = 0; i < decalCount; i++)
|
||||||
{
|
{
|
||||||
if (i == 20)
|
if (i == 20)
|
||||||
{
|
{
|
||||||
DrawText("...", x0, yPos, 10, LIME);
|
DrawText("...", (int)x0, (int)yPos, 10, LIME);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < 20)
|
if (i < 20)
|
||||||
{
|
{
|
||||||
DrawText(TextFormat("Decal #%d", i+1), x0, yPos, 10, LIME);
|
DrawText(TextFormat("Decal #%d", i+1), (int)x0, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", decalModels[i].meshes[0].vertexCount), x1, yPos, 10, LIME);
|
DrawText(TextFormat("%d", decalModels[i].meshes[0].vertexCount), (int)x1, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", decalModels[i].meshes[0].triangleCount), x2, yPos, 10, LIME);
|
DrawText(TextFormat("%d", decalModels[i].meshes[0].triangleCount), (int)x2, (int)yPos, 10, LIME);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,18 +240,18 @@ int main(void)
|
||||||
triangleCount += decalModels[i].meshes[0].triangleCount;
|
triangleCount += decalModels[i].meshes[0].triangleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("TOTAL", x0, yPos, 10, LIME);
|
DrawText("TOTAL", (int)x0, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", vertexCount), x1, yPos, 10, LIME);
|
DrawText(TextFormat("%d", vertexCount), (int)x1, (int)yPos, 10, LIME);
|
||||||
DrawText(TextFormat("%d", triangleCount), x2, yPos, 10, LIME);
|
DrawText(TextFormat("%d", triangleCount), (int)x2, (int)yPos, 10, LIME);
|
||||||
yPos += 15;
|
yPos += 15;
|
||||||
|
|
||||||
DrawText("Hold RMB to move camera", 10, 430, 10, GRAY);
|
DrawText("Hold RMB to move camera", 10, 430, 10, GRAY);
|
||||||
DrawText("(c) Character model and texture from kenney.nl", screenWidth - 260, screenHeight - 20, 10, GRAY);
|
DrawText("(c) Character model and texture from kenney.nl", screenWidth - 260, screenHeight - 20, 10, GRAY);
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
if (GuiButton((Rectangle){ 10, screenHeight - 100, 100, 60 }, showModel ? "Hide Model" : "Show Model")) showModel = !showModel;
|
if (GuiButton((Rectangle){ 10, screenHeight - 1000.f, 100, 60 }, showModel ? "Hide Model" : "Show Model")) showModel = !showModel;
|
||||||
|
|
||||||
if (GuiButton((Rectangle){ 10 + 110, screenHeight - 100, 100, 60 }, "Clear Decals"))
|
if (GuiButton((Rectangle){ 10 + 110, screenHeight - 100.0f, 100, 60 }, "Clear Decals"))
|
||||||
{
|
{
|
||||||
// Clear decals, unload all decal models
|
// Clear decals, unload all decal models
|
||||||
for (int i = 0; i < decalCount; i++) UnloadModel(decalModels[i]);
|
for (int i = 0; i < decalCount; i++) UnloadModel(decalModels[i]);
|
||||||
|
|
@ -596,8 +596,8 @@ static bool GuiButton(Rectangle rec, const char *label)
|
||||||
DrawRectangleRec(rec, bgColor);
|
DrawRectangleRec(rec, bgColor);
|
||||||
DrawRectangleLinesEx(rec, 2.0f, DARKGRAY);
|
DrawRectangleLinesEx(rec, 2.0f, DARKGRAY);
|
||||||
|
|
||||||
float fontSize = 10.0f;
|
int fontSize = 10;
|
||||||
float textWidth = MeasureText(label, fontSize);
|
int textWidth = MeasureText(label, fontSize);
|
||||||
|
|
||||||
DrawText(label, (int)(rec.x + rec.width*0.5f - textWidth*0.5f), (int)(rec.y + rec.height*0.5f - fontSize*0.5f), fontSize, DARKGRAY);
|
DrawText(label, (int)(rec.x + rec.width*0.5f - textWidth*0.5f), (int)(rec.y + rec.height*0.5f - fontSize*0.5f), fontSize, DARKGRAY);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,9 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -80,18 +80,23 @@ int main(void)
|
||||||
if (playerCellY < 0) playerCellY = 0;
|
if (playerCellY < 0) playerCellY = 0;
|
||||||
else if (playerCellY >= cubicmap.height) playerCellY = cubicmap.height - 1;
|
else if (playerCellY >= cubicmap.height) playerCellY = cubicmap.height - 1;
|
||||||
|
|
||||||
// Check map collisions using image data and player position
|
// Check map collisions using image data and player position against surrounding cells only
|
||||||
// TODO: Improvement: Just check player surrounding cells for collision
|
for (int y = playerCellY - 1; y <= playerCellY + 1; y++)
|
||||||
for (int y = 0; y < cubicmap.height; y++)
|
|
||||||
{
|
{
|
||||||
for (int x = 0; x < cubicmap.width; x++)
|
// Avoid map accessing out of bounds
|
||||||
|
if ((y >= 0) && (y < cubicmap.height))
|
||||||
{
|
{
|
||||||
if ((mapPixels[y*cubicmap.width + x].r == 255) && // Collision: white pixel, only check R channel
|
for (int x = playerCellX - 1; x <= playerCellX + 1; x++)
|
||||||
(CheckCollisionCircleRec(playerPos, playerRadius,
|
|
||||||
(Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f })))
|
|
||||||
{
|
{
|
||||||
// Collision detected, reset camera position
|
// NOTE: Collision: Only checking R channel for white pixel
|
||||||
camera.position = oldCamPos;
|
if (((x >= 0) && (x < cubicmap.width)) &&
|
||||||
|
(mapPixels[y*cubicmap.width + x].r == 255) &&
|
||||||
|
(CheckCollisionCircleRec(playerPos, playerRadius,
|
||||||
|
(Rectangle){ mapPosition.x - 0.5f + x*1.0f, mapPosition.z - 0.5f + y*1.0f, 1.0f, 1.0f })))
|
||||||
|
{
|
||||||
|
// Collision detected, reset camera position
|
||||||
|
camera.position = oldCamPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,25 +148,25 @@ void DrawSphereBasic(Color color)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < slices; j++)
|
for (int j = 0; j < slices; j++)
|
||||||
{
|
{
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*i))*sinf(DEG2RAD*(j*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*i)),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*i)),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*i))*cosf(DEG2RAD*(j*360.0f/slices)));
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1))),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360.0f/slices)));
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*(j*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*sinf(DEG2RAD*(j*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1))),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*(j*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*cosf(DEG2RAD*(j*360.0f/slices)));
|
||||||
|
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*i))*sinf(DEG2RAD*(j*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*i))*sinf(DEG2RAD*(j*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*i)),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*i)),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*i))*cosf(DEG2RAD*(j*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*i))*cosf(DEG2RAD*(j*360.0f/slices)));
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*sinf(DEG2RAD*((j+1)*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i)))*sinf(DEG2RAD*((j+1)*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*(i))),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*(i))),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*(i)))*cosf(DEG2RAD*((j+1)*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i)))*cosf(DEG2RAD*((j+1)*360.0f/slices)));
|
||||||
rlVertex3f(cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360/slices)),
|
rlVertex3f(cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*sinf(DEG2RAD*((j+1)*360.0f/slices)),
|
||||||
sinf(DEG2RAD*(270+(180/(rings + 1))*(i+1))),
|
sinf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1))),
|
||||||
cosf(DEG2RAD*(270+(180/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360/slices)));
|
cosf(DEG2RAD*(270+(180.0f/(rings + 1))*(i+1)))*cosf(DEG2RAD*((j+1)*360.0f/slices)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rlEnd();
|
rlEnd();
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ int main(void)
|
||||||
|
|
||||||
// Calculate the cube position
|
// Calculate the cube position
|
||||||
Vector3 cubePos = {
|
Vector3 cubePos = {
|
||||||
(float)(x - numBlocks/2)*(scale*3.0f) + scatter,
|
(float)(x - (float)numBlocks/2)*(scale*3.0f) + scatter,
|
||||||
(float)(y - numBlocks/2)*(scale*2.0f) + scatter,
|
(float)(y - (float)numBlocks/2)*(scale*2.0f) + scatter,
|
||||||
(float)(z - numBlocks/2)*(scale*3.0f) + scatter
|
(float)(z - (float)numBlocks/2)*(scale*3.0f) + scatter
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pick a color with a hue depending on cube position for the rainbow color effect
|
// Pick a color with a hue depending on cube position for the rainbow color effect
|
||||||
|
|
|
||||||
6042
examples/models/raygui.h
Normal file
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_DESKTOP_SDL)
|
||||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
|
#define GLAD_GLES2_IMPLEMENTATION
|
||||||
#include "glad_gles2.h" // Required for: OpenGL functionality
|
#include "glad_gles2.h" // Required for: OpenGL functionality
|
||||||
#define glGenVertexArrays glGenVertexArraysOES
|
#define glGenVertexArrays glGenVertexArraysOES
|
||||||
#define glBindVertexArray glBindVertexArrayOES
|
#define glBindVertexArray glBindVertexArrayOES
|
||||||
|
|
|
||||||
|
|
@ -1,263 +0,0 @@
|
||||||
/*******************************************************************************************
|
|
||||||
*
|
|
||||||
* reasings - raylib easings library, based on Robert Penner library
|
|
||||||
*
|
|
||||||
* Useful easing functions for values animation
|
|
||||||
*
|
|
||||||
* This header uses:
|
|
||||||
* #define REASINGS_STATIC_INLINE // Inlines all functions code, so it runs faster.
|
|
||||||
* // This requires lots of memory on system.
|
|
||||||
* How to use:
|
|
||||||
* The four inputs t,b,c,d are defined as follows:
|
|
||||||
* t = current time (in any unit measure, but same unit as duration)
|
|
||||||
* b = starting value to interpolate
|
|
||||||
* c = the total change in value of b that needs to occur
|
|
||||||
* d = total time it should take to complete (duration)
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* int currentTime = 0;
|
|
||||||
* int duration = 100;
|
|
||||||
* float startPositionX = 0.0f;
|
|
||||||
* float finalPositionX = 30.0f;
|
|
||||||
* float currentPositionX = startPositionX;
|
|
||||||
*
|
|
||||||
* while (currentPositionX < finalPositionX)
|
|
||||||
* {
|
|
||||||
* currentPositionX = EaseSineIn(currentTime, startPositionX, finalPositionX - startPositionX, duration);
|
|
||||||
* currentTime++;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* A port of Robert Penner's easing equations to C (http://robertpenner.com/easing/)
|
|
||||||
*
|
|
||||||
* Robert Penner License
|
|
||||||
* ---------------------------------------------------------------------------------
|
|
||||||
* Open source under the BSD License.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2001 Robert Penner. All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* - Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* - Neither the name of the author nor the names of contributors may be used
|
|
||||||
* to endorse or promote products derived from this software without specific
|
|
||||||
* prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
||||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
* ---------------------------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
|
|
||||||
*
|
|
||||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
|
||||||
* will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
|
||||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
|
||||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
|
||||||
* in the product documentation would be appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
|
||||||
* as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
*
|
|
||||||
**********************************************************************************************/
|
|
||||||
|
|
||||||
#ifndef REASINGS_H
|
|
||||||
#define REASINGS_H
|
|
||||||
|
|
||||||
#define REASINGS_STATIC_INLINE // NOTE: By default, compile functions as static inline
|
|
||||||
|
|
||||||
#if defined(REASINGS_STATIC_INLINE)
|
|
||||||
#define EASEDEF static inline
|
|
||||||
#else
|
|
||||||
#define EASEDEF extern
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), powf()
|
|
||||||
|
|
||||||
#ifndef PI
|
|
||||||
#define PI 3.14159265358979323846f //Required as PI is not always defined in math.h
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" { // Prevents name mangling of functions
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Linear Easing functions
|
|
||||||
EASEDEF float EaseLinearNone(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear
|
|
||||||
EASEDEF float EaseLinearIn(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear In
|
|
||||||
EASEDEF float EaseLinearOut(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear Out
|
|
||||||
EASEDEF float EaseLinearInOut(float t, float b, float c, float d) { return (c*t/d + b); } // Ease: Linear In Out
|
|
||||||
|
|
||||||
// Sine Easing functions
|
|
||||||
EASEDEF float EaseSineIn(float t, float b, float c, float d) { return (-c*cosf(t/d*(PI/2.0f)) + c + b); } // Ease: Sine In
|
|
||||||
EASEDEF float EaseSineOut(float t, float b, float c, float d) { return (c*sinf(t/d*(PI/2.0f)) + b); } // Ease: Sine Out
|
|
||||||
EASEDEF float EaseSineInOut(float t, float b, float c, float d) { return (-c/2.0f*(cosf(PI*t/d) - 1.0f) + b); } // Ease: Sine In Out
|
|
||||||
|
|
||||||
// Circular Easing functions
|
|
||||||
EASEDEF float EaseCircIn(float t, float b, float c, float d) { t /= d; return (-c*(sqrtf(1.0f - t*t) - 1.0f) + b); } // Ease: Circular In
|
|
||||||
EASEDEF float EaseCircOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*sqrtf(1.0f - t*t) + b); } // Ease: Circular Out
|
|
||||||
EASEDEF float EaseCircInOut(float t, float b, float c, float d) // Ease: Circular In Out
|
|
||||||
{
|
|
||||||
if ((t/=d/2.0f) < 1.0f) return (-c/2.0f*(sqrtf(1.0f - t*t) - 1.0f) + b);
|
|
||||||
t -= 2.0f; return (c/2.0f*(sqrtf(1.0f - t*t) + 1.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cubic Easing functions
|
|
||||||
EASEDEF float EaseCubicIn(float t, float b, float c, float d) { t /= d; return (c*t*t*t + b); } // Ease: Cubic In
|
|
||||||
EASEDEF float EaseCubicOut(float t, float b, float c, float d) { t = t/d - 1.0f; return (c*(t*t*t + 1.0f) + b); } // Ease: Cubic Out
|
|
||||||
EASEDEF float EaseCubicInOut(float t, float b, float c, float d) // Ease: Cubic In Out
|
|
||||||
{
|
|
||||||
if ((t/=d/2.0f) < 1.0f) return (c/2.0f*t*t*t + b);
|
|
||||||
t -= 2.0f; return (c/2.0f*(t*t*t + 2.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quadratic Easing functions
|
|
||||||
EASEDEF float EaseQuadIn(float t, float b, float c, float d) { t /= d; return (c*t*t + b); } // Ease: Quadratic In
|
|
||||||
EASEDEF float EaseQuadOut(float t, float b, float c, float d) { t /= d; return (-c*t*(t - 2.0f) + b); } // Ease: Quadratic Out
|
|
||||||
EASEDEF float EaseQuadInOut(float t, float b, float c, float d) // Ease: Quadratic In Out
|
|
||||||
{
|
|
||||||
if ((t/=d/2) < 1) return (((c/2)*(t*t)) + b);
|
|
||||||
return (-c/2.0f*(((t - 1.0f)*(t - 3.0f)) - 1.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exponential Easing functions
|
|
||||||
EASEDEF float EaseExpoIn(float t, float b, float c, float d) { return (t == 0.0f) ? b : (c*powf(2.0f, 10.0f*(t/d - 1.0f)) + b); } // Ease: Exponential In
|
|
||||||
EASEDEF float EaseExpoOut(float t, float b, float c, float d) { return (t == d) ? (b + c) : (c*(-powf(2.0f, -10.0f*t/d) + 1.0f) + b); } // Ease: Exponential Out
|
|
||||||
EASEDEF float EaseExpoInOut(float t, float b, float c, float d) // Ease: Exponential In Out
|
|
||||||
{
|
|
||||||
if (t == 0.0f) return b;
|
|
||||||
if (t == d) return (b + c);
|
|
||||||
if ((t/=d/2.0f) < 1.0f) return (c/2.0f*powf(2.0f, 10.0f*(t - 1.0f)) + b);
|
|
||||||
|
|
||||||
return (c/2.0f*(-powf(2.0f, -10.0f*(t - 1.0f)) + 2.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Back Easing functions
|
|
||||||
EASEDEF float EaseBackIn(float t, float b, float c, float d) // Ease: Back In
|
|
||||||
{
|
|
||||||
float s = 1.70158f;
|
|
||||||
float postFix = t/=d;
|
|
||||||
return (c*(postFix)*t*((s + 1.0f)*t - s) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
EASEDEF float EaseBackOut(float t, float b, float c, float d) // Ease: Back Out
|
|
||||||
{
|
|
||||||
float s = 1.70158f;
|
|
||||||
t = t/d - 1.0f;
|
|
||||||
return (c*(t*t*((s + 1.0f)*t + s) + 1.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
EASEDEF float EaseBackInOut(float t, float b, float c, float d) // Ease: Back In Out
|
|
||||||
{
|
|
||||||
float s = 1.70158f;
|
|
||||||
if ((t/=d/2.0f) < 1.0f)
|
|
||||||
{
|
|
||||||
s *= 1.525f;
|
|
||||||
return (c/2.0f*(t*t*((s + 1.0f)*t - s)) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
float postFix = t-=2.0f;
|
|
||||||
s *= 1.525f;
|
|
||||||
return (c/2.0f*((postFix)*t*((s + 1.0f)*t + s) + 2.0f) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bounce Easing functions
|
|
||||||
EASEDEF float EaseBounceOut(float t, float b, float c, float d) // Ease: Bounce Out
|
|
||||||
{
|
|
||||||
if ((t/=d) < (1.0f/2.75f))
|
|
||||||
{
|
|
||||||
return (c*(7.5625f*t*t) + b);
|
|
||||||
}
|
|
||||||
else if (t < (2.0f/2.75f))
|
|
||||||
{
|
|
||||||
float postFix = t-=(1.5f/2.75f);
|
|
||||||
return (c*(7.5625f*(postFix)*t + 0.75f) + b);
|
|
||||||
}
|
|
||||||
else if (t < (2.5/2.75))
|
|
||||||
{
|
|
||||||
float postFix = t-=(2.25f/2.75f);
|
|
||||||
return (c*(7.5625f*(postFix)*t + 0.9375f) + b);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
float postFix = t-=(2.625f/2.75f);
|
|
||||||
return (c*(7.5625f*(postFix)*t + 0.984375f) + b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EASEDEF float EaseBounceIn(float t, float b, float c, float d) { return (c - EaseBounceOut(d - t, 0.0f, c, d) + b); } // Ease: Bounce In
|
|
||||||
EASEDEF float EaseBounceInOut(float t, float b, float c, float d) // Ease: Bounce In Out
|
|
||||||
{
|
|
||||||
if (t < d/2.0f) return (EaseBounceIn(t*2.0f, 0.0f, c, d)*0.5f + b);
|
|
||||||
else return (EaseBounceOut(t*2.0f - d, 0.0f, c, d)*0.5f + c*0.5f + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Elastic Easing functions
|
|
||||||
EASEDEF float EaseElasticIn(float t, float b, float c, float d) // Ease: Elastic In
|
|
||||||
{
|
|
||||||
if (t == 0.0f) return b;
|
|
||||||
if ((t/=d) == 1.0f) return (b + c);
|
|
||||||
|
|
||||||
float p = d*0.3f;
|
|
||||||
float a = c;
|
|
||||||
float s = p/4.0f;
|
|
||||||
float postFix = a*powf(2.0f, 10.0f*(t-=1.0f));
|
|
||||||
|
|
||||||
return (-(postFix*sinf((t*d-s)*(2.0f*PI)/p )) + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
EASEDEF float EaseElasticOut(float t, float b, float c, float d) // Ease: Elastic Out
|
|
||||||
{
|
|
||||||
if (t == 0.0f) return b;
|
|
||||||
if ((t/=d) == 1.0f) return (b + c);
|
|
||||||
|
|
||||||
float p = d*0.3f;
|
|
||||||
float a = c;
|
|
||||||
float s = p/4.0f;
|
|
||||||
|
|
||||||
return (a*powf(2.0f,-10.0f*t)*sinf((t*d-s)*(2.0f*PI)/p) + c + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
EASEDEF float EaseElasticInOut(float t, float b, float c, float d) // Ease: Elastic In Out
|
|
||||||
{
|
|
||||||
if (t == 0.0f) return b;
|
|
||||||
if ((t/=d/2.0f) == 2.0f) return (b + c);
|
|
||||||
|
|
||||||
float p = d*(0.3f*1.5f);
|
|
||||||
float a = c;
|
|
||||||
float s = p/4.0f;
|
|
||||||
|
|
||||||
if (t < 1.0f)
|
|
||||||
{
|
|
||||||
float postFix = a*powf(2.0f, 10.0f*(t-=1.0f));
|
|
||||||
return -0.5f*(postFix*sinf((t*d-s)*(2.0f*PI)/p)) + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
float postFix = a*powf(2.0f, -10.0f*(t-=1.0f));
|
|
||||||
|
|
||||||
return (postFix*sinf((t*d-s)*(2.0f*PI)/p)*0.5f + c + b);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // REASINGS_H
|
|
||||||
|
Before Width: | Height: | Size: 10 KiB |
|
|
@ -36,7 +36,7 @@ void main()
|
||||||
vec3 ambient = albedo*vec3(0.1);
|
vec3 ambient = albedo*vec3(0.1);
|
||||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||||
|
|
||||||
for (int i = 0; i < NR_LIGHTS; ++i)
|
for (int i = 0; i < NR_LIGHTS; i++)
|
||||||
{
|
{
|
||||||
if (lights[i].enabled == 0) continue;
|
if (lights[i].enabled == 0) continue;
|
||||||
vec3 lightDirection = lights[i].position - fragPosition;
|
vec3 lightDirection = lights[i].position - fragPosition;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ void main()
|
||||||
// Fc(z) = z^2 + c on the complex numbers c from the plane does not diverge to infinity starting at z = 0
|
// Fc(z) = z^2 + c on the complex numbers c from the plane does not diverge to infinity starting at z = 0
|
||||||
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
|
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
|
||||||
|
|
||||||
for (int iter = 0; iter < maxIterationsLimit; ++iter)
|
for (int iter = 0; iter < maxIterationsLimit; iter++)
|
||||||
{
|
{
|
||||||
float aa = a*a;
|
float aa = a*a;
|
||||||
float bb = b*b;
|
float bb = b*b;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ uniform float ampY;
|
||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ void main()
|
||||||
vec3 ambient = albedo*vec3(0.1);
|
vec3 ambient = albedo*vec3(0.1);
|
||||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||||
|
|
||||||
for (int i = 0; i < NR_LIGHTS; ++i)
|
for (int i = 0; i < NR_LIGHTS; i++)
|
||||||
{
|
{
|
||||||
if (lights[i].enabled == 0) continue;
|
if (lights[i].enabled == 0) continue;
|
||||||
vec3 lightDirection = lights[i].position - fragPosition;
|
vec3 lightDirection = lights[i].position - fragPosition;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ void main()
|
||||||
a = aa - bb + c.x;
|
a = aa - bb + c.x;
|
||||||
b = twoab + c.y;
|
b = twoab + c.y;
|
||||||
|
|
||||||
++iter;
|
iter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iter >= maxIterations)
|
if (iter >= maxIterations)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ uniform float ampY;
|
||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ uniform vec3 viewPosition;
|
||||||
const float QUADRATIC = 0.032;
|
const float QUADRATIC = 0.032;
|
||||||
const float LINEAR = 0.09;
|
const float LINEAR = 0.09;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
vec3 fragPosition = texture(gPosition, texCoord).rgb;
|
||||||
vec3 normal = texture(gNormal, texCoord).rgb;
|
vec3 normal = texture(gNormal, texCoord).rgb;
|
||||||
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
vec3 albedo = texture(gAlbedoSpec, texCoord).rgb;
|
||||||
|
|
@ -32,7 +33,7 @@ void main() {
|
||||||
vec3 ambient = albedo*vec3(0.1f);
|
vec3 ambient = albedo*vec3(0.1f);
|
||||||
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
vec3 viewDirection = normalize(viewPosition - fragPosition);
|
||||||
|
|
||||||
for (int i = 0; i < NR_LIGHTS; ++i)
|
for (int i = 0; i < NR_LIGHTS; i++)
|
||||||
{
|
{
|
||||||
if (lights[i].enabled == 0) continue;
|
if (lights[i].enabled == 0) continue;
|
||||||
vec3 lightDirection = lights[i].position - fragPosition;
|
vec3 lightDirection = lights[i].position - fragPosition;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ layout (location = 1) in vec2 vertexTexCoord;
|
||||||
|
|
||||||
out vec2 texCoord;
|
out vec2 texCoord;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
gl_Position = vec4(vertexPosition, 1.0);
|
gl_Position = vec4(vertexPosition, 1.0);
|
||||||
texCoord = vertexTexCoord;
|
texCoord = vertexTexCoord;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ in vec3 fragNormal;
|
||||||
uniform sampler2D diffuseTexture;
|
uniform sampler2D diffuseTexture;
|
||||||
uniform sampler2D specularTexture;
|
uniform sampler2D specularTexture;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
// store the fragment position vector in the first gbuffer texture
|
// store the fragment position vector in the first gbuffer texture
|
||||||
gPosition = fragPosition;
|
gPosition = fragPosition;
|
||||||
// also store the per-fragment normals into the gbuffer
|
// also store the per-fragment normals into the gbuffer
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ void main()
|
||||||
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
|
// Here: z = a + bi. Iterations: z -> z^2 + c = (a + bi)^2 + (c.x + c.yi) = (a^2 - b^2 + c.x) + (2ab + c.y)i
|
||||||
|
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
for (iter = 0; iter < maxIterations; ++iter)
|
for (iter = 0; iter < maxIterations; iter++)
|
||||||
{
|
{
|
||||||
float aa = a*a;
|
float aa = a*a;
|
||||||
float bb = b*b;
|
float bb = b*b;
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ uniform float ampY;
|
||||||
uniform float speedX;
|
uniform float speedX;
|
||||||
uniform float speedY;
|
uniform float speedY;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
|
{
|
||||||
float pixelWidth = 1.0/size.x;
|
float pixelWidth = 1.0/size.x;
|
||||||
float pixelHeight = 1.0/size.y;
|
float pixelHeight = 1.0/size.y;
|
||||||
float aspect = pixelHeight/pixelWidth;
|
float aspect = pixelHeight/pixelWidth;
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,13 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// GBuffer data
|
// GBuffer data
|
||||||
typedef struct GBuffer {
|
typedef struct GBuffer {
|
||||||
unsigned int framebuffer;
|
unsigned int framebufferId;
|
||||||
|
|
||||||
unsigned int positionTexture;
|
unsigned int positionTextureId;
|
||||||
unsigned int normalTexture;
|
unsigned int normalTextureId;
|
||||||
unsigned int albedoSpecTexture;
|
unsigned int albedoSpecTextureId;
|
||||||
|
|
||||||
unsigned int depthRenderbuffer;
|
unsigned int depthRenderbufferId;
|
||||||
} GBuffer;
|
} GBuffer;
|
||||||
|
|
||||||
// Deferred mode passes
|
// Deferred mode passes
|
||||||
|
|
@ -90,15 +90,10 @@ int main(void)
|
||||||
|
|
||||||
// Initialize the G-buffer
|
// Initialize the G-buffer
|
||||||
GBuffer gBuffer = { 0 };
|
GBuffer gBuffer = { 0 };
|
||||||
gBuffer.framebuffer = rlLoadFramebuffer();
|
gBuffer.framebufferId = rlLoadFramebuffer();
|
||||||
|
if (gBuffer.framebufferId == 0) TraceLog(LOG_WARNING, "Failed to create framebufferId");
|
||||||
|
|
||||||
if (!gBuffer.framebuffer)
|
rlEnableFramebuffer(gBuffer.framebufferId);
|
||||||
{
|
|
||||||
TraceLog(LOG_WARNING, "Failed to create framebuffer");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
|
||||||
|
|
||||||
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
||||||
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
||||||
|
|
@ -107,46 +102,42 @@ int main(void)
|
||||||
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios
|
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios
|
||||||
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
||||||
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`
|
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`
|
||||||
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
gBuffer.positionTextureId = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||||
|
|
||||||
// Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility
|
// Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility
|
||||||
// This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations
|
// This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations
|
||||||
gBuffer.normalTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
gBuffer.normalTextureId = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||||
|
|
||||||
// Albedo (diffuse color) and specular strength can be combined into one texture
|
// Albedo (diffuse color) and specular strength can be combined into one texture
|
||||||
// The color in RGB, and the specular strength in the alpha channel
|
// The color in RGB, and the specular strength in the alpha channel
|
||||||
gBuffer.albedoSpecTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
gBuffer.albedoSpecTextureId = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
||||||
|
|
||||||
// Activate the draw buffers for our framebuffer
|
// Activate the draw buffers for our framebufferId
|
||||||
rlActiveDrawBuffers(3);
|
rlActiveDrawBuffers(3);
|
||||||
|
|
||||||
// Now we attach our textures to the framebuffer
|
// Now we attach our textures to the framebufferId
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebufferId, gBuffer.positionTextureId, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebufferId, gBuffer.normalTextureId, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebufferId, gBuffer.albedoSpecTextureId, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
|
|
||||||
// Finally we attach the depth buffer
|
// Finally we attach the depth buffer
|
||||||
gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true);
|
gBuffer.depthRenderbufferId = rlLoadTextureDepth(screenWidth, screenHeight, true);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
rlFramebufferAttach(gBuffer.framebufferId, gBuffer.depthRenderbufferId, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
||||||
|
|
||||||
// Make sure our framebuffer is complete
|
// Make sure our framebufferId is complete
|
||||||
// NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have
|
// NOTE: rlFramebufferComplete() automatically unbinds the framebufferId, so we don't have to rlDisableFramebuffer() here
|
||||||
// to rlDisableFramebuffer() here
|
if (!rlFramebufferComplete(gBuffer.framebufferId)) TraceLog(LOG_WARNING, "Framebuffer is not complete");
|
||||||
if (!rlFramebufferComplete(gBuffer.framebuffer))
|
|
||||||
{
|
|
||||||
TraceLog(LOG_WARNING, "Framebuffer is not complete");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we initialize the sampler2D uniform's in the deferred shader
|
// Now we initialize the sampler2D uniform's in the deferred shader
|
||||||
// We do this by setting the uniform's values to the texture units that
|
// We do this by setting the uniform's values to the texture units that
|
||||||
// we later bind our g-buffer textures to
|
// we later bind our g-buffer textures to
|
||||||
rlEnableShader(deferredShader.id);
|
rlEnableShader(deferredShader.id);
|
||||||
int texUnitPosition = 0;
|
int texUnitPosition = 0;
|
||||||
int texUnitNormal = 1;
|
int texUnitNormal = 1;
|
||||||
int texUnitAlbedoSpec = 2;
|
int texUnitAlbedoSpec = 2;
|
||||||
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gPosition"), &texUnitPosition, RL_SHADER_UNIFORM_SAMPLER2D);
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gPosition"), &texUnitPosition, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gNormal"), &texUnitNormal, RL_SHADER_UNIFORM_SAMPLER2D);
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gNormal"), &texUnitNormal, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gAlbedoSpec"), &texUnitAlbedoSpec, RL_SHADER_UNIFORM_SAMPLER2D);
|
SetShaderValue(deferredShader, rlGetLocationUniform(deferredShader.id, "gAlbedoSpec"), &texUnitAlbedoSpec, RL_SHADER_UNIFORM_SAMPLER2D);
|
||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
|
|
||||||
// Assign out lighting shader to model
|
// Assign out lighting shader to model
|
||||||
|
|
@ -176,7 +167,7 @@ int main(void)
|
||||||
cubeRotations[i] = (float)(rand()%360);
|
cubeRotations[i] = (float)(rand()%360);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeferredMode mode = DEFERRED_SHADING;
|
int mode = DEFERRED_SHADING;
|
||||||
|
|
||||||
rlEnableDepthTest();
|
rlEnableDepthTest();
|
||||||
|
|
||||||
|
|
@ -215,17 +206,16 @@ int main(void)
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
// Draw to the geometry buffer by first activating it
|
// Draw to the geometry buffer by first activating it
|
||||||
rlEnableFramebuffer(gBuffer.framebuffer);
|
rlEnableFramebuffer(gBuffer.framebufferId);
|
||||||
rlClearColor(0, 0, 0, 0);
|
rlClearColor(0, 0, 0, 0);
|
||||||
rlClearScreenBuffers(); // Clear color and depth buffer
|
rlClearScreenBuffers(); // Clear color and depth buffer
|
||||||
|
|
||||||
rlDisableColorBlend();
|
rlDisableColorBlend();
|
||||||
|
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
||||||
// will not work, as they won't immediately load the shader program
|
// will not work, as they won't immediately load the shader program
|
||||||
rlEnableShader(gbufferShader.id);
|
rlEnableShader(gbufferShader.id);
|
||||||
// When drawing a model here, make sure that the material's shaders
|
// When drawing a model here, make sure that the material's shaders are set to the gbuffer shader!
|
||||||
// are set to the gbuffer shader!
|
|
||||||
DrawModel(model, Vector3Zero(), 1.0f, WHITE);
|
DrawModel(model, Vector3Zero(), 1.0f, WHITE);
|
||||||
DrawModel(cube, (Vector3) { 0.0, 1.0f, 0.0 }, 1.0f, WHITE);
|
DrawModel(cube, (Vector3) { 0.0, 1.0f, 0.0 }, 1.0f, WHITE);
|
||||||
|
|
||||||
|
|
@ -234,12 +224,12 @@ int main(void)
|
||||||
Vector3 position = cubePositions[i];
|
Vector3 position = cubePositions[i];
|
||||||
DrawModelEx(cube, position, (Vector3) { 1, 1, 1 }, cubeRotations[i], (Vector3) { CUBE_SCALE, CUBE_SCALE, CUBE_SCALE }, WHITE);
|
DrawModelEx(cube, position, (Vector3) { 1, 1, 1 }, cubeRotations[i], (Vector3) { CUBE_SCALE, CUBE_SCALE, CUBE_SCALE }, WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
rlEnableColorBlend();
|
rlEnableColorBlend();
|
||||||
|
|
||||||
// Go back to the default framebuffer (0) and draw our deferred shading
|
// Go back to the default framebufferId (0) and draw our deferred shading
|
||||||
rlDisableFramebuffer();
|
rlDisableFramebuffer();
|
||||||
rlClearScreenBuffers(); // Clear color & depth buffer
|
rlClearScreenBuffers(); // Clear color & depth buffer
|
||||||
|
|
||||||
|
|
@ -254,21 +244,21 @@ int main(void)
|
||||||
// We are binding them to locations that we earlier set in sampler2D uniforms `gPosition`, `gNormal`,
|
// We are binding them to locations that we earlier set in sampler2D uniforms `gPosition`, `gNormal`,
|
||||||
// and `gAlbedoSpec`
|
// and `gAlbedoSpec`
|
||||||
rlActiveTextureSlot(texUnitPosition);
|
rlActiveTextureSlot(texUnitPosition);
|
||||||
rlEnableTexture(gBuffer.positionTexture);
|
rlEnableTexture(gBuffer.positionTextureId);
|
||||||
rlActiveTextureSlot(texUnitNormal);
|
rlActiveTextureSlot(texUnitNormal);
|
||||||
rlEnableTexture(gBuffer.normalTexture);
|
rlEnableTexture(gBuffer.normalTextureId);
|
||||||
rlActiveTextureSlot(texUnitAlbedoSpec);
|
rlActiveTextureSlot(texUnitAlbedoSpec);
|
||||||
rlEnableTexture(gBuffer.albedoSpecTexture);
|
rlEnableTexture(gBuffer.albedoSpecTextureId);
|
||||||
|
|
||||||
// Finally, we draw a fullscreen quad to our default framebuffer
|
// Finally, we draw a fullscreen quad to our default framebufferId
|
||||||
// This will now be shaded using our deferred shader
|
// This will now be shaded using our deferred shader
|
||||||
rlLoadDrawQuad();
|
rlLoadDrawQuad();
|
||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
rlEnableColorBlend();
|
rlEnableColorBlend();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// As a last step, we now copy over the depth buffer from our g-buffer to the default framebuffer
|
// As a last step, we now copy over the depth buffer from our g-buffer to the default framebufferId
|
||||||
rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebuffer);
|
rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebufferId);
|
||||||
rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0);
|
rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0);
|
||||||
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
||||||
rlDisableFramebuffer();
|
rlDisableFramebuffer();
|
||||||
|
|
@ -290,7 +280,7 @@ int main(void)
|
||||||
case DEFERRED_POSITION:
|
case DEFERRED_POSITION:
|
||||||
{
|
{
|
||||||
DrawTextureRec((Texture2D){
|
DrawTextureRec((Texture2D){
|
||||||
.id = gBuffer.positionTexture,
|
.id = gBuffer.positionTextureId,
|
||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
@ -300,7 +290,7 @@ int main(void)
|
||||||
case DEFERRED_NORMAL:
|
case DEFERRED_NORMAL:
|
||||||
{
|
{
|
||||||
DrawTextureRec((Texture2D){
|
DrawTextureRec((Texture2D){
|
||||||
.id = gBuffer.normalTexture,
|
.id = gBuffer.normalTextureId,
|
||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
@ -310,7 +300,7 @@ int main(void)
|
||||||
case DEFERRED_ALBEDO:
|
case DEFERRED_ALBEDO:
|
||||||
{
|
{
|
||||||
DrawTextureRec((Texture2D){
|
DrawTextureRec((Texture2D){
|
||||||
.id = gBuffer.albedoSpecTexture,
|
.id = gBuffer.albedoSpecTextureId,
|
||||||
.width = screenWidth,
|
.width = screenWidth,
|
||||||
.height = screenHeight,
|
.height = screenHeight,
|
||||||
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
}, (Rectangle) { 0, 0, (float)screenWidth, (float)-screenHeight }, Vector2Zero(), RAYWHITE);
|
||||||
|
|
@ -331,18 +321,20 @@ int main(void)
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
UnloadModel(model); // Unload the models
|
// Unload the models
|
||||||
|
UnloadModel(model);
|
||||||
UnloadModel(cube);
|
UnloadModel(cube);
|
||||||
|
|
||||||
UnloadShader(deferredShader); // Unload shaders
|
// Unload shaders
|
||||||
|
UnloadShader(deferredShader);
|
||||||
UnloadShader(gbufferShader);
|
UnloadShader(gbufferShader);
|
||||||
|
|
||||||
// Unload geometry buffer and all attached textures
|
// Unload geometry buffer and all attached textures
|
||||||
rlUnloadFramebuffer(gBuffer.framebuffer);
|
rlUnloadFramebuffer(gBuffer.framebufferId);
|
||||||
rlUnloadTexture(gBuffer.positionTexture);
|
rlUnloadTexture(gBuffer.positionTextureId);
|
||||||
rlUnloadTexture(gBuffer.normalTexture);
|
rlUnloadTexture(gBuffer.normalTextureId);
|
||||||
rlUnloadTexture(gBuffer.albedoSpecTexture);
|
rlUnloadTexture(gBuffer.albedoSpecTextureId);
|
||||||
rlUnloadTexture(gBuffer.depthRenderbuffer);
|
rlUnloadTexture(gBuffer.depthRenderbufferId);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -258,8 +258,8 @@ int main(void)
|
||||||
UnloadImage(pattern);
|
UnloadImage(pattern);
|
||||||
|
|
||||||
mode = MODE_PAUSE;
|
mode = MODE_PAUSE;
|
||||||
offsetX = worldWidth*presetPatterns[preset].position.x - windowWidth/zoom/2.0f;
|
offsetX = worldWidth*presetPatterns[preset].position.x - (float)windowWidth/zoom/2.0f;
|
||||||
offsetY = worldHeight*presetPatterns[preset].position.y - windowHeight/zoom/2.0f;
|
offsetY = worldHeight*presetPatterns[preset].position.y - (float)windowHeight/zoom/2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check window draw inside world limits
|
// Check window draw inside world limits
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ int main(void)
|
||||||
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
|
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Declare Struct used to store camera locs
|
// Declare Struct used to store camera locs
|
||||||
RayLocs marchLocs = {0};
|
RayLocs marchLocs = { 0 };
|
||||||
|
|
||||||
// Fill the struct with shader locs
|
// Fill the struct with shader locs
|
||||||
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
|
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [others] example - compute shader
|
* raylib [shaders] example - rlgl compute
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 4.3 versions for compute shaders support,
|
* WARNING: This example requires raylib compiled with OpenGL 4.3 version for
|
||||||
* shaders used in this example are #version 430 (OpenGL 4.3)
|
* compute shaders support, shaders used in this example are #version 430
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|
@ -19,9 +19,10 @@
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "rlgl.h"
|
#include "rlgl.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h> // Required for: NULL
|
||||||
|
|
||||||
// IMPORTANT: This must match gol*.glsl GOL_WIDTH constant
|
// IMPORTANT: This must match gol*.glsl GOL_WIDTH constant
|
||||||
// This must be a multiple of 16 (check golLogic compute dispatch)
|
// This must be a multiple of 16 (check golLogic compute dispatch)
|
||||||
|
|
@ -57,7 +58,7 @@ int main(void)
|
||||||
const int screenWidth = GOL_WIDTH;
|
const int screenWidth = GOL_WIDTH;
|
||||||
const int screenHeight = GOL_WIDTH;
|
const int screenHeight = GOL_WIDTH;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [others] example - compute shader");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - rlgl compute");
|
||||||
|
|
||||||
const Vector2 resolution = { (float)screenWidth, (float)screenHeight };
|
const Vector2 resolution = { (float)screenWidth, (float)screenHeight };
|
||||||
unsigned int brushSize = 8;
|
unsigned int brushSize = 8;
|
||||||
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
|
@ -41,7 +41,7 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - vertex displacement");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - vertex displacement");
|
||||||
|
|
||||||
// set up camera
|
// set up camera
|
||||||
Camera camera = {0};
|
Camera camera = { 0 };
|
||||||
camera.position = (Vector3) {20.0f, 5.0f, -20.0f};
|
camera.position = (Vector3) {20.0f, 5.0f, -20.0f};
|
||||||
camera.target = (Vector3) {0.0f, 0.0f, 0.0f};
|
camera.target = (Vector3) {0.0f, 0.0f, 0.0f};
|
||||||
camera.up = (Vector3) {0.0f, 1.0f, 0.0f};
|
camera.up = (Vector3) {0.0f, 1.0f, 0.0f};
|
||||||
|
|
|
||||||
|
|
@ -46,19 +46,19 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - ball physics");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - ball physics");
|
||||||
|
|
||||||
Ball balls[MAX_BALLS] = {{
|
Ball balls[MAX_BALLS] = {{
|
||||||
.pos = { GetScreenWidth()/2, GetScreenHeight()/2 },
|
.pos = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f },
|
||||||
.vel = { 200, 200 },
|
.vel = { 200, 200 },
|
||||||
.ppos = { 0 },
|
.ppos = { 0 },
|
||||||
.radius = 40,
|
.radius = 40,
|
||||||
.friction = 0.99,
|
.friction = 0.99f,
|
||||||
.elasticity = 0.9,
|
.elasticity = 0.9f,
|
||||||
.color = BLUE,
|
.color = BLUE,
|
||||||
.grabbed = false
|
.grabbed = false
|
||||||
}};
|
}};
|
||||||
|
|
||||||
int ballCount = 1;
|
int ballCount = 1;
|
||||||
Ball *grabbedBall = NULL; // A pointer to the current ball that is grabbed
|
Ball *grabbedBall = NULL; // A pointer to the current ball that is grabbed
|
||||||
Vector2 pressOffset = {0}; // Mouse press offset relative to the ball that grabbedd
|
Vector2 pressOffset = { 0 }; // Mouse press offset relative to the ball that grabbedd
|
||||||
|
|
||||||
float gravity = 100; // World gravity
|
float gravity = 100; // World gravity
|
||||||
|
|
||||||
|
|
@ -110,11 +110,11 @@ int main(void)
|
||||||
{
|
{
|
||||||
balls[ballCount++] = (Ball){
|
balls[ballCount++] = (Ball){
|
||||||
.pos = mousePos,
|
.pos = mousePos,
|
||||||
.vel = { GetRandomValue(-300, 300), GetRandomValue(-300, 300) },
|
.vel = { (float)GetRandomValue(-300, 300), (float)GetRandomValue(-300, 300) },
|
||||||
.ppos = { 0 },
|
.ppos = { 0 },
|
||||||
.radius = 20 + GetRandomValue(0, 30),
|
.radius = 20.0f + (float)GetRandomValue(0, 30),
|
||||||
.friction = 0.99,
|
.friction = 0.99f,
|
||||||
.elasticity = 0.9,
|
.elasticity = 0.9f,
|
||||||
.color = { GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 },
|
.color = { GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 },
|
||||||
.grabbed = false
|
.grabbed = false
|
||||||
};
|
};
|
||||||
|
|
@ -126,7 +126,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ballCount; i++)
|
for (int i = 0; i < ballCount; i++)
|
||||||
{
|
{
|
||||||
if (!balls[i].grabbed) balls[i].vel = (Vector2){ GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000) };
|
if (!balls[i].grabbed) balls[i].vel = (Vector2){ (float)GetRandomValue(-2000, 2000), (float)GetRandomValue(-2000, 2000) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ int main(void)
|
||||||
for (int i = 0; i < MAX_COLORS_COUNT; i++)
|
for (int i = 0; i < MAX_COLORS_COUNT; i++)
|
||||||
{
|
{
|
||||||
colorsRecs[i].x = 20.0f + 100.0f *(i%7) + 10.0f *(i%7);
|
colorsRecs[i].x = 20.0f + 100.0f *(i%7) + 10.0f *(i%7);
|
||||||
colorsRecs[i].y = 80.0f + 100.0f *(i/7) + 10.0f *(i/7);
|
colorsRecs[i].y = 80.0f + 100.0f *((int)i/7) + 10.0f *((float)i/7);
|
||||||
colorsRecs[i].width = 100.0f;
|
colorsRecs[i].width = 100.0f;
|
||||||
colorsRecs[i].height = 100.0f;
|
colorsRecs[i].height = 100.0f;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,7 @@ static void DrawDisplaySegment(Vector2 center, int length, int thick, bool verti
|
||||||
(Vector2){ center.x + thick/2.0f, center.y - length/2.0f }, // Point 3
|
(Vector2){ center.x + thick/2.0f, center.y - length/2.0f }, // Point 3
|
||||||
(Vector2){ center.x - thick/2.0f, center.y + length/2.0f }, // Point 4
|
(Vector2){ center.x - thick/2.0f, center.y + length/2.0f }, // Point 4
|
||||||
(Vector2){ center.x + thick/2.0f, center.y + length/2.0f }, // Point 5
|
(Vector2){ center.x + thick/2.0f, center.y + length/2.0f }, // Point 5
|
||||||
(Vector2){ center.x, center.y + length/2 + thick/2.0f }, // Point 6
|
(Vector2){ center.x, center.y + (float)length/2 + thick/2.0f }, // Point 6
|
||||||
};
|
};
|
||||||
|
|
||||||
DrawTriangleStrip(segmentPointsV, 6, color);
|
DrawTriangleStrip(segmentPointsV, 6, color);
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ int main(void)
|
||||||
float totalM = m1 + m2;
|
float totalM = m1 + m2;
|
||||||
|
|
||||||
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
||||||
previousPosition.x += (screenWidth/2);
|
previousPosition.x += ((float)screenWidth/2);
|
||||||
previousPosition.y += (screenHeight/2 - 100);
|
previousPosition.y += ((float)screenHeight/2 - 100);
|
||||||
|
|
||||||
// Scale length
|
// Scale length
|
||||||
float L1 = l1*lengthScaler;
|
float L1 = l1*lengthScaler;
|
||||||
|
|
@ -105,8 +105,8 @@ int main(void)
|
||||||
|
|
||||||
// Calculate position
|
// Calculate position
|
||||||
Vector2 currentPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
Vector2 currentPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
||||||
currentPosition.x += screenWidth/2;
|
currentPosition.x += (float)screenWidth/2;
|
||||||
currentPosition.y += screenHeight/2 - 100;
|
currentPosition.y += (float)screenHeight/2 - 100;
|
||||||
|
|
||||||
// Draw to render texture
|
// Draw to render texture
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [others] example - easings testbed
|
* raylib [shapes] example - easings testbed
|
||||||
*
|
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
||||||
|
*
|
||||||
* Example contributed by Juan Miguel López (@flashback-fx) and reviewed by Ramon Santamaria (@raysan5)
|
* Example contributed by Juan Miguel López (@flashback-fx) and reviewed by Ramon Santamaria (@raysan5)
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#include "reasings.h" // Required for easing functions
|
#include "reasings.h" // Required for: easing functions
|
||||||
|
|
||||||
#define FONT_SIZE 20
|
#define FONT_SIZE 20
|
||||||
|
|
||||||
|
|
@ -26,6 +26,9 @@
|
||||||
#define D_MIN 1.0f
|
#define D_MIN 1.0f
|
||||||
#define D_MAX 10000.0f
|
#define D_MAX 10000.0f
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
// Easing types
|
// Easing types
|
||||||
enum EasingTypes {
|
enum EasingTypes {
|
||||||
EASE_LINEAR_NONE = 0,
|
EASE_LINEAR_NONE = 0,
|
||||||
|
|
@ -60,13 +63,22 @@ enum EasingTypes {
|
||||||
EASING_NONE = NUM_EASING_TYPES
|
EASING_NONE = NUM_EASING_TYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
static float NoEase(float t, float b, float c, float d); // NoEase function declaration, function used when "no easing" is selected for any axis
|
typedef struct EasingFuncs {
|
||||||
|
|
||||||
// Easing functions reference data
|
|
||||||
static const struct {
|
|
||||||
const char *name;
|
const char *name;
|
||||||
float (*func)(float, float, float, float);
|
float (*func)(float, float, float, float);
|
||||||
} Easings[] = {
|
} EasingFuncs;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Function used when "no easing" is selected for any axis
|
||||||
|
static float NoEase(float t, float b, float c, float d);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Easing functions reference data
|
||||||
|
static const EasingFuncs easings[] = {
|
||||||
[EASE_LINEAR_NONE] = { .name = "EaseLinearNone", .func = EaseLinearNone },
|
[EASE_LINEAR_NONE] = { .name = "EaseLinearNone", .func = EaseLinearNone },
|
||||||
[EASE_LINEAR_IN] = { .name = "EaseLinearIn", .func = EaseLinearIn },
|
[EASE_LINEAR_IN] = { .name = "EaseLinearIn", .func = EaseLinearIn },
|
||||||
[EASE_LINEAR_OUT] = { .name = "EaseLinearOut", .func = EaseLinearOut },
|
[EASE_LINEAR_OUT] = { .name = "EaseLinearOut", .func = EaseLinearOut },
|
||||||
|
|
@ -108,7 +120,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [others] example - easings testbed");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings testbed");
|
||||||
|
|
||||||
Vector2 ballPosition = { 100.0f, 100.0f };
|
Vector2 ballPosition = { 100.0f, 100.0f };
|
||||||
|
|
||||||
|
|
@ -157,11 +169,11 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change d (duration) value
|
// Change d (duration) value
|
||||||
if (IsKeyPressed(KEY_W) && d < D_MAX - D_STEP) d += D_STEP;
|
if (IsKeyPressed(KEY_W) && (d < D_MAX - D_STEP)) d += D_STEP;
|
||||||
else if (IsKeyPressed(KEY_Q) && d > D_MIN + D_STEP) d -= D_STEP;
|
else if (IsKeyPressed(KEY_Q) && (d > D_MIN + D_STEP)) d -= D_STEP;
|
||||||
|
|
||||||
if (IsKeyDown(KEY_S) && d < D_MAX - D_STEP_FINE) d += D_STEP_FINE;
|
if (IsKeyDown(KEY_S) && (d < D_MAX - D_STEP_FINE)) d += D_STEP_FINE;
|
||||||
else if (IsKeyDown(KEY_A) && d > D_MIN + D_STEP_FINE) d -= D_STEP_FINE;
|
else if (IsKeyDown(KEY_A) && (d > D_MIN + D_STEP_FINE)) d -= D_STEP_FINE;
|
||||||
|
|
||||||
// Play, pause and restart controls
|
// Play, pause and restart controls
|
||||||
if (IsKeyPressed(KEY_SPACE) || IsKeyPressed(KEY_T) ||
|
if (IsKeyPressed(KEY_SPACE) || IsKeyPressed(KEY_T) ||
|
||||||
|
|
@ -182,8 +194,8 @@ int main(void)
|
||||||
// Movement computation
|
// Movement computation
|
||||||
if (!paused && ((boundedT && t < d) || !boundedT))
|
if (!paused && ((boundedT && t < d) || !boundedT))
|
||||||
{
|
{
|
||||||
ballPosition.x = Easings[easingX].func(t, 100.0f, 700.0f - 170.0f, d);
|
ballPosition.x = easings[easingX].func(t, 100.0f, 700.0f - 170.0f, d);
|
||||||
ballPosition.y = Easings[easingY].func(t, 100.0f, 400.0f - 170.0f, d);
|
ballPosition.y = easings[easingY].func(t, 100.0f, 400.0f - 170.0f, d);
|
||||||
t += 1.0f;
|
t += 1.0f;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -195,8 +207,8 @@ int main(void)
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Draw information text
|
// Draw information text
|
||||||
DrawText(TextFormat("Easing x: %s", Easings[easingX].name), 20, FONT_SIZE, FONT_SIZE, LIGHTGRAY);
|
DrawText(TextFormat("Easing x: %s", easings[easingX].name), 20, FONT_SIZE, FONT_SIZE, LIGHTGRAY);
|
||||||
DrawText(TextFormat("Easing y: %s", Easings[easingY].name), 20, FONT_SIZE*2, FONT_SIZE, LIGHTGRAY);
|
DrawText(TextFormat("Easing y: %s", easings[easingY].name), 20, FONT_SIZE*2, FONT_SIZE, LIGHTGRAY);
|
||||||
DrawText(TextFormat("t (%c) = %.2f d = %.2f", (boundedT == true)? 'b' : 'u', t, d), 20, FONT_SIZE*3, FONT_SIZE, LIGHTGRAY);
|
DrawText(TextFormat("t (%c) = %.2f d = %.2f", (boundedT == true)? 'b' : 'u', t, d), 20, FONT_SIZE*3, FONT_SIZE, LIGHTGRAY);
|
||||||
|
|
||||||
// Draw instructions text
|
// Draw instructions text
|
||||||
|
|
@ -220,7 +232,9 @@ int main(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
// NoEase function, used when "no easing" is selected for any axis
|
// NoEase function, used when "no easing" is selected for any axis
|
||||||
// It just ignores all parameters besides b
|
// It just ignores all parameters besides b
|
||||||
static float NoEase(float t, float b, float c, float d)
|
static float NoEase(float t, float b, float c, float d)
|
||||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
196
examples/shapes/shapes_hilbert_curve.c
Normal file
|
|
@ -0,0 +1,196 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [shapes] example - hilbert curve
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.6, last time updated with raylib 5.6
|
||||||
|
*
|
||||||
|
* Example contributed by Hamza RAHAL (@hmz-rhl) 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) 2025 Hamza RAHAL (@hmz-rhl)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
#include "raygui.h"
|
||||||
|
|
||||||
|
#include <stdlib.h> // Required for: calloc(), free()
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static Vector2 *LoadHilbertPath(int order, float size, int *strokeCount);
|
||||||
|
static void UnloadHilbertPath(Vector2 *hilbertPath);
|
||||||
|
static Vector2 ComputeHilbertStep(int order, int index);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - hilbert curve");
|
||||||
|
|
||||||
|
int order = 2;
|
||||||
|
float size = GetScreenHeight();
|
||||||
|
int strokeCount = 0;
|
||||||
|
Vector2 *hilbertPath = LoadHilbertPath(order, size, &strokeCount);
|
||||||
|
|
||||||
|
int prevOrder = order;
|
||||||
|
int prevSize = (int)size; // NOTE: Size from slider is float but for comparison we use int
|
||||||
|
int counter = 0;
|
||||||
|
float thick = 2.0f;
|
||||||
|
bool animate = true;
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Check if order or size have changed to regenerate
|
||||||
|
// NOTE: Size from slider is float but for comparison we use int
|
||||||
|
if ((prevOrder != order) || (prevSize != (int)size))
|
||||||
|
{
|
||||||
|
UnloadHilbertPath(hilbertPath);
|
||||||
|
hilbertPath = LoadHilbertPath(order, size, &strokeCount);
|
||||||
|
|
||||||
|
if (animate) counter = 0;
|
||||||
|
else counter = strokeCount;
|
||||||
|
|
||||||
|
prevOrder = order;
|
||||||
|
prevSize = size;
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
if (counter < strokeCount)
|
||||||
|
{
|
||||||
|
// Draw Hilbert path animation, one stroke every frame
|
||||||
|
for (int i = 1; i <= counter; i++)
|
||||||
|
{
|
||||||
|
DrawLineEx(hilbertPath[i], hilbertPath[i - 1], thick, ColorFromHSV(((float)i/strokeCount)*360.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Draw full Hilbert path
|
||||||
|
for (int i = 1; i < strokeCount; i++)
|
||||||
|
{
|
||||||
|
DrawLineEx(hilbertPath[i], hilbertPath[i - 1], thick, ColorFromHSV(((float)i/strokeCount)*360.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw UI using raygui
|
||||||
|
GuiCheckBox((Rectangle){ 450, 50, 20, 20 }, "ANIMATE GENERATION ON CHANGE", &animate);
|
||||||
|
GuiSpinner((Rectangle){ 585, 100, 180, 30 }, "HILBERT CURVE ORDER: ", &order, 2, 8, false);
|
||||||
|
GuiSlider((Rectangle){ 524, 150, 240, 24 }, "THICKNESS: ", NULL, &thick, 1.0f, 10.0f);
|
||||||
|
GuiSlider((Rectangle){ 524, 190, 240, 24 }, "TOTAL SIZE: ", NULL, &size, 10.0f, GetScreenHeight()*1.5f);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadHilbertPath(hilbertPath);
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Load the whole Hilbert Path (including each U and their link)
|
||||||
|
static Vector2 *LoadHilbertPath(int order, float size, int *strokeCount)
|
||||||
|
{
|
||||||
|
int N = 1 << order;
|
||||||
|
float len = size/N;
|
||||||
|
*strokeCount = N*N;
|
||||||
|
|
||||||
|
Vector2 *hilbertPath = (Vector2 *)RL_CALLOC(*strokeCount, sizeof(Vector2));
|
||||||
|
|
||||||
|
for (int i = 0; i < *strokeCount; i++)
|
||||||
|
{
|
||||||
|
hilbertPath[i] = ComputeHilbertStep(order, i);
|
||||||
|
hilbertPath[i].x = hilbertPath[i].x*len + len/2.0f;
|
||||||
|
hilbertPath[i].y = hilbertPath[i].y*len + len/2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hilbertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unload Hilbert path data
|
||||||
|
static void UnloadHilbertPath(Vector2 *hilbertPath)
|
||||||
|
{
|
||||||
|
RL_FREE(hilbertPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute Hilbert path U positions
|
||||||
|
static Vector2 ComputeHilbertStep(int order, int index)
|
||||||
|
{
|
||||||
|
// Hilbert points base pattern
|
||||||
|
static const Vector2 hilbertPoints[4] = {
|
||||||
|
[0] = { .x = 0, .y = 0 },
|
||||||
|
[1] = { .x = 0, .y = 1 },
|
||||||
|
[2] = { .x = 1, .y = 1 },
|
||||||
|
[3] = { .x = 1, .y = 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
int hilbertIndex = index&3;
|
||||||
|
Vector2 vect = hilbertPoints[hilbertIndex];
|
||||||
|
float temp = 0.0f;
|
||||||
|
int len = 0;
|
||||||
|
|
||||||
|
for (int j = 1; j < order; j++)
|
||||||
|
{
|
||||||
|
index = index >> 2;
|
||||||
|
hilbertIndex = index&3;
|
||||||
|
len = 1 << j;
|
||||||
|
|
||||||
|
switch (hilbertIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
temp = vect.x;
|
||||||
|
vect.x = vect.y;
|
||||||
|
vect.y = temp;
|
||||||
|
} break;
|
||||||
|
case 2: vect.x += len;
|
||||||
|
case 1: vect.y += len; break;
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
temp = len - 1 - vect.x;
|
||||||
|
vect.x = 2*len - 1 - vect.y;
|
||||||
|
vect.y = temp;
|
||||||
|
} break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return vect;
|
||||||
|
}
|
||||||
BIN
examples/shapes/shapes_hilbert_curve.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
|
|
@ -50,9 +50,9 @@ int main(void)
|
||||||
int symmetry = 6;
|
int symmetry = 6;
|
||||||
float angle = 360.0f/(float)symmetry;
|
float angle = 360.0f/(float)symmetry;
|
||||||
float thickness = 3.0f;
|
float thickness = 3.0f;
|
||||||
Rectangle resetButtonRec = { screenWidth - 55, 5, 50, 25 };
|
Rectangle resetButtonRec = { screenWidth - 55.0f, 5.0f, 50, 25 };
|
||||||
Rectangle backButtonRec = { screenWidth - 55, screenHeight - 30, 25, 25 };
|
Rectangle backButtonRec = { screenWidth - 55.0f, screenHeight - 30.0f, 25, 25 };
|
||||||
Rectangle nextButtonRec = { screenWidth - 30, screenHeight - 30, 25, 25 };
|
Rectangle nextButtonRec = { screenWidth - 30.0f, screenHeight - 30.0f, 25, 25 };
|
||||||
Vector2 mousePos = { 0 };
|
Vector2 mousePos = { 0 };
|
||||||
Vector2 prevMousePos = { 0 };
|
Vector2 prevMousePos = { 0 };
|
||||||
Vector2 scaleVector = { 1.0f, -1.0f };
|
Vector2 scaleVector = { 1.0f, -1.0f };
|
||||||
|
|
|
||||||
|
|
@ -185,12 +185,12 @@ static void BuildProductionStep(PenroseLSystem *ls)
|
||||||
char *newProduction = (char *)RL_MALLOC(sizeof(char)*STR_MAX_SIZE);
|
char *newProduction = (char *)RL_MALLOC(sizeof(char)*STR_MAX_SIZE);
|
||||||
newProduction[0] = '\0';
|
newProduction[0] = '\0';
|
||||||
|
|
||||||
int productionLength = strnlen(ls->production, STR_MAX_SIZE);
|
int productionLength = (int)strnlen(ls->production, STR_MAX_SIZE);
|
||||||
|
|
||||||
for (int i = 0; i < productionLength; i++)
|
for (int i = 0; i < productionLength; i++)
|
||||||
{
|
{
|
||||||
char step = ls->production[i];
|
char step = ls->production[i];
|
||||||
int remainingSpace = STR_MAX_SIZE - strnlen(newProduction, STR_MAX_SIZE) - 1;
|
int remainingSpace = STR_MAX_SIZE - (int)strnlen(newProduction, STR_MAX_SIZE) - 1;
|
||||||
switch (step)
|
switch (step)
|
||||||
{
|
{
|
||||||
case 'W': strncat(newProduction, ls->ruleW, remainingSpace); break;
|
case 'W': strncat(newProduction, ls->ruleW, remainingSpace); break;
|
||||||
|
|
@ -201,7 +201,7 @@ static void BuildProductionStep(PenroseLSystem *ls)
|
||||||
{
|
{
|
||||||
if (step != 'F')
|
if (step != 'F')
|
||||||
{
|
{
|
||||||
int t = strnlen(newProduction, STR_MAX_SIZE);
|
int t = (int)strnlen(newProduction, STR_MAX_SIZE);
|
||||||
newProduction[t] = step;
|
newProduction[t] = step;
|
||||||
newProduction[t + 1] = '\0';
|
newProduction[t + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
@ -218,7 +218,7 @@ static void BuildProductionStep(PenroseLSystem *ls)
|
||||||
// Draw penrose tile lines
|
// Draw penrose tile lines
|
||||||
static void DrawPenroseLSystem(PenroseLSystem *ls)
|
static void DrawPenroseLSystem(PenroseLSystem *ls)
|
||||||
{
|
{
|
||||||
Vector2 screenCenter = { GetScreenWidth()/2, GetScreenHeight()/2 };
|
Vector2 screenCenter = { GetScreenWidth()/2.0f, GetScreenHeight()/2.0f };
|
||||||
|
|
||||||
TurtleState turtle = {
|
TurtleState turtle = {
|
||||||
.origin = { 0 },
|
.origin = { 0 },
|
||||||
|
|
@ -245,7 +245,7 @@ static void DrawPenroseLSystem(PenroseLSystem *ls)
|
||||||
Vector2 startPosScreen = { startPosWorld.x + screenCenter.x, startPosWorld.y + screenCenter.y };
|
Vector2 startPosScreen = { startPosWorld.x + screenCenter.x, startPosWorld.y + screenCenter.y };
|
||||||
Vector2 endPosScreen = { turtle.origin.x + screenCenter.x, turtle.origin.y + screenCenter.y };
|
Vector2 endPosScreen = { turtle.origin.x + screenCenter.x, turtle.origin.y + screenCenter.y };
|
||||||
|
|
||||||
DrawLineEx(startPosScreen, endPosScreen, 2, Fade(BLACK, 0.2));
|
DrawLineEx(startPosScreen, endPosScreen, 2, Fade(BLACK, 0.2f));
|
||||||
}
|
}
|
||||||
|
|
||||||
repeats = 1;
|
repeats = 1;
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ int main(void)
|
||||||
bool showPercentages = false;
|
bool showPercentages = false;
|
||||||
bool showDonut = false;
|
bool showDonut = false;
|
||||||
int hoveredSlice = -1;
|
int hoveredSlice = -1;
|
||||||
Rectangle scrollPanelBounds = {0};
|
Rectangle scrollPanelBounds = { 0 };
|
||||||
Vector2 scrollContentOffset = {0};
|
Vector2 scrollContentOffset = { 0 };
|
||||||
Rectangle view = { 0 };
|
Rectangle view = { 0 };
|
||||||
|
|
||||||
// UI layout parameters
|
// UI layout parameters
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ int main(void)
|
||||||
|
|
||||||
// Set the text (using markdown!)
|
// Set the text (using markdown!)
|
||||||
char text[64] = "Hello ~~World~~ in 3D!";
|
char text[64] = "Hello ~~World~~ in 3D!";
|
||||||
Vector3 tbox = {0};
|
Vector3 tbox = { 0 };
|
||||||
int layers = 1;
|
int layers = 1;
|
||||||
int quads = 0;
|
int quads = 0;
|
||||||
float layerDistance = 0.01f;
|
float layerDistance = 0.01f;
|
||||||
|
|
@ -133,7 +133,7 @@ int main(void)
|
||||||
Shader alphaDiscard = LoadShader(NULL, TextFormat("resources/shaders/glsl%i/alpha_discard.fs", GLSL_VERSION));
|
Shader alphaDiscard = LoadShader(NULL, TextFormat("resources/shaders/glsl%i/alpha_discard.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Array filled with multiple random colors (when multicolor mode is set)
|
// Array filled with multiple random colors (when multicolor mode is set)
|
||||||
Color multi[TEXT_MAX_LAYERS] = {0};
|
Color multi[TEXT_MAX_LAYERS] = { 0 };
|
||||||
|
|
||||||
DisableCursor(); // Limit cursor to relative movement inside the window
|
DisableCursor(); // Limit cursor to relative movement inside the window
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,8 @@ int main(void)
|
||||||
if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0);
|
if (currentFont == 0) textSize = MeasureTextEx(fontDefault, msg, fontSize, 0);
|
||||||
else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0);
|
else textSize = MeasureTextEx(fontSDF, msg, fontSize, 0);
|
||||||
|
|
||||||
fontPosition.x = GetScreenWidth()/2 - textSize.x/2;
|
fontPosition.x = (float)GetScreenWidth()/2 - textSize.x/2;
|
||||||
fontPosition.y = GetScreenHeight()/2 - textSize.y/2 + 80;
|
fontPosition.y = (float)GetScreenHeight()/2 - textSize.y/2 + 80;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -178,14 +178,14 @@ static void DrawTextStyled(Font font, const char *text, Vector2 position, float
|
||||||
// Convert hex color text into actual Color
|
// Convert hex color text into actual Color
|
||||||
unsigned int colHexValue = strtoul(colHexText, NULL, 16);
|
unsigned int colHexValue = strtoul(colHexText, NULL, 16);
|
||||||
if (text[i - 1] == 'c')
|
if (text[i - 1] == 'c')
|
||||||
{
|
{
|
||||||
colFront = GetColor(colHexValue);
|
colFront = GetColor(colHexValue);
|
||||||
colFront.a *= (float)color.a/255.0f;
|
//colFront.a *= (unsigned char)(colFront.a*(float)color.a/255.0f); // TODO: Review
|
||||||
}
|
}
|
||||||
else if (text[i - 1] == 'b')
|
else if (text[i - 1] == 'b')
|
||||||
{
|
{
|
||||||
colBack = GetColor(colHexValue);
|
colBack = GetColor(colHexValue);
|
||||||
colBack.a *= (float)color.a/255.0f;
|
//colBack.a *= (unsigned char)(colFront.a*(float)color.a/255.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
i += (colHexCount + 1); // Skip color value retrieved and ']'
|
i += (colHexCount + 1); // Skip color value retrieved and ']'
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
{
|
{
|
||||||
if (!wordWrap)
|
if (!wordWrap)
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -234,7 +234,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
{
|
{
|
||||||
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -258,7 +258,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
|
|
||||||
if (wordWrap && (i == endLine))
|
if (wordWrap && (i == endLine))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
startLine = endLine;
|
startLine = endLine;
|
||||||
endLine = -1;
|
endLine = -1;
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ int main(void)
|
||||||
TextParticle textParticles[MAX_TEXT_PARTICLES] = { 0 };
|
TextParticle textParticles[MAX_TEXT_PARTICLES] = { 0 };
|
||||||
int particleCount = 0;
|
int particleCount = 0;
|
||||||
TextParticle *grabbedTextParticle = NULL;
|
TextParticle *grabbedTextParticle = NULL;
|
||||||
Vector2 pressOffset = {0};
|
Vector2 pressOffset = { 0 };
|
||||||
|
|
||||||
PrepareFirstTextParticle("raylib => fun videogames programming!", textParticles, &particleCount);
|
PrepareFirstTextParticle("raylib => fun videogames programming!", textParticles, &particleCount);
|
||||||
|
|
||||||
|
|
@ -133,7 +133,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < particleCount; i++)
|
for (int i = 0; i < particleCount; i++)
|
||||||
{
|
{
|
||||||
if (!textParticles[i].grabbed) textParticles[i].vel = (Vector2){ GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000) };
|
if (!textParticles[i].grabbed) textParticles[i].vel = (Vector2){ (float)GetRandomValue(-2000, 2000), (float)GetRandomValue(-2000, 2000) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,9 +233,9 @@ int main(void)
|
||||||
for (int i = 0; i < particleCount; i++)
|
for (int i = 0; i < particleCount; i++)
|
||||||
{
|
{
|
||||||
TextParticle *tp = &textParticles[i];
|
TextParticle *tp = &textParticles[i];
|
||||||
DrawRectangle(tp->rect.x-tp->borderWidth, tp->rect.y-tp->borderWidth, tp->rect.width+tp->borderWidth*2, tp->rect.height+tp->borderWidth*2, BLACK);
|
DrawRectangleRec((Rectangle) { tp->rect.x - tp->borderWidth, tp->rect.y - tp->borderWidth, tp->rect.width + tp->borderWidth * 2, tp->rect.height + tp->borderWidth * 2 }, BLACK);
|
||||||
DrawRectangleRec(tp->rect, tp->color);
|
DrawRectangleRec(tp->rect, tp->color);
|
||||||
DrawText(tp->text, tp->rect.x+tp->padding, tp->rect.y+tp->padding, FONT_SIZE, BLACK);
|
DrawText(tp->text, (int)(tp->rect.x+tp->padding), (int)(tp->rect.y+tp->padding), FONT_SIZE, BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawText("grab a text particle by pressing with the mouse and throw it by releasing", 10, 10, 10, DARKGRAY);
|
DrawText("grab a text particle by pressing with the mouse and throw it by releasing", 10, 10, 10, DARKGRAY);
|
||||||
|
|
@ -265,8 +265,8 @@ void PrepareFirstTextParticle(const char* text, TextParticle *tps, int *particle
|
||||||
{
|
{
|
||||||
tps[0] = CreateTextParticle(
|
tps[0] = CreateTextParticle(
|
||||||
text,
|
text,
|
||||||
GetScreenWidth()/2,
|
GetScreenWidth()/2.0f,
|
||||||
GetScreenHeight()/2,
|
GetScreenHeight()/2.0f,
|
||||||
RAYWHITE
|
RAYWHITE
|
||||||
);
|
);
|
||||||
*particleCount = 1;
|
*particleCount = 1;
|
||||||
|
|
@ -277,12 +277,12 @@ TextParticle CreateTextParticle(const char *text, float x, float y, Color color)
|
||||||
TextParticle tp = {
|
TextParticle tp = {
|
||||||
.text = "",
|
.text = "",
|
||||||
.rect = { x, y, 30, 30 },
|
.rect = { x, y, 30, 30 },
|
||||||
.vel = { GetRandomValue(-200, 200), GetRandomValue(-200, 200) },
|
.vel = { (float)GetRandomValue(-200, 200), (float)GetRandomValue(-200, 200) },
|
||||||
.ppos = { 0 },
|
.ppos = { 0 },
|
||||||
.padding = 5.0f,
|
.padding = 5.0f,
|
||||||
.borderWidth = 5.0f,
|
.borderWidth = 5.0f,
|
||||||
.friction = 0.99,
|
.friction = 0.99f,
|
||||||
.elasticity = 0.9,
|
.elasticity = 0.9f,
|
||||||
.color = color,
|
.color = color,
|
||||||
.grabbed = false
|
.grabbed = false
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ int main(void)
|
||||||
DrawTriangle(a, b, c, emoji[selected].color);
|
DrawTriangle(a, b, c, emoji[selected].color);
|
||||||
|
|
||||||
// Draw the main text message
|
// Draw the main text message
|
||||||
Rectangle textRect = { msgRect.x + horizontalPadding/2, msgRect.y + verticalPadding/2, msgRect.width - horizontalPadding, msgRect.height };
|
Rectangle textRect = { msgRect.x + (float)horizontalPadding/2, msgRect.y + (float)verticalPadding/2, msgRect.width - horizontalPadding, msgRect.height };
|
||||||
DrawTextBoxed(*font, messages[message].text, textRect, (float)font->baseSize, 1.0f, true, WHITE);
|
DrawTextBoxed(*font, messages[message].text, textRect, (float)font->baseSize, 1.0f, true, WHITE);
|
||||||
|
|
||||||
// Draw the info text below the main message
|
// Draw the info text below the main message
|
||||||
|
|
@ -421,7 +421,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
{
|
{
|
||||||
if (!wordWrap)
|
if (!wordWrap)
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -429,7 +429,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
{
|
{
|
||||||
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -453,7 +453,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
||||||
|
|
||||||
if (wordWrap && (i == endLine))
|
if (wordWrap && (i == endLine))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + (float)font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
startLine = endLine;
|
startLine = endLine;
|
||||||
endLine = -1;
|
endLine = -1;
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
#include "raymath.h" // Required for: Lerp()
|
#include "raymath.h" // Required for: Lerp()
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef enum TextAlignment {
|
typedef enum TextAlignment {
|
||||||
TEXT_ALIGN_LEFT = 0,
|
TEXT_ALIGN_LEFT = 0,
|
||||||
TEXT_ALIGN_TOP = 0,
|
TEXT_ALIGN_TOP = 0,
|
||||||
|
|
@ -43,7 +41,7 @@ int main(void)
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - words alignment");
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - words alignment");
|
||||||
|
|
||||||
// Define the rectangle we will draw the text in
|
// Define the rectangle we will draw the text in
|
||||||
Rectangle textContainerRect = (Rectangle){ screenWidth/2-screenWidth/4, screenHeight/2-screenHeight/3, screenWidth/2, screenHeight*2/3 };
|
Rectangle textContainerRect = (Rectangle){ (float)screenWidth/2-(float)screenWidth/4, (float)screenHeight/2-(float)screenHeight/3, (float)screenWidth/2, (float)screenHeight*2/3 };
|
||||||
|
|
||||||
// Some text to display the current alignment
|
// Some text to display the current alignment
|
||||||
const char *textAlignNameH[] = { "Left", "Centre", "Right" };
|
const char *textAlignNameH[] = { "Left", "Centre", "Right" };
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,10 @@ int main(void)
|
||||||
bunnies[i].position.x += bunnies[i].speed.x;
|
bunnies[i].position.x += bunnies[i].speed.x;
|
||||||
bunnies[i].position.y += bunnies[i].speed.y;
|
bunnies[i].position.y += bunnies[i].speed.y;
|
||||||
|
|
||||||
if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) ||
|
if (((bunnies[i].position.x + (float)texBunny.width/2) > GetScreenWidth()) ||
|
||||||
((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1;
|
((bunnies[i].position.x + (float)texBunny.width/2) < 0)) bunnies[i].speed.x *= -1;
|
||||||
if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) ||
|
if (((bunnies[i].position.y + (float)texBunny.height/2) > GetScreenHeight()) ||
|
||||||
((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1;
|
((bunnies[i].position.y + (float)texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ int main(void)
|
||||||
|
|
||||||
// If the mouse is on this preset, highlight it
|
// If the mouse is on this preset, highlight it
|
||||||
if (mouseInCell == i + 8)
|
if (mouseInCell == i + 8)
|
||||||
DrawRectangleLinesEx((Rectangle) { 2 + (presetsSizeX + 2.0f)*(i/2),
|
DrawRectangleLinesEx((Rectangle) { 2 + (presetsSizeX + 2.0f)*((float)i/2),
|
||||||
(presetsSizeY + 2.0f)*(i%2),
|
(presetsSizeY + 2.0f)*(i%2),
|
||||||
presetsSizeX + 4.0f, presetsSizeY + 4.0f }, 3, RED);
|
presetsSizeX + 4.0f, presetsSizeY + 4.0f }, 3, RED);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ int main(void)
|
||||||
// at a smaller size (one pixel per tile) and scale it on drawing with bilinear filtering
|
// at a smaller size (one pixel per tile) and scale it on drawing with bilinear filtering
|
||||||
RenderTexture2D fogOfWar = LoadRenderTexture(map.tilesX, map.tilesY);
|
RenderTexture2D fogOfWar = LoadRenderTexture(map.tilesX, map.tilesY);
|
||||||
SetTextureFilter(fogOfWar.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(fogOfWar.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
SetTextureWrap(fogOfWar.texture, TEXTURE_WRAP_CLAMP);
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -93,8 +94,8 @@ int main(void)
|
||||||
for (unsigned int i = 0; i < map.tilesX*map.tilesY; i++) if (map.tileFog[i] == 1) map.tileFog[i] = 2;
|
for (unsigned int i = 0; i < map.tilesX*map.tilesY; i++) if (map.tileFog[i] == 1) map.tileFog[i] = 2;
|
||||||
|
|
||||||
// Get current tile position from player pixel position
|
// Get current tile position from player pixel position
|
||||||
playerTileX = (int)((playerPosition.x + MAP_TILE_SIZE/2)/MAP_TILE_SIZE);
|
playerTileX = (int)((playerPosition.x + (float)MAP_TILE_SIZE/2)/MAP_TILE_SIZE);
|
||||||
playerTileY = (int)((playerPosition.y + MAP_TILE_SIZE/2)/MAP_TILE_SIZE);
|
playerTileY = (int)((playerPosition.y + (float)MAP_TILE_SIZE/2)/MAP_TILE_SIZE);
|
||||||
|
|
||||||
// Check visibility and update fog
|
// Check visibility and update fog
|
||||||
// NOTE: We check tilemap limits to avoid processing tiles out-of-array-bounds (it could crash program)
|
// NOTE: We check tilemap limits to avoid processing tiles out-of-array-bounds (it could crash program)
|
||||||
|
|
|
||||||
209
examples/textures/textures_framebuffer_rendering.c
Normal file
|
|
@ -0,0 +1,209 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [textures] example - framebuffer rendering
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.6, last time updated with raylib 5.6
|
||||||
|
*
|
||||||
|
* Example contributed by Jack Boakes (@jackboakes) 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) 2026 Jack Boakes (@jackboakes)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module Functions Declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void DrawCameraPrism(Camera3D camera, float aspect, Color color);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
const int splitWidth = screenWidth/2;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - framebuffer rendering");
|
||||||
|
|
||||||
|
// Camera to look at the 3D world
|
||||||
|
Camera3D subjectCamera = { 0 };
|
||||||
|
subjectCamera.position = (Vector3){ 5.0f, 5.0f, 5.0f };
|
||||||
|
subjectCamera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
subjectCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
subjectCamera.fovy = 45.0f;
|
||||||
|
subjectCamera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
// Camera to observe the subject camera and 3D world
|
||||||
|
Camera3D observerCamera = { 0 };
|
||||||
|
observerCamera.position = (Vector3){ 10.0f, 10.0f, 10.0f };
|
||||||
|
observerCamera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
observerCamera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
observerCamera.fovy = 45.0f;
|
||||||
|
observerCamera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
// Set up render textures
|
||||||
|
RenderTexture2D observerTarget = LoadRenderTexture(splitWidth, screenHeight);
|
||||||
|
Rectangle observerSource = { 0.0f, 0.0f, (float)observerTarget.texture.width, -(float)observerTarget.texture.height };
|
||||||
|
Rectangle observerDest = { 0.0f, 0.0f, (float)splitWidth, (float)screenHeight };
|
||||||
|
|
||||||
|
RenderTexture2D subjectTarget = LoadRenderTexture(splitWidth, screenHeight);
|
||||||
|
Rectangle subjectSource = { 0.0f, 0.0f, (float)subjectTarget.texture.width, -(float)subjectTarget.texture.height };
|
||||||
|
Rectangle subjectDest = { (float)splitWidth, 0.0f, (float)splitWidth, (float)screenHeight };
|
||||||
|
const float textureAspectRatio = (float)subjectTarget.texture.width/(float)subjectTarget.texture.height;
|
||||||
|
|
||||||
|
// Rectangles for cropping render texture
|
||||||
|
const float captureSize = 128.0f;
|
||||||
|
Rectangle cropSource = { (subjectTarget.texture.width - captureSize)/2.0f, (subjectTarget.texture.height - captureSize)/2.0f, captureSize, -captureSize };
|
||||||
|
Rectangle cropDest = { splitWidth + 20, 20, captureSize, captureSize};
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
DisableCursor();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&observerCamera, CAMERA_FREE);
|
||||||
|
UpdateCamera(&subjectCamera, CAMERA_ORBITAL);
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_R)) observerCamera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
// Build LHS observer view texture
|
||||||
|
BeginTextureMode(observerTarget);
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(observerCamera);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
DrawCube((Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, 2.0f, 2.0f, GOLD);
|
||||||
|
DrawCubeWires((Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, 2.0f, 2.0f, PINK);
|
||||||
|
DrawCameraPrism(subjectCamera, textureAspectRatio, GREEN);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawText("Observer View", 10, observerTarget.texture.height - 30, 20, BLACK);
|
||||||
|
DrawText("WASD + Mouse to Move", 10, 10, 20, DARKGRAY);
|
||||||
|
DrawText("Scroll to Zoom", 10, 30, 20, DARKGRAY);
|
||||||
|
DrawText("R to Reset Observer Target", 10, 50, 20, DARKGRAY);
|
||||||
|
|
||||||
|
EndTextureMode();
|
||||||
|
|
||||||
|
// Build RHS subject view texture
|
||||||
|
BeginTextureMode(subjectTarget);
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(subjectCamera);
|
||||||
|
|
||||||
|
DrawCube((Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, 2.0f, 2.0f, GOLD);
|
||||||
|
DrawCubeWires((Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, 2.0f, 2.0f, PINK);
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
DrawRectangleLines((subjectTarget.texture.width - captureSize)/2, (subjectTarget.texture.height - captureSize)/2, captureSize, captureSize, GREEN);
|
||||||
|
DrawText("Subject View", 10, subjectTarget.texture.height - 30, 20, BLACK);
|
||||||
|
|
||||||
|
EndTextureMode();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
|
// Draw observer texture LHS
|
||||||
|
DrawTexturePro(observerTarget.texture, observerSource, observerDest, (Vector2){0.0f, 0.0f }, 0.0f, WHITE);
|
||||||
|
|
||||||
|
// Draw subject texture RHS
|
||||||
|
DrawTexturePro(subjectTarget.texture, subjectSource, subjectDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
|
||||||
|
|
||||||
|
// Draw the small crop overlay on top
|
||||||
|
DrawTexturePro(subjectTarget.texture, cropSource, cropDest, (Vector2){ 0.0f, 0.0f }, 0.0f, WHITE);
|
||||||
|
DrawRectangleLinesEx(cropDest, 2, BLACK);
|
||||||
|
|
||||||
|
// Draw split screen divider line
|
||||||
|
DrawLine(splitWidth, 0, splitWidth, screenHeight, BLACK);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadRenderTexture(observerTarget);
|
||||||
|
UnloadRenderTexture(subjectTarget);
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static void DrawCameraPrism(Camera3D camera, float aspect, Color color)
|
||||||
|
{
|
||||||
|
float length = Vector3Distance(camera.position, camera.target);
|
||||||
|
// Define the 4 corners of the camera's prism plane sliced at the target in Normalized Device Coordinates
|
||||||
|
Vector3 planeNDC[4] = {
|
||||||
|
{ -1.0f, -1.0f, 1.0f }, // Bottom Left
|
||||||
|
{ 1.0f, -1.0f, 1.0f }, // Bottom Right
|
||||||
|
{ 1.0f, 1.0f, 1.0f }, // Top Right
|
||||||
|
{ -1.0f, 1.0f, 1.0f } // Top Left
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build the matrices
|
||||||
|
Matrix view = GetCameraMatrix(camera);
|
||||||
|
Matrix proj = MatrixPerspective(camera.fovy * DEG2RAD, aspect, 0.05f, length);
|
||||||
|
// Combine view and projection so we can reverse the full camera transform
|
||||||
|
Matrix viewProj = MatrixMultiply(view, proj);
|
||||||
|
// Invert the view-projection matrix to unproject points from NDC space back into world space
|
||||||
|
Matrix inverseViewProj = MatrixInvert(viewProj);
|
||||||
|
|
||||||
|
// Transform the 4 plane corners from NDC into world space
|
||||||
|
Vector3 corners[4];
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
float x = planeNDC[i].x;
|
||||||
|
float y = planeNDC[i].y;
|
||||||
|
float z = planeNDC[i].z;
|
||||||
|
|
||||||
|
// Multiply NDC position by the inverse view-projection matrix
|
||||||
|
// This produces a homogeneous (x, y, z, w) position in world space
|
||||||
|
float vx = inverseViewProj.m0*x + inverseViewProj.m4*y + inverseViewProj.m8*z + inverseViewProj.m12;
|
||||||
|
float vy = inverseViewProj.m1*x + inverseViewProj.m5*y + inverseViewProj.m9*z + inverseViewProj.m13;
|
||||||
|
float vz = inverseViewProj.m2*x + inverseViewProj.m6*y + inverseViewProj.m10*z + inverseViewProj.m14;
|
||||||
|
float vw = inverseViewProj.m3*x + inverseViewProj.m7*y + inverseViewProj.m11*z + inverseViewProj.m15;
|
||||||
|
|
||||||
|
corners[i] = (Vector3){ vx/vw, vy/vw, vz/vw };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the far plane sliced at the target
|
||||||
|
DrawLine3D(corners[0], corners[1], color);
|
||||||
|
DrawLine3D(corners[1], corners[2], color);
|
||||||
|
DrawLine3D(corners[2], corners[3], color);
|
||||||
|
DrawLine3D(corners[3], corners[0], color);
|
||||||
|
|
||||||
|
// Draw the prism lines from the far plane to the camera position
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
DrawLine3D(camera.position, corners[i], color);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
examples/textures/textures_framebuffer_rendering.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
|
|
@ -156,7 +156,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
DrawRectangleRec(toggleRecs[i], ((i == currentProcess) || (i == mouseHoverRec)) ? SKYBLUE : LIGHTGRAY);
|
DrawRectangleRec(toggleRecs[i], ((i == currentProcess) || (i == mouseHoverRec)) ? SKYBLUE : LIGHTGRAY);
|
||||||
DrawRectangleLines((int)toggleRecs[i].x, (int) toggleRecs[i].y, (int) toggleRecs[i].width, (int) toggleRecs[i].height, ((i == currentProcess) || (i == mouseHoverRec)) ? BLUE : GRAY);
|
DrawRectangleLines((int)toggleRecs[i].x, (int) toggleRecs[i].y, (int) toggleRecs[i].width, (int) toggleRecs[i].height, ((i == currentProcess) || (i == mouseHoverRec)) ? BLUE : GRAY);
|
||||||
DrawText( processText[i], (int)( toggleRecs[i].x + toggleRecs[i].width/2 - MeasureText(processText[i], 10)/2), (int) toggleRecs[i].y + 11, 10, ((i == currentProcess) || (i == mouseHoverRec)) ? DARKBLUE : DARKGRAY);
|
DrawText( processText[i], (int)( toggleRecs[i].x + toggleRecs[i].width/2 - (float)MeasureText(processText[i], 10)/2), (int) toggleRecs[i].y + 11, 10, ((i == currentProcess) || (i == mouseHoverRec)) ? DARKBLUE : DARKGRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
|
DrawTexture(texture, screenWidth - texture.width - 60, screenHeight/2 - texture.height/2, WHITE);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ int main(void)
|
||||||
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
|
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||||
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||||
|
|
||||||
Vector2 position = { (float)(screenWidth/2 - texture.width/2), (float)(screenHeight/2 - texture.height/2 - 20) };
|
Vector2 position = { (float)screenWidth/2 - (float)texture.width/2, (float)screenHeight/2 - (float)texture.height/2 - 20 };
|
||||||
|
|
||||||
bool showFont = false;
|
bool showFont = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ int main(void)
|
||||||
float hue = t*t;
|
float hue = t*t;
|
||||||
float saturation = t;
|
float saturation = t;
|
||||||
float value = t;
|
float value = t;
|
||||||
|
|
||||||
palette[i] = ColorFromHSV(250.0f + 150.0f*hue, saturation, value);
|
palette[i] = ColorFromHSV(250.0f + 150.0f*hue, saturation, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,11 +67,9 @@ int main(void)
|
||||||
// Grow flameRoot
|
// Grow flameRoot
|
||||||
for (int x = 2; x < flameWidth; x++)
|
for (int x = 2; x < flameWidth; x++)
|
||||||
{
|
{
|
||||||
unsigned short flame = flameRootBuffer[x];
|
int flame = (int)flameRootBuffer[x];
|
||||||
if (flame == 255) continue;
|
|
||||||
flame += GetRandomValue(0, 2);
|
flame += GetRandomValue(0, 2);
|
||||||
if (flame > 255) flame = 255;
|
flameRootBuffer[x] = (flame > 255)? 255: (unsigned char)flame;
|
||||||
flameRootBuffer[x] = flame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer flameRoot to indexBuffer
|
// Transfer flameRoot to indexBuffer
|
||||||
|
|
@ -83,8 +82,7 @@ int main(void)
|
||||||
// Clear top row, because it can't move any higher
|
// Clear top row, because it can't move any higher
|
||||||
for (int x = 0; x < imageWidth; x++)
|
for (int x = 0; x < imageWidth; x++)
|
||||||
{
|
{
|
||||||
if (indexBuffer[x] == 0) continue;
|
if (indexBuffer[x] != 0) indexBuffer[x] = 0;
|
||||||
indexBuffer[x] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip top row, it is already cleared
|
// Skip top row, it is already cleared
|
||||||
|
|
@ -94,18 +92,22 @@ int main(void)
|
||||||
{
|
{
|
||||||
unsigned int i = x + y*imageWidth;
|
unsigned int i = x + y*imageWidth;
|
||||||
unsigned char colorIndex = indexBuffer[i];
|
unsigned char colorIndex = indexBuffer[i];
|
||||||
if (colorIndex == 0) continue;
|
|
||||||
|
|
||||||
// Move pixel a row above
|
if (colorIndex != 0)
|
||||||
indexBuffer[i] = 0;
|
{
|
||||||
int moveX = GetRandomValue(0, 2) - 1;
|
// Move pixel a row above
|
||||||
int newX = x + moveX;
|
indexBuffer[i] = 0;
|
||||||
if (newX < 0 || newX >= imageWidth) continue;
|
int moveX = GetRandomValue(0, 2) - 1;
|
||||||
|
int newX = x + moveX;
|
||||||
|
|
||||||
unsigned int iabove = i - imageWidth + moveX;
|
if ((newX > 0) && (newX < imageWidth))
|
||||||
int decay = GetRandomValue(0, 3);
|
{
|
||||||
colorIndex -= (decay < colorIndex)? decay : colorIndex;
|
unsigned int iabove = i - imageWidth + moveX;
|
||||||
indexBuffer[iabove] = colorIndex;
|
int decay = GetRandomValue(0, 3);
|
||||||
|
colorIndex -= (decay < colorIndex)? decay : colorIndex;
|
||||||
|
indexBuffer[iabove] = colorIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,6 +119,7 @@ int main(void)
|
||||||
unsigned int i = x + y*imageWidth;
|
unsigned int i = x + y*imageWidth;
|
||||||
unsigned char colorIndex = indexBuffer[i];
|
unsigned char colorIndex = indexBuffer[i];
|
||||||
Color col = palette[colorIndex];
|
Color col = palette[colorIndex];
|
||||||
|
|
||||||
ImageDrawPixel(&screenImage, x, y, col);
|
ImageDrawPixel(&screenImage, x, y, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ int main(void)
|
||||||
Rectangle sourceRec = { 0, 0, (float)button.width, frameHeight };
|
Rectangle sourceRec = { 0, 0, (float)button.width, frameHeight };
|
||||||
|
|
||||||
// Define button bounds on screen
|
// Define button bounds on screen
|
||||||
Rectangle btnBounds = { screenWidth/2.0f - button.width/2.0f, screenHeight/2.0f - button.height/NUM_FRAMES/2.0f, (float)button.width, frameHeight };
|
Rectangle btnBounds = { screenWidth/2.0f - button.width/2.0f, screenHeight/2.0f - (float)button.height/NUM_FRAMES/2.0f, (float)button.width, frameHeight };
|
||||||
|
|
||||||
int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED
|
int btnState = 0; // Button state: 0-NORMAL, 1-MOUSE_HOVER, 2-PRESSED
|
||||||
bool btnAction = false; // Button action should be activated
|
bool btnAction = false; // Button action should be activated
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ int main(void)
|
||||||
Texture2D explosion = LoadTexture("resources/explosion.png");
|
Texture2D explosion = LoadTexture("resources/explosion.png");
|
||||||
|
|
||||||
// Init variables for animation
|
// Init variables for animation
|
||||||
float frameWidth = (float)(explosion.width/NUM_FRAMES_PER_LINE); // Sprite one frame rectangle width
|
float frameWidth = (float)explosion.width/NUM_FRAMES_PER_LINE; // Sprite one frame rectangle width
|
||||||
float frameHeight = (float)(explosion.height/NUM_LINES); // Sprite one frame rectangle height
|
float frameHeight = (float)explosion.height/NUM_LINES; // Sprite one frame rectangle height
|
||||||
int currentFrame = 0;
|
int currentFrame = 0;
|
||||||
int currentLine = 0;
|
int currentLine = 0;
|
||||||
|
|
||||||
|
|
|
||||||