Merge branch 'raysan5:master' into master
This commit is contained in:
commit
ad75005015
|
|
@ -3,7 +3,7 @@
|
||||||
#
|
#
|
||||||
# You may wish to alter this file to override the set of languages analyzed,
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
# or to provide custom queries or build logic.
|
# or to provide custom queries or build logic.
|
||||||
name: "CodeQL"
|
name: Analyze raylib with CodeQL
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Android
|
name: Build raylib - Android
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: CMakeBuilds
|
name: Build raylib CMake - Windows+Linux
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Linux Examples
|
name: Build raylib examples - Linux
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Windows Examples
|
name: Build raylib examples - Windows
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Linux
|
name: Build raylib - Linux
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: macOS
|
name: Build raylib - macOS
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: WebAssembly
|
name: Build raylib - WebAssembly
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
name: Windows
|
name: Build raylib - Windows
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
@ -1,37 +1,37 @@
|
||||||
name: Parse raylib API
|
name: Parse raylib API
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- "src/raylib.h"
|
- "src/raylib.h"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Update parse files
|
- name: Update parse files
|
||||||
working-directory: tools/parser
|
working-directory: tools/parser
|
||||||
run: |
|
run: |
|
||||||
make raylib_api
|
make raylib_api
|
||||||
mv raylib_api.* output
|
mv raylib_api.* output
|
||||||
|
|
||||||
- name: Diff parse files
|
- name: Diff parse files
|
||||||
id: diff
|
id: diff
|
||||||
run: |
|
run: |
|
||||||
git add -N parser
|
git add -N parser
|
||||||
git diff --name-only --exit-code
|
git diff --name-only --exit-code
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Commit parse files
|
- name: Commit parse files
|
||||||
if: steps.diff.outcome == 'failure'
|
if: steps.diff.outcome == 'failure'
|
||||||
run: |
|
run: |
|
||||||
set -x
|
set -x
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.name "github-actions[bot]"
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
git add parser
|
git add tools/parser
|
||||||
git commit -m "Update raylib_api.* by CI"
|
git commit -m "Update raylib_api.* by CI"
|
||||||
git push
|
git push
|
||||||
72
.github/workflows/update_examples.yml
vendored
Normal file
72
.github/workflows/update_examples.yml
vendored
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
name: Update examples collection
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- 'examples/**'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'examples/**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup emsdk
|
||||||
|
uses: mymindstorm/setup-emsdk@v14
|
||||||
|
with:
|
||||||
|
version: 'latest'
|
||||||
|
actions-cache-folder: 'emsdk-cache'
|
||||||
|
|
||||||
|
- name: Clone raylib.com repo to update files
|
||||||
|
run: |
|
||||||
|
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/raysan5/raylib.com.git
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Build and run rexm tool (requires GNU Makefile)
|
||||||
|
# "rexm update" validates and updates all required examples in raylib and even raylib.com repos,
|
||||||
|
# note that it calls examples/Makefile.Web internally, so it requires [make] tool available
|
||||||
|
run: |
|
||||||
|
sudo apt-get update && sudo apt-get install -y libopengl0 libglu1-mesa libx11-dev libxrandr-dev libxcursor-dev libxi-dev libxinerama-dev libgl1-mesa-dev libglu1-mesa-dev
|
||||||
|
cd "${{ github.workspace }}/src"
|
||||||
|
make PLATFORM=PLATFORM_DESKTOP
|
||||||
|
sudo make install
|
||||||
|
make clean
|
||||||
|
make PLATFORM=PLATFORM_WEB
|
||||||
|
cd ../tools/rexm/
|
||||||
|
make
|
||||||
|
export REXM_EXAMPLES_BASE_PATH="${{ github.workspace }}/examples"
|
||||||
|
export REXM_EXAMPLES_WEB_PATH="${{ github.workspace }}/raylib.com/examples"
|
||||||
|
export REXM_EXAMPLES_TEMPLATE_FILE_PATH="${{ github.workspace }}/examples/examples_template.c"
|
||||||
|
export REXM_EXAMPLES_TEMPLATE_SCREENSHOT_PATH="${{ github.workspace }}/examples/examples_template.png"
|
||||||
|
export REXM_EXAMPLES_COLLECTION_FILE_PATH="${{ github.workspace }}/examples/examples_list.txt"
|
||||||
|
export REXM_EXAMPLES_VS2022_SLN_FILE="${{ github.workspace }}/projects/VS2022/raylib.sln"
|
||||||
|
export EMSDK_PATH="${{ github.workspace }}/emsdk-cache/emsdk-main"
|
||||||
|
./rexm update
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Commit changes to raylib repo (DISABLED)
|
||||||
|
if: github.event_name == 'push' && false
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
git config --global user.name "github-actions[bot]"
|
||||||
|
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add -A
|
||||||
|
git commit -m "Update examples collection" || echo "git exited with code 1, nothing changed"
|
||||||
|
git push
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Push changes to raylib.com repo (DISABLED)
|
||||||
|
if: github.event_name == 'push' && false
|
||||||
|
run: |
|
||||||
|
cd raylib.com
|
||||||
|
git add -A
|
||||||
|
git commit -m "Update web examples" || echo "git exited with code 1, nothing changed"
|
||||||
|
git push origin
|
||||||
|
shell: bash
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -113,5 +113,9 @@ docgen_tmp/
|
||||||
|
|
||||||
# Tools stuff
|
# Tools stuff
|
||||||
tools/parser/raylib_parser
|
tools/parser/raylib_parser
|
||||||
tools/rexm/VS2022
|
tools/rexm/rexm.exe
|
||||||
tools/rexm/rexm
|
tools/rexm/rexm
|
||||||
|
|
||||||
|
# CI
|
||||||
|
emsdk-cache/
|
||||||
|
raylib.com/
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [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-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/Not-Nik/raylib-zig) | **5.5** | [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 |
|
||||||
| [raylib-zig-bindings](https://github.com/L-Briand/raylib-zig-bindings) | **5.0** | [Zig](https://ziglang.org) | Zlib |
|
| [raylib-zig-bindings](https://github.com/L-Briand/raylib-zig-bindings) | **5.0** | [Zig](https://ziglang.org) | Zlib |
|
||||||
| [hare-raylib](https://git.sr.ht/~evantj/hare-raylib) | **auto** | [Hare](https://harelang.org) | Zlib |
|
| [hare-raylib](https://git.sr.ht/~evantj/hare-raylib) | **auto** | [Hare](https://harelang.org) | Zlib |
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Local variables | lowerCase | `Vector2 playerPosition = { 0 };`
|
||||||
Global variables | lowerCase | `bool windowReady = false;`
|
Global variables | lowerCase | `bool windowReady = false;`
|
||||||
Constants | lowerCase | `const int maxValue = 8;`
|
Constants | lowerCase | `const int maxValue = 8;`
|
||||||
Pointers | MyType *pointer | `Texture2D *array = NULL;`
|
Pointers | MyType *pointer | `Texture2D *array = NULL;`
|
||||||
float values | always x.xf | `float gravity = 10.0f`
|
float values | always x.xf | `float gravity = 10.0f` (avoid `10.f`)
|
||||||
Operators | value1*value2 | `int product = value*6;`
|
Operators | value1*value2 | `int product = value*6;`
|
||||||
Operators | value1/value2 | `int division = value/4;`
|
Operators | value1/value2 | `int division = value/4;`
|
||||||
Operators | value1 + value2 | `int sum = value + 10;`
|
Operators | value1 + value2 | `int sum = value + 10;`
|
||||||
|
|
@ -72,19 +72,19 @@ void SomeFunction()
|
||||||
**If proposing new functions, please try to use a clear naming for function-name and functions-parameters, in case of doubt, open an issue for discussion.**
|
**If proposing new functions, please try to use a clear naming for function-name and functions-parameters, in case of doubt, open an issue for discussion.**
|
||||||
|
|
||||||
## Files and Directories Naming Conventions
|
## Files and Directories Naming Conventions
|
||||||
|
|
||||||
- Directories will be named using `snake_case`: `resources/models`, `resources/fonts`
|
- Directories will be named using `snake_case`: `resources/models`, `resources/fonts`
|
||||||
|
|
||||||
- Files will be named using `snake_case`: `main_title.png`, `cubicmap.png`, `sound.wav`
|
- Files will be named using `snake_case`: `main_title.png`, `cubicmap.png`, `sound.wav`
|
||||||
|
|
||||||
_NOTE: Avoid any space or special character in the files/dir naming!_
|
_NOTE: Avoid any space or special character in the files/dir naming!_
|
||||||
|
|
||||||
## Games/Examples Directories Organization Conventions
|
## Games/Examples Directories Organization Conventions
|
||||||
|
|
||||||
- Data files should be organized by context and usage in the game, think about the loading requirements for data and put all the resources that need to be loaded at the same time together.
|
- Data files should be organized by context and usage in the game, think about the loading requirements for data and put all the resources that need to be loaded at the same time together.
|
||||||
- Use descriptive names for the files, it would be perfect if just reading the name of the file, it was possible to know what is that file and where fits in the game.
|
- Use descriptive names for the files, it would be perfect if just reading the name of the file, it was possible to know what is that file and where fits in the game.
|
||||||
- Here is an example, note that some resources require to be loaded all at once while other require to be loaded only at initialization (gui, font).
|
- Here is an example, note that some resources require to be loaded all at once while other require to be loaded only at initialization (gui, font).
|
||||||
|
|
||||||
```
|
```
|
||||||
resources/audio/fx/long_jump.wav
|
resources/audio/fx/long_jump.wav
|
||||||
resources/audio/music/main_theme.ogg
|
resources/audio/music/main_theme.ogg
|
||||||
|
|
|
||||||
80
build.zig
80
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.13.0";
|
const min_ver = "0.15.1";
|
||||||
|
|
||||||
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";
|
||||||
|
|
@ -99,26 +99,32 @@ const config_h_flags = outer: {
|
||||||
break :outer flags[0..i].*;
|
break :outer flags[0..i].*;
|
||||||
};
|
};
|
||||||
|
|
||||||
fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
|
pub fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, options: Options) !*std.Build.Step.Compile {
|
||||||
var raylib_flags_arr = std.ArrayList([]const u8).init(b.allocator);
|
var raylib_flags_arr: std.ArrayList([]const u8) = .empty;
|
||||||
defer raylib_flags_arr.deinit();
|
defer raylib_flags_arr.deinit(b.allocator);
|
||||||
|
|
||||||
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
try raylib_flags_arr.appendSlice(
|
||||||
"-std=gnu99",
|
b.allocator,
|
||||||
"-D_GNU_SOURCE",
|
&[_][]const u8{
|
||||||
"-DGL_SILENCE_DEPRECATION=199309L",
|
"-std=gnu99",
|
||||||
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
"-D_GNU_SOURCE",
|
||||||
});
|
"-DGL_SILENCE_DEPRECATION=199309L",
|
||||||
|
"-fno-sanitize=undefined", // https://github.com/raysan5/raylib/issues/3674
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (options.shared) {
|
if (options.shared) {
|
||||||
try raylib_flags_arr.appendSlice(&[_][]const u8{
|
try raylib_flags_arr.appendSlice(
|
||||||
"-fPIC",
|
b.allocator,
|
||||||
"-DBUILD_LIBTYPE_SHARED",
|
&[_][]const u8{
|
||||||
});
|
"-fPIC",
|
||||||
|
"-DBUILD_LIBTYPE_SHARED",
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a flag indiciating the use of a custom `config.h`
|
// Sets a flag indiciating the use of a custom `config.h`
|
||||||
try raylib_flags_arr.append("-DEXTERNAL_CONFIG_FLAGS");
|
try raylib_flags_arr.append(b.allocator, "-DEXTERNAL_CONFIG_FLAGS");
|
||||||
if (options.config.len > 0) {
|
if (options.config.len > 0) {
|
||||||
// Splits a space-separated list of config flags into multiple flags
|
// Splits a space-separated list of config flags into multiple flags
|
||||||
//
|
//
|
||||||
|
|
@ -128,7 +134,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
|
|
||||||
// Apply config flags supplied by the user
|
// Apply config flags supplied by the user
|
||||||
while (config_iter.next()) |config_flag|
|
while (config_iter.next()) |config_flag|
|
||||||
try raylib_flags_arr.append(config_flag);
|
try raylib_flags_arr.append(b.allocator, config_flag);
|
||||||
|
|
||||||
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
|
// Apply all relevant configs from `src/config.h` *except* the user-specified ones
|
||||||
//
|
//
|
||||||
|
|
@ -146,11 +152,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, append default value from config.h to compile flags
|
// Otherwise, append default value from config.h to compile flags
|
||||||
try raylib_flags_arr.append(flag);
|
try raylib_flags_arr.append(b.allocator, flag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Set default config if no custome config got set
|
// Set default config if no custome config got set
|
||||||
try raylib_flags_arr.appendSlice(&config_h_flags);
|
try raylib_flags_arr.appendSlice(b.allocator, &config_h_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
const raylib = b.addLibrary(.{
|
const raylib = b.addLibrary(.{
|
||||||
|
|
@ -168,28 +174,28 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
raylib.addIncludePath(b.path("src/external/glfw/include"));
|
raylib.addIncludePath(b.path("src/external/glfw/include"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var c_source_files = try std.ArrayList([]const u8).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", "src/utils.c" });
|
||||||
|
|
||||||
if (options.rshapes) {
|
if (options.rshapes) {
|
||||||
try c_source_files.append("src/rshapes.c");
|
try c_source_files.append(b.allocator, "src/rshapes.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RSHAPES");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RSHAPES");
|
||||||
}
|
}
|
||||||
if (options.rtextures) {
|
if (options.rtextures) {
|
||||||
try c_source_files.append("src/rtextures.c");
|
try c_source_files.append(b.allocator, "src/rtextures.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXTURES");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RTEXTURES");
|
||||||
}
|
}
|
||||||
if (options.rtext) {
|
if (options.rtext) {
|
||||||
try c_source_files.append("src/rtext.c");
|
try c_source_files.append(b.allocator, "src/rtext.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RTEXT");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RTEXT");
|
||||||
}
|
}
|
||||||
if (options.rmodels) {
|
if (options.rmodels) {
|
||||||
try c_source_files.append("src/rmodels.c");
|
try c_source_files.append(b.allocator, "src/rmodels.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RMODELS");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RMODELS");
|
||||||
}
|
}
|
||||||
if (options.raudio) {
|
if (options.raudio) {
|
||||||
try c_source_files.append("src/raudio.c");
|
try c_source_files.append(b.allocator, "src/raudio.c");
|
||||||
try raylib_flags_arr.append("-DSUPPORT_MODULE_RAUDIO");
|
try raylib_flags_arr.append(b.allocator, "-DSUPPORT_MODULE_RAUDIO");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.opengl_version != .auto) {
|
if (options.opengl_version != .auto) {
|
||||||
|
|
@ -200,7 +206,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
switch (target.result.os.tag) {
|
switch (target.result.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
switch (options.platform) {
|
switch (options.platform) {
|
||||||
.glfw => try c_source_files.append("src/rglfw.c"),
|
.glfw => try c_source_files.append(b.allocator, "src/rglfw.c"),
|
||||||
.rgfw, .sdl, .drm, .android => {},
|
.rgfw, .sdl, .drm, .android => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,14 +267,14 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
raylib.addSystemIncludePath(.{ .cwd_relative = androidAsmPath });
|
raylib.addSystemIncludePath(.{ .cwd_relative = androidAsmPath });
|
||||||
raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath });
|
raylib.addSystemIncludePath(.{ .cwd_relative = androidGluePath });
|
||||||
|
|
||||||
var libcData = std.ArrayList(u8).init(b.allocator);
|
var libcData: std.ArrayList(u8) = .empty;
|
||||||
const writer = libcData.writer();
|
var aw: std.Io.Writer.Allocating = .fromArrayList(b.allocator, &libcData);
|
||||||
try (std.zig.LibCInstallation{
|
try (std.zig.LibCInstallation{
|
||||||
.include_dir = androidIncludePath,
|
.include_dir = androidIncludePath,
|
||||||
.sys_include_dir = androidIncludePath,
|
.sys_include_dir = androidIncludePath,
|
||||||
.crt_dir = androidApiSpecificPath,
|
.crt_dir = androidApiSpecificPath,
|
||||||
}).render(writer);
|
}).render(&aw.writer);
|
||||||
const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice());
|
const libcFile = b.addWriteFiles().add("android-libc.txt", try libcData.toOwnedSlice(b.allocator));
|
||||||
raylib.setLibCFile(libcFile);
|
raylib.setLibCFile(libcFile);
|
||||||
|
|
||||||
if (options.opengl_version == .auto) {
|
if (options.opengl_version == .auto) {
|
||||||
|
|
@ -279,7 +285,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
|
|
||||||
setDesktopPlatform(raylib, .android);
|
setDesktopPlatform(raylib, .android);
|
||||||
} else {
|
} else {
|
||||||
try c_source_files.append("src/rglfw.c");
|
try c_source_files.append(b.allocator, "src/rglfw.c");
|
||||||
|
|
||||||
if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) {
|
if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) {
|
||||||
raylib.root_module.addCMacro("_GLFW_X11", "");
|
raylib.root_module.addCMacro("_GLFW_X11", "");
|
||||||
|
|
@ -320,7 +326,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("rglfw.c");
|
try c_source_files.append(b.allocator, "rglfw.c");
|
||||||
raylib.linkSystemLibrary("GL");
|
raylib.linkSystemLibrary("GL");
|
||||||
raylib.linkSystemLibrary("rt");
|
raylib.linkSystemLibrary("rt");
|
||||||
raylib.linkSystemLibrary("dl");
|
raylib.linkSystemLibrary("dl");
|
||||||
|
|
@ -343,7 +349,7 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
|
||||||
}
|
}
|
||||||
|
|
||||||
// On macos rglfw.c include Objective-C files.
|
// On macos rglfw.c include Objective-C files.
|
||||||
try raylib_flags_arr.append("-ObjC");
|
try raylib_flags_arr.append(b.allocator, "-ObjC");
|
||||||
raylib.root_module.addCSourceFile(.{
|
raylib.root_module.addCSourceFile(.{
|
||||||
.file = b.path("src/rglfw.c"),
|
.file = b.path("src/rglfw.c"),
|
||||||
.flags = raylib_flags_arr.items,
|
.flags = raylib_flags_arr.items,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
.{
|
.{
|
||||||
.name = .raylib,
|
.name = .raylib,
|
||||||
.version = "5.5.0",
|
.version = "5.5.0",
|
||||||
.minimum_zig_version = "0.14.0",
|
.minimum_zig_version = "0.15.1",
|
||||||
|
|
||||||
.fingerprint = 0x13035e5cb8bc1ac2, // Changing this has security and trust implications.
|
.fingerprint = 0x13035e5cb8bc1ac2, // Changing this has security and trust implications.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -507,6 +507,7 @@ CORE = \
|
||||||
core/core_3d_camera_free \
|
core/core_3d_camera_free \
|
||||||
core/core_3d_camera_mode \
|
core/core_3d_camera_mode \
|
||||||
core/core_3d_camera_split_screen \
|
core/core_3d_camera_split_screen \
|
||||||
|
core/core_3d_camera_fps \
|
||||||
core/core_3d_picking \
|
core/core_3d_picking \
|
||||||
core/core_automation_events \
|
core/core_automation_events \
|
||||||
core/core_basic_screen_manager \
|
core/core_basic_screen_manager \
|
||||||
|
|
@ -598,6 +599,7 @@ TEXT = \
|
||||||
text/text_raylib_fonts \
|
text/text_raylib_fonts \
|
||||||
text/text_rectangle_bounds \
|
text/text_rectangle_bounds \
|
||||||
text/text_unicode \
|
text/text_unicode \
|
||||||
|
text/text_unicode_ranges \
|
||||||
text/text_writing_anim
|
text/text_writing_anim
|
||||||
|
|
||||||
MODELS = \
|
MODELS = \
|
||||||
|
|
@ -639,7 +641,7 @@ SHADERS = \
|
||||||
shaders/shaders_mesh_instancing \
|
shaders/shaders_mesh_instancing \
|
||||||
shaders/shaders_model_shader \
|
shaders/shaders_model_shader \
|
||||||
shaders/shaders_multi_sample2d \
|
shaders/shaders_multi_sample2d \
|
||||||
shaders/shaders_normalmap \
|
shaders/shaders_normal_map \
|
||||||
shaders/shaders_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching \
|
shaders/shaders_raymarching \
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ USE_WAYLAND_DISPLAY ?= FALSE
|
||||||
BUILD_WEB_ASYNCIFY ?= TRUE
|
BUILD_WEB_ASYNCIFY ?= TRUE
|
||||||
BUILD_WEB_SHELL ?= $(RAYLIB_PATH)/src/shell.html
|
BUILD_WEB_SHELL ?= $(RAYLIB_PATH)/src/shell.html
|
||||||
BUILD_WEB_HEAP_SIZE ?= 134217728
|
BUILD_WEB_HEAP_SIZE ?= 134217728
|
||||||
BUILD_WEB_RESOURCES ?= TRUE
|
BUILD_WEB_RESOURCES ?= FALSE
|
||||||
BUILD_WEB_RESOURCES_PATH ?= $(dir $<)resources@resources
|
BUILD_WEB_RESOURCES_PATH ?= $(dir $<)resources@resources
|
||||||
# Use WebGL2 backend (OpenGL 3.0)
|
# Use WebGL2 backend (OpenGL 3.0)
|
||||||
# WARNING: Requires raylib compiled with GRAPHICS_API_OPENGL_ES3
|
# WARNING: Requires raylib compiled with GRAPHICS_API_OPENGL_ES3
|
||||||
|
|
@ -507,6 +507,7 @@ CORE = \
|
||||||
core/core_3d_camera_free \
|
core/core_3d_camera_free \
|
||||||
core/core_3d_camera_mode \
|
core/core_3d_camera_mode \
|
||||||
core/core_3d_camera_split_screen \
|
core/core_3d_camera_split_screen \
|
||||||
|
core/core_3d_camera_fps \
|
||||||
core/core_3d_picking \
|
core/core_3d_picking \
|
||||||
core/core_automation_events \
|
core/core_automation_events \
|
||||||
core/core_basic_screen_manager \
|
core/core_basic_screen_manager \
|
||||||
|
|
@ -598,6 +599,7 @@ TEXT = \
|
||||||
text/text_raylib_fonts \
|
text/text_raylib_fonts \
|
||||||
text/text_rectangle_bounds \
|
text/text_rectangle_bounds \
|
||||||
text/text_unicode \
|
text/text_unicode \
|
||||||
|
text/text_unicode_ranges \
|
||||||
text/text_writing_anim
|
text/text_writing_anim
|
||||||
|
|
||||||
MODELS = \
|
MODELS = \
|
||||||
|
|
@ -639,7 +641,7 @@ SHADERS = \
|
||||||
shaders/shaders_mesh_instancing \
|
shaders/shaders_mesh_instancing \
|
||||||
shaders/shaders_model_shader \
|
shaders/shaders_model_shader \
|
||||||
shaders/shaders_multi_sample2d \
|
shaders/shaders_multi_sample2d \
|
||||||
shaders/shaders_normalmap \
|
shaders/shaders_normal_map \
|
||||||
shaders/shaders_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching \
|
shaders/shaders_raymarching \
|
||||||
|
|
@ -702,6 +704,9 @@ core/core_3d_camera_mode: core/core_3d_camera_mode.c
|
||||||
core/core_3d_camera_split_screen: core/core_3d_camera_split_screen.c
|
core/core_3d_camera_split_screen: core/core_3d_camera_split_screen.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
core/core_3d_camera_fps: core/core_3d_camera_fps.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
core/core_3d_picking: core/core_3d_picking.c
|
core/core_3d_picking: core/core_3d_picking.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
||||||
|
|
@ -916,8 +921,7 @@ textures/textures_logo_raylib: textures/textures_logo_raylib.c
|
||||||
--preload-file textures/resources/raylib_logo.png@resources/raylib_logo.png
|
--preload-file textures/resources/raylib_logo.png@resources/raylib_logo.png
|
||||||
|
|
||||||
textures/textures_mouse_painting: textures/textures_mouse_painting.c
|
textures/textures_mouse_painting: textures/textures_mouse_painting.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
--preload-file textures/my_amazing_texture_painting.png@my_amazing_texture_painting.png
|
|
||||||
|
|
||||||
textures/textures_npatch_drawing: textures/textures_npatch_drawing.c
|
textures/textures_npatch_drawing: textures/textures_npatch_drawing.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
|
|
@ -996,14 +1000,14 @@ text/text_input_box: text/text_input_box.c
|
||||||
|
|
||||||
text/text_raylib_fonts: text/text_raylib_fonts.c
|
text/text_raylib_fonts: text/text_raylib_fonts.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
--preload-file text/resources/fonts/alagard.png@resources/fonts/alagard.png \
|
--preload-file text/resources/sprite_fonts/alagard.png@resources/sprite_fonts/alagard.png \
|
||||||
--preload-file text/resources/fonts/pixelplay.png@resources/fonts/pixelplay.png \
|
--preload-file text/resources/sprite_fonts/pixelplay.png@resources/sprite_fonts/pixelplay.png \
|
||||||
--preload-file text/resources/fonts/mecha.png@resources/fonts/mecha.png \
|
--preload-file text/resources/sprite_fonts/mecha.png@resources/sprite_fonts/mecha.png \
|
||||||
--preload-file text/resources/fonts/setback.png@resources/fonts/setback.png \
|
--preload-file text/resources/sprite_fonts/setback.png@resources/sprite_fonts/setback.png \
|
||||||
--preload-file text/resources/fonts/romulus.png@resources/fonts/romulus.png \
|
--preload-file text/resources/sprite_fonts/romulus.png@resources/sprite_fonts/romulus.png \
|
||||||
--preload-file text/resources/fonts/pixantiqua.png@resources/fonts/pixantiqua.png \
|
--preload-file text/resources/sprite_fonts/pixantiqua.png@resources/sprite_fonts/pixantiqua.png \
|
||||||
--preload-file text/resources/fonts/alpha_beta.png@resources/fonts/alpha_beta.png \
|
--preload-file text/resources/sprite_fonts/alpha_beta.png@resources/sprite_fonts/alpha_beta.png \
|
||||||
--preload-file text/resources/fonts/jupiter_crash.png@resources/fonts/jupiter_crash.png
|
--preload-file text/resources/sprite_fonts/jupiter_crash.png@resources/sprite_fonts/jupiter_crash.png
|
||||||
|
|
||||||
text/text_rectangle_bounds: text/text_rectangle_bounds.c
|
text/text_rectangle_bounds: text/text_rectangle_bounds.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||||
|
|
@ -1014,6 +1018,10 @@ text/text_unicode: text/text_unicode.c
|
||||||
--preload-file text/resources/noto_cjk.fnt@resources/noto_cjk.fnt \
|
--preload-file text/resources/noto_cjk.fnt@resources/noto_cjk.fnt \
|
||||||
--preload-file text/resources/symbola.fnt@resources/symbola.fnt
|
--preload-file text/resources/symbola.fnt@resources/symbola.fnt
|
||||||
|
|
||||||
|
text/text_unicode_ranges: text/text_unicode_ranges.c
|
||||||
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
|
||||||
|
--preload-file text/resources/NotoSansTC-Regular.ttf@resources/NotoSansTC-Regular.ttf
|
||||||
|
|
||||||
text/text_writing_anim: text/text_writing_anim.c
|
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)
|
||||||
|
|
||||||
|
|
@ -1202,7 +1210,7 @@ shaders/shaders_multi_sample2d: shaders/shaders_multi_sample2d.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/color_mix.fs@resources/shaders/glsl100/color_mix.fs
|
--preload-file shaders/resources/shaders/glsl100/color_mix.fs@resources/shaders/glsl100/color_mix.fs
|
||||||
|
|
||||||
shaders/shaders_normalmap: shaders/shaders_normalmap.c
|
shaders/shaders_normal_map: shaders/shaders_normal_map.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/normalmap.vs@resources/shaders/glsl100/normalmap.vs \
|
--preload-file shaders/resources/shaders/glsl100/normalmap.vs@resources/shaders/glsl100/normalmap.vs \
|
||||||
--preload-file shaders/resources/shaders/glsl100/normalmap.fs@resources/shaders/glsl100/normalmap.fs \
|
--preload-file shaders/resources/shaders/glsl100/normalmap.fs@resources/shaders/glsl100/normalmap.fs \
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,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: 160]
|
## EXAMPLES COLLECTION [TOTAL: 162]
|
||||||
|
|
||||||
### category: core [36]
|
### category: core [37]
|
||||||
|
|
||||||
Examples using raylib[core](../src/rcore.c) platform functionality like window creation, inputs, drawing modes and system functionality.
|
Examples using raylib[core](../src/rcore.c) platform functionality like window creation, inputs, drawing modes and system functionality.
|
||||||
|
|
||||||
|
|
@ -40,6 +40,7 @@ Examples using raylib[core](../src/rcore.c) platform functionality like window c
|
||||||
| [core_3d_camera_free](core/core_3d_camera_free.c) | <img src="core/core_3d_camera_free.png" alt="core_3d_camera_free" width="80"> | ⭐☆☆☆ | 1.3 | 1.3 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_3d_camera_free](core/core_3d_camera_free.c) | <img src="core/core_3d_camera_free.png" alt="core_3d_camera_free" width="80"> | ⭐☆☆☆ | 1.3 | 1.3 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_3d_camera_first_person](core/core_3d_camera_first_person.c) | <img src="core/core_3d_camera_first_person.png" alt="core_3d_camera_first_person" width="80"> | ⭐⭐☆☆ | 1.3 | 1.3 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_3d_camera_first_person](core/core_3d_camera_first_person.c) | <img src="core/core_3d_camera_first_person.png" alt="core_3d_camera_first_person" width="80"> | ⭐⭐☆☆ | 1.3 | 1.3 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_3d_camera_split_screen](core/core_3d_camera_split_screen.c) | <img src="core/core_3d_camera_split_screen.png" alt="core_3d_camera_split_screen" width="80"> | ⭐⭐⭐☆ | 3.7 | 4.0 | [Jeffery Myers](https://github.com/JeffM2501) |
|
| [core_3d_camera_split_screen](core/core_3d_camera_split_screen.c) | <img src="core/core_3d_camera_split_screen.png" alt="core_3d_camera_split_screen" width="80"> | ⭐⭐⭐☆ | 3.7 | 4.0 | [Jeffery Myers](https://github.com/JeffM2501) |
|
||||||
|
| [core_3d_camera_fps](core/core_3d_camera_fps.c) | <img src="core/core_3d_camera_fps.png" alt="core_3d_camera_fps" width="80"> | ⭐⭐⭐☆ | 5.5 | 5.5 | [Agnis Aldins](https://github.com/nezvers) |
|
||||||
| [core_3d_picking](core/core_3d_picking.c) | <img src="core/core_3d_picking.png" alt="core_3d_picking" width="80"> | ⭐⭐☆☆ | 1.3 | 4.0 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_3d_picking](core/core_3d_picking.c) | <img src="core/core_3d_picking.png" alt="core_3d_picking" width="80"> | ⭐⭐☆☆ | 1.3 | 4.0 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_world_screen](core/core_world_screen.c) | <img src="core/core_world_screen.png" alt="core_world_screen" width="80"> | ⭐⭐☆☆ | 1.3 | 1.4 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [core_world_screen](core/core_world_screen.c) | <img src="core/core_world_screen.png" alt="core_world_screen" width="80"> | ⭐⭐☆☆ | 1.3 | 1.4 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [core_custom_logging](core/core_custom_logging.c) | <img src="core/core_custom_logging.png" alt="core_custom_logging" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Pablo Marcos Oltra](https://github.com/pamarcos) |
|
| [core_custom_logging](core/core_custom_logging.c) | <img src="core/core_custom_logging.png" alt="core_custom_logging" width="80"> | ⭐⭐⭐☆ | 2.5 | 2.5 | [Pablo Marcos Oltra](https://github.com/pamarcos) |
|
||||||
|
|
@ -121,7 +122,7 @@ Examples using raylib textures functionality, including image/textures loading/g
|
||||||
| [textures_image_rotate](textures/textures_image_rotate.c) | <img src="textures/textures_image_rotate.png" alt="textures_image_rotate" width="80"> | ⭐⭐☆☆ | 1.0 | 1.0 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [textures_image_rotate](textures/textures_image_rotate.c) | <img src="textures/textures_image_rotate.png" alt="textures_image_rotate" width="80"> | ⭐⭐☆☆ | 1.0 | 1.0 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [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) |
|
||||||
|
|
||||||
### category: text [12]
|
### category: text [13]
|
||||||
|
|
||||||
Examples using raylib text functionality, including sprite fonts loading/generation and text drawing, provided by raylib [text](../src/rtext.c) module.
|
Examples using raylib text functionality, including sprite fonts loading/generation and text drawing, provided by raylib [text](../src/rtext.c) module.
|
||||||
|
|
||||||
|
|
@ -139,6 +140,7 @@ Examples using raylib text functionality, including sprite fonts loading/generat
|
||||||
| [text_unicode](text/text_unicode.c) | <img src="text/text_unicode.png" alt="text_unicode" width="80"> | ⭐⭐⭐⭐️ | 2.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
|
| [text_unicode](text/text_unicode.c) | <img src="text/text_unicode.png" alt="text_unicode" width="80"> | ⭐⭐⭐⭐️ | 2.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
|
||||||
| [text_draw_3d](text/text_draw_3d.c) | <img src="text/text_draw_3d.png" alt="text_draw_3d" width="80"> | ⭐⭐⭐⭐️ | 3.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
|
| [text_draw_3d](text/text_draw_3d.c) | <img src="text/text_draw_3d.png" alt="text_draw_3d" width="80"> | ⭐⭐⭐⭐️ | 3.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
|
||||||
| [text_codepoints_loading](text/text_codepoints_loading.c) | <img src="text/text_codepoints_loading.png" alt="text_codepoints_loading" width="80"> | ⭐⭐⭐☆ | 4.2 | 4.2 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [text_codepoints_loading](text/text_codepoints_loading.c) | <img src="text/text_codepoints_loading.png" alt="text_codepoints_loading" width="80"> | ⭐⭐⭐☆ | 4.2 | 4.2 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
|
| [text_unicode_ranges](text/text_unicode_ranges.c) | <img src="text/text_unicode_ranges.png" alt="text_unicode_ranges" width="80"> | ⭐⭐⭐⭐️ | 2.5 | 4.0 | [Vlad Adrian](https://github.com/demizdor) |
|
||||||
|
|
||||||
### category: models [23]
|
### category: models [23]
|
||||||
|
|
||||||
|
|
@ -193,7 +195,7 @@ Examples using raylib shaders functionality, including shaders loading, paramete
|
||||||
| [shaders_hot_reloading](shaders/shaders_hot_reloading.c) | <img src="shaders/shaders_hot_reloading.png" alt="shaders_hot_reloading" width="80"> | ⭐⭐⭐☆ | 3.0 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [shaders_hot_reloading](shaders/shaders_hot_reloading.c) | <img src="shaders/shaders_hot_reloading.png" alt="shaders_hot_reloading" width="80"> | ⭐⭐⭐☆ | 3.0 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [shaders_mesh_instancing](shaders/shaders_mesh_instancing.c) | <img src="shaders/shaders_mesh_instancing.png" alt="shaders_mesh_instancing" width="80"> | ⭐⭐⭐⭐️ | 3.7 | 4.2 | [seanpringle](https://github.com/seanpringle) |
|
| [shaders_mesh_instancing](shaders/shaders_mesh_instancing.c) | <img src="shaders/shaders_mesh_instancing.png" alt="shaders_mesh_instancing" width="80"> | ⭐⭐⭐⭐️ | 3.7 | 4.2 | [seanpringle](https://github.com/seanpringle) |
|
||||||
| [shaders_multi_sample2d](shaders/shaders_multi_sample2d.c) | <img src="shaders/shaders_multi_sample2d.png" alt="shaders_multi_sample2d" width="80"> | ⭐⭐☆☆ | 3.5 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
| [shaders_multi_sample2d](shaders/shaders_multi_sample2d.c) | <img src="shaders/shaders_multi_sample2d.png" alt="shaders_multi_sample2d" width="80"> | ⭐⭐☆☆ | 3.5 | 3.5 | [Ramon Santamaria](https://github.com/raysan5) |
|
||||||
| [shaders_normalmap](shaders/shaders_normalmap.c) | <img src="shaders/shaders_normalmap.png" alt="shaders_normalmap" width="80"> | ⭐⭐⭐⭐️ | 5.6 | 5.6 | [Jeremy Montgomery](https://github.com/Sir_Irk) |
|
| [shaders_normal_map](shaders/shaders_normal_map.c) | <img src="shaders/shaders_normal_map.png" alt="shaders_normal_map" width="80"> | ⭐⭐⭐⭐️ | 5.6 | 5.6 | [Jeremy Montgomery](https://github.com/Sir_Irk) |
|
||||||
| [shaders_spotlight](shaders/shaders_spotlight.c) | <img src="shaders/shaders_spotlight.png" alt="shaders_spotlight" width="80"> | ⭐⭐☆☆ | 2.5 | 3.7 | [Chris Camacho](https://github.com/chriscamacho) |
|
| [shaders_spotlight](shaders/shaders_spotlight.c) | <img src="shaders/shaders_spotlight.png" alt="shaders_spotlight" width="80"> | ⭐⭐☆☆ | 2.5 | 3.7 | [Chris Camacho](https://github.com/chriscamacho) |
|
||||||
| [shaders_deferred_render](shaders/shaders_deferred_render.c) | <img src="shaders/shaders_deferred_render.png" alt="shaders_deferred_render" width="80"> | ⭐⭐⭐⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
| [shaders_deferred_render](shaders/shaders_deferred_render.c) | <img src="shaders/shaders_deferred_render.png" alt="shaders_deferred_render" width="80"> | ⭐⭐⭐⭐️ | 4.5 | 4.5 | [Justin Andreas Lacoste](https://github.com/27justin) |
|
||||||
| [shaders_hybrid_render](shaders/shaders_hybrid_render.c) | <img src="shaders/shaders_hybrid_render.png" alt="shaders_hybrid_render" width="80"> | ⭐⭐⭐⭐️ | 4.2 | 4.2 | [Buğra Alptekin Sarı](https://github.com/BugraAlptekinSari) |
|
| [shaders_hybrid_render](shaders/shaders_hybrid_render.c) | <img src="shaders/shaders_hybrid_render.png" alt="shaders_hybrid_render" width="80"> | ⭐⭐⭐⭐️ | 4.2 | 4.2 | [Buğra Alptekin Sarı](https://github.com/BugraAlptekinSari) |
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - processing mixed output");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - mixed audio processing");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Module playing (streaming)
|
* raylib [audio] example - module playing (streaming)
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Music playing (streaming)
|
* raylib [audio] example - music playing (streaming)
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Raw audio streaming
|
* raylib [audio] example - raw audio streaming
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Sound loading and playing
|
* raylib [audio] example - sound loading and playing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - spatialized 3D sound
|
* raylib [audio] example - 3d sound positioning
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -32,7 +32,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - 3d sound positioning");
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Music stream processing effects
|
* raylib [audio] example - stream effects
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,26 @@
|
||||||
:: .
|
:: .
|
||||||
:: Compile your examples for web using: build_example_web.bat <example_category>/<example_name>
|
:: Compile your examples for web using: build_example_web.bat <example_category>/<example_name>
|
||||||
:: .
|
:: .
|
||||||
set "INPUT_FILE=%1"
|
SET "INPUT_FILE=%1"
|
||||||
:: Change delimiter for the FOR loop
|
:: Change delimiter for the FOR loop
|
||||||
for /f "tokens=1-10 delims=/" %%a in ("%INPUT_FILE%") do (
|
FOR /f "tokens=1-10 delims=/" %%a IN ("%INPUT_FILE%") DO (
|
||||||
set CATEGORY=%%a
|
SET CATEGORY=%%a
|
||||||
set FILENAME=%%b
|
SET FILENAME=%%b
|
||||||
)
|
)
|
||||||
:: > Setup required Environment
|
:: > SETup required Environment
|
||||||
:: -------------------------------------
|
:: -------------------------------------
|
||||||
set RAYLIB_PATH=C:\GitHub\raylib
|
SET RAYLIB_PATH=C:\GitHub\raylib
|
||||||
set EMSDK_PATH=C:\raylib\emsdk
|
SET EMSDK_PATH=C:\raylib\emsdk
|
||||||
|
SET COMPILER_PATH=C:\raylib\w64devkit\bin
|
||||||
|
ENV_SET PATH=%COMPILER_PATH%
|
||||||
|
SET MAKE=mingw32-make
|
||||||
echo
|
echo
|
||||||
:: Set required web compilation options
|
:: Set required web compilation options
|
||||||
:: -------------------------------------
|
:: -------------------------------------
|
||||||
set CC=%EMSDK_PATH%\upstream\emscripten\emcc
|
::SET CC=%EMSDK_PATH%\upstream\emscripten\emcc
|
||||||
set CFLAGS=-Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result -O3 -I. -Iexternal -I%RAYLIB_PATH%\src -I%RAYLIB_PATH%\external -DPLATFORM_WEB
|
::SET CFLAGS=-Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -Wunused-result -O3 -I. -Iexternal -I%RAYLIB_PATH%\src -I%RAYLIB_PATH%\external -DPLATFORM_WEB
|
||||||
set LDFLAGS=-L. -L$(RAYLIB_PATH)\src -sUSE_GLFW=3 -sEXPORTED_RUNTIME_METHODS=ccall -sASYNCIFY --shell-file %RAYLIB_PATH%\src\shell.html
|
::SET LDFLAGS=-L. -L$(RAYLIB_PATH)\src -sUSE_GLFW=3 -sEXPORTED_RUNTIME_METHODS=ccall -sASYNCIFY --shell-file %RAYLIB_PATH%\src\shell.html
|
||||||
set LDLIBS=%RAYLIB_PATH%\src\libraylib.web.a
|
::SET LDLIBS=%RAYLIB_PATH%\src\libraylib.web.a
|
||||||
:: TODO: If using some resources/assets, set the directory path as shown in the commented line!
|
|
||||||
set RESOURCES=
|
|
||||||
::set RESOURCES=--preload-file $(RESOURCES_PATH)
|
|
||||||
cd %RAYLIB_PATH%\examples\%CATEGORY%
|
|
||||||
echo
|
echo
|
||||||
:: Clean latest build
|
:: Clean latest build
|
||||||
:: ------------------------
|
:: ------------------------
|
||||||
|
|
@ -38,6 +37,8 @@ echo on
|
||||||
:: Compile program
|
:: Compile program
|
||||||
:: -----------------------
|
:: -----------------------
|
||||||
C:
|
C:
|
||||||
%CC% -o %FILENAME%.html %FILENAME%.c %CFLAGS% %LDFLAGS% %LDLIBS% %RESOURCES%
|
cd %RAYLIB_PATH%\examples
|
||||||
|
%MAKE% -f Makefile.Web %CATEGORY%/%FILENAME% PLATFORM=PLATFORM_WEB -B
|
||||||
|
::%CC% -o %FILENAME%.html %FILENAME%.c %CFLAGS% %LDFLAGS% %LDLIBS% %RESOURCES%
|
||||||
cd ..
|
cd ..
|
||||||
echo
|
echo
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - 2D Camera system
|
* raylib [core] example - 2d camera
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - 2D Camera platformer
|
* raylib [core] example - 2d camera platformer
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
@ -54,7 +54,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 2d camera platformer");
|
||||||
|
|
||||||
Player player = { 0 };
|
Player player = { 0 };
|
||||||
player.position = (Vector2){ 400, 280 };
|
player.position = (Vector2){ 400, 280 };
|
||||||
|
|
|
||||||
330
examples/core/core_3d_camera_fps.c
Normal file
330
examples/core/core_3d_camera_fps.c
Normal file
|
|
@ -0,0 +1,330 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - 3d first-person camera controller
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.5, last time updated with raylib 5.5
|
||||||
|
*
|
||||||
|
* Example contributed by Agnis Aldins (@nezvers) 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-2025 Agnis Aldins (@nezvers)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#include "raymath.h"
|
||||||
|
#include "rcamera.h"
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Defines and Macros
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Movement constants
|
||||||
|
#define GRAVITY 32.0f
|
||||||
|
#define MAX_SPEED 20.0f
|
||||||
|
#define CROUCH_SPEED 5.0f
|
||||||
|
#define JUMP_FORCE 12.0f
|
||||||
|
#define MAX_ACCEL 150.0f
|
||||||
|
// Grounded drag
|
||||||
|
#define FRICTION 0.86f
|
||||||
|
// Increasing air drag, increases strafing speed
|
||||||
|
#define AIR_DRAG 0.98f
|
||||||
|
// Responsiveness for turning movement direction to looked direction
|
||||||
|
#define CONTROL 15.0f
|
||||||
|
#define CROUCH_HEIGHT 0.0f
|
||||||
|
#define STAND_HEIGHT 1.0f
|
||||||
|
#define BOTTOM_HEIGHT 0.5f
|
||||||
|
|
||||||
|
#define NORMALIZE_INPUT 0
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Types and Structures Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Body structure
|
||||||
|
typedef struct {
|
||||||
|
Vector3 position;
|
||||||
|
Vector3 velocity;
|
||||||
|
Vector3 dir;
|
||||||
|
bool isGrounded;
|
||||||
|
} Body;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static Vector2 sensitivity = { 0.001f, 0.001f };
|
||||||
|
|
||||||
|
static Body player = { 0 };
|
||||||
|
static Vector2 lookRotation = { 0 };
|
||||||
|
static float headTimer = 0.0f;
|
||||||
|
static float walkLerp = 0.0f;
|
||||||
|
static float headLerp = STAND_HEIGHT;
|
||||||
|
static Vector2 lean = { 0 };
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module functions declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
static void DrawLevel(void);
|
||||||
|
static void UpdateCameraAngle(Camera *camera);
|
||||||
|
static void UpdateBody(Body *body, float rot, char side, char forward, bool jumpPressed, bool crouchHold);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d first-person camera controller");
|
||||||
|
|
||||||
|
// Initialize camera variables
|
||||||
|
// NOTE: UpdateCameraAngle() takes care of the rest
|
||||||
|
Camera camera = { 0 };
|
||||||
|
camera.fovy = 60.0f;
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
camera.position = (Vector3){
|
||||||
|
player.position.x,
|
||||||
|
player.position.y + (BOTTOM_HEIGHT + headLerp),
|
||||||
|
player.position.z,
|
||||||
|
};
|
||||||
|
|
||||||
|
UpdateCameraAngle(&camera); // Update camera parameters
|
||||||
|
|
||||||
|
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
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
Vector2 mouseDelta = GetMouseDelta();
|
||||||
|
lookRotation.x -= mouseDelta.x*sensitivity.x;
|
||||||
|
lookRotation.y += mouseDelta.y*sensitivity.y;
|
||||||
|
|
||||||
|
char sideway = (IsKeyDown(KEY_D) - IsKeyDown(KEY_A));
|
||||||
|
char forward = (IsKeyDown(KEY_W) - IsKeyDown(KEY_S));
|
||||||
|
bool crouching = IsKeyDown(KEY_LEFT_CONTROL);
|
||||||
|
UpdateBody(&player, lookRotation.x, sideway, forward, IsKeyPressed(KEY_SPACE), crouching);
|
||||||
|
|
||||||
|
float delta = GetFrameTime();
|
||||||
|
headLerp = Lerp(headLerp, (crouching ? CROUCH_HEIGHT : STAND_HEIGHT), 20.0f*delta);
|
||||||
|
camera.position = (Vector3){
|
||||||
|
player.position.x,
|
||||||
|
player.position.y + (BOTTOM_HEIGHT + headLerp),
|
||||||
|
player.position.z,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (player.isGrounded && ((forward != 0) || (sideway != 0)))
|
||||||
|
{
|
||||||
|
headTimer += delta*3.0f;
|
||||||
|
walkLerp = Lerp(walkLerp, 1.0f, 10.0f*delta);
|
||||||
|
camera.fovy = Lerp(camera.fovy, 55.0f, 5.0f*delta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
walkLerp = Lerp(walkLerp, 0.0f, 10.0f*delta);
|
||||||
|
camera.fovy = Lerp(camera.fovy, 60.0f, 5.0f*delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
lean.x = Lerp(lean.x, sideway*0.02f, 10.0f*delta);
|
||||||
|
lean.y = Lerp(lean.y, forward*0.015f, 10.0f*delta);
|
||||||
|
|
||||||
|
UpdateCameraAngle(&camera);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
DrawLevel();
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
// Draw info box
|
||||||
|
DrawRectangle(5, 5, 330, 75, Fade(SKYBLUE, 0.5f));
|
||||||
|
DrawRectangleLines(5, 5, 330, 75, BLUE);
|
||||||
|
|
||||||
|
DrawText("Camera controls:", 15, 15, 10, BLACK);
|
||||||
|
DrawText("- Move keys: W, A, S, D, Space, Left-Ctrl", 15, 30, 10, BLACK);
|
||||||
|
DrawText("- Look around: arrow keys or mouse", 15, 45, 10, BLACK);
|
||||||
|
DrawText(TextFormat("- Velocity Len: (%06.3f)", Vector2Length((Vector2){ player.velocity.x, player.velocity.z })), 15, 60, 10, BLACK);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Module functions definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
void UpdateBody(Body* body, float rot, char side, char forward, bool jumpPressed, bool crouchHold)
|
||||||
|
{
|
||||||
|
Vector2 input = (Vector2){ (float)side, (float)-forward };
|
||||||
|
|
||||||
|
#if defined(NORMALIZE_INPUT)
|
||||||
|
// Slow down diagonal movement
|
||||||
|
if ((side != 0) && (forward != 0)) input = Vector2Normalize(input);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float delta = GetFrameTime();
|
||||||
|
|
||||||
|
if (!body->isGrounded) body->velocity.y -= GRAVITY*delta;
|
||||||
|
|
||||||
|
if (body->isGrounded && jumpPressed)
|
||||||
|
{
|
||||||
|
body->velocity.y = JUMP_FORCE;
|
||||||
|
body->isGrounded = false;
|
||||||
|
|
||||||
|
// Sound can be played at this moment
|
||||||
|
//SetSoundPitch(fxJump, 1.0f + (GetRandomValue(-100, 100)*0.001));
|
||||||
|
//PlaySound(fxJump);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 front = (Vector3){ sin(rot), 0.f, cos(rot) };
|
||||||
|
Vector3 right = (Vector3){ cos(-rot), 0.f, sin(-rot) };
|
||||||
|
|
||||||
|
Vector3 desiredDir = (Vector3){ input.x*right.x + input.y*front.x, 0.0f, input.x*right.z + input.y*front.z, };
|
||||||
|
body->dir = Vector3Lerp(body->dir, desiredDir, CONTROL*delta);
|
||||||
|
|
||||||
|
float decel = (body->isGrounded ? FRICTION : AIR_DRAG);
|
||||||
|
Vector3 hvel = (Vector3){ body->velocity.x*decel, 0.0f, body->velocity.z*decel };
|
||||||
|
|
||||||
|
float hvelLength = Vector3Length(hvel); // Magnitude
|
||||||
|
if (hvelLength < (MAX_SPEED*0.01f)) hvel = (Vector3){ 0 };
|
||||||
|
|
||||||
|
// This is what creates strafing
|
||||||
|
float speed = Vector3DotProduct(hvel, body->dir);
|
||||||
|
|
||||||
|
// Whenever the amount of acceleration to add is clamped by the maximum acceleration constant,
|
||||||
|
// a Player can make the speed faster by bringing the direction closer to horizontal velocity angle
|
||||||
|
// More info here: https://youtu.be/v3zT3Z5apaM?t=165
|
||||||
|
float maxSpeed = (crouchHold? CROUCH_SPEED : MAX_SPEED);
|
||||||
|
float accel = Clamp(maxSpeed - speed, 0.f, MAX_ACCEL*delta);
|
||||||
|
hvel.x += body->dir.x*accel;
|
||||||
|
hvel.z += body->dir.z*accel;
|
||||||
|
|
||||||
|
body->velocity.x = hvel.x;
|
||||||
|
body->velocity.z = hvel.z;
|
||||||
|
|
||||||
|
body->position.x += body->velocity.x*delta;
|
||||||
|
body->position.y += body->velocity.y*delta;
|
||||||
|
body->position.z += body->velocity.z*delta;
|
||||||
|
|
||||||
|
// Fancy collision system against the floor
|
||||||
|
if (body->position.y <= 0.0f)
|
||||||
|
{
|
||||||
|
body->position.y = 0.0f;
|
||||||
|
body->velocity.y = 0.0f;
|
||||||
|
body->isGrounded = true; // Enable jumping
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update camera
|
||||||
|
static void UpdateCameraAngle(Camera *camera)
|
||||||
|
{
|
||||||
|
const Vector3 up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
const Vector3 targetOffset = (Vector3){ 0.0f, 0.0f, -1.0f };
|
||||||
|
|
||||||
|
// Left and right
|
||||||
|
Vector3 yaw = Vector3RotateByAxisAngle(targetOffset, up, lookRotation.x);
|
||||||
|
|
||||||
|
// Clamp view up
|
||||||
|
float maxAngleUp = Vector3Angle(up, yaw);
|
||||||
|
maxAngleUp -= 0.001f; // Avoid numerical errors
|
||||||
|
if ( -(lookRotation.y) > maxAngleUp) { lookRotation.y = -maxAngleUp; }
|
||||||
|
|
||||||
|
// Clamp view down
|
||||||
|
float maxAngleDown = Vector3Angle(Vector3Negate(up), yaw);
|
||||||
|
maxAngleDown *= -1.0f; // Downwards angle is negative
|
||||||
|
maxAngleDown += 0.001f; // Avoid numerical errors
|
||||||
|
if ( -(lookRotation.y) < maxAngleDown) { lookRotation.y = -maxAngleDown; }
|
||||||
|
|
||||||
|
// Up and down
|
||||||
|
Vector3 right = Vector3Normalize(Vector3CrossProduct(yaw, up));
|
||||||
|
|
||||||
|
// Rotate view vector around right axis
|
||||||
|
float pitchAngle = -lookRotation.y -
|
||||||
|
lean.y;
|
||||||
|
pitchAngle = Clamp(pitchAngle, -PI / 2 + 0.0001f, PI / 2 - 0.0001f); // Clamp angle so it doesn't go past straight up or straight down
|
||||||
|
Vector3 pitch = Vector3RotateByAxisAngle(yaw, right, pitchAngle);
|
||||||
|
|
||||||
|
// Head animation
|
||||||
|
// Rotate up direction around forward axis
|
||||||
|
float headSin = sin(headTimer*PI);
|
||||||
|
float headCos = cos(headTimer*PI);
|
||||||
|
const float stepRotation = 0.01f;
|
||||||
|
camera->up = Vector3RotateByAxisAngle(up, pitch, headSin*stepRotation + lean.x);
|
||||||
|
|
||||||
|
// Camera BOB
|
||||||
|
const float bobSide = 0.1f;
|
||||||
|
const float bobUp = 0.15f;
|
||||||
|
Vector3 bobbing = Vector3Scale(right, headSin*bobSide);
|
||||||
|
bobbing.y = fabsf(headCos*bobUp);
|
||||||
|
|
||||||
|
camera->position = Vector3Add(camera->position, Vector3Scale(bobbing, walkLerp));
|
||||||
|
camera->target = Vector3Add(camera->position, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw game level
|
||||||
|
static void DrawLevel(void)
|
||||||
|
{
|
||||||
|
const int floorExtent = 25;
|
||||||
|
const float tileSize = 5.0f;
|
||||||
|
const Color tileColor1 = (Color){ 150, 200, 200, 255 };
|
||||||
|
|
||||||
|
// Floor tiles
|
||||||
|
for (int y = -floorExtent; y < floorExtent; y++)
|
||||||
|
{
|
||||||
|
for (int x = -floorExtent; x < floorExtent; x++)
|
||||||
|
{
|
||||||
|
if ((y & 1) && (x & 1))
|
||||||
|
{
|
||||||
|
DrawPlane((Vector3){ x*tileSize, 0.0f, y*tileSize}, (Vector2){ tileSize, tileSize }, tileColor1);
|
||||||
|
}
|
||||||
|
else if (!(y & 1) && !(x & 1))
|
||||||
|
{
|
||||||
|
DrawPlane((Vector3){ x*tileSize, 0.0f, y*tileSize}, (Vector2){ tileSize, tileSize }, LIGHTGRAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vector3 towerSize = (Vector3){ 16.0f, 32.0f, 16.0f };
|
||||||
|
const Color towerColor = (Color){ 150, 200, 200, 255 };
|
||||||
|
|
||||||
|
Vector3 towerPos = (Vector3){ 16.0f, 16.0f, 16.0f };
|
||||||
|
DrawCubeV(towerPos, towerSize, towerColor);
|
||||||
|
DrawCubeWiresV(towerPos, towerSize, DARKBLUE);
|
||||||
|
|
||||||
|
towerPos.x *= -1;
|
||||||
|
DrawCubeV(towerPos, towerSize, towerColor);
|
||||||
|
DrawCubeWiresV(towerPos, towerSize, DARKBLUE);
|
||||||
|
|
||||||
|
towerPos.z *= -1;
|
||||||
|
DrawCubeV(towerPos, towerSize, towerColor);
|
||||||
|
DrawCubeWiresV(towerPos, towerSize, DARKBLUE);
|
||||||
|
|
||||||
|
towerPos.x *= -1;
|
||||||
|
DrawCubeV(towerPos, towerSize, towerColor);
|
||||||
|
DrawCubeWiresV(towerPos, towerSize, DARKBLUE);
|
||||||
|
|
||||||
|
// Red sun
|
||||||
|
DrawSphere((Vector3){ 300.0f, 300.0f, 0.0f }, 100.0f, (Color){ 255, 0, 0, 255 });
|
||||||
|
}
|
||||||
BIN
examples/core/core_3d_camera_fps.png
Normal file
BIN
examples/core/core_3d_camera_fps.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Initialize 3d camera free
|
* raylib [core] example - 3d camera free
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Initialize 3d camera mode
|
* raylib [core] example - 3d camera mode
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - 3d cmaera split screen
|
* raylib [core] example - 3d camera split screen
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Picking in 3d mode
|
* raylib [core] example - 3d picking
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] examples - basic screen manager
|
* raylib [core] example - basic screen manager
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Basic window
|
* raylib [core] example - basic window
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Basic window (adapted for HTML5 platform)
|
* raylib [core] example - basic window
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Custom logging
|
* raylib [core] example - custom logging
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Windows drop files
|
* raylib [core] example - drop files
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - HighDPI
|
* raylib [core] example - high dpi
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] e/4
|
* Example complexity rating: [★☆☆☆] e/4
|
||||||
*
|
*
|
||||||
|
|
@ -29,7 +29,7 @@ int main(void)
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - high dpi");
|
||||||
SetWindowMinSize(450, 450);
|
SetWindowMinSize(450, 450);
|
||||||
|
|
||||||
int logicalGridDescY = 120;
|
int logicalGridDescY = 120;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Gamepad input
|
* raylib [core] example - gamepad input
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Input Gestures Detection
|
* raylib [core] example - input gestures
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Input Gestures for Web
|
* raylib [core] example - input gestures web
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Keyboard input
|
* raylib [core] example - keyboard input
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Mouse input
|
* raylib [core] example - mouse input
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
@ -29,7 +29,6 @@ int main(void)
|
||||||
|
|
||||||
Vector2 ballPosition = { -100.0f, -100.0f };
|
Vector2 ballPosition = { -100.0f, -100.0f };
|
||||||
Color ballColor = DARKBLUE;
|
Color ballColor = DARKBLUE;
|
||||||
int isCursorHidden = 0;
|
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
||||||
|
|
@ -41,15 +40,13 @@ int main(void)
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_H))
|
if (IsKeyPressed(KEY_H))
|
||||||
{
|
{
|
||||||
if (isCursorHidden == 0)
|
if (IsCursorHidden())
|
||||||
{
|
{
|
||||||
HideCursor();
|
ShowCursor();
|
||||||
isCursorHidden = 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShowCursor();
|
HideCursor();
|
||||||
isCursorHidden = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +72,7 @@ int main(void)
|
||||||
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY);
|
||||||
DrawText("Press 'H' to toggle cursor visibility", 10, 30, 20, DARKGRAY);
|
DrawText("Press 'H' to toggle cursor visibility", 10, 30, 20, DARKGRAY);
|
||||||
|
|
||||||
if (isCursorHidden == 1) DrawText("CURSOR HIDDEN", 20, 60, 20, RED);
|
if (!IsCursorHidden()) DrawText("CURSOR HIDDEN", 20, 60, 20, RED);
|
||||||
else DrawText("CURSOR VISIBLE", 20, 60, 20, LIME);
|
else DrawText("CURSOR VISIBLE", 20, 60, 20, LIME);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] examples - Mouse wheel input
|
* raylib [core] example - input mouse wheel
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Input multitouch
|
* raylib [core] example - input multitouch
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Generate random values
|
* raylib [core] example - generate random values
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Scissor test
|
* raylib [core] example - scissor test
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Smooth Pixel-perfect camera
|
* raylib [core] example - smooth pixel-perfect camera
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Storage save/load values
|
* raylib [core] example - storage save/load values
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - VR Simulator (Oculus Rift CV1 parameters)
|
* raylib [core] example - vr simulator
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - window scale letterbox (and virtual mouse)
|
* raylib [core] example - window scale letterbox
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -27,12 +27,12 @@
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
const int windowWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int windowHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
// Enable config flags for resizable window and vertical synchro
|
// Enable config flags for resizable window and vertical synchro
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
|
||||||
InitWindow(windowWidth, windowHeight, "raylib [core] example - window scale letterbox");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - window scale letterbox");
|
||||||
SetWindowMinSize(320, 240);
|
SetWindowMinSize(320, 240);
|
||||||
|
|
||||||
int gameScreenWidth = 640;
|
int gameScreenWidth = 640;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Window should close
|
* raylib [core] example - window should close
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - World to screen
|
* raylib [core] example - core world screen
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# examples must be provided as: <example_category>;<example_name>;<example_stars>;<raylib_created_version>;<raylib_last_update_version>;"<example_author_name>";<author_github_user>
|
# examples must be provided as: <example_category>;<example_name>;<example_stars>;<raylib_created_version>;<raylib_last_update_version>;"<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
|
# 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
|
# WARNING: List is not ordered by example name but by the display order on web
|
||||||
#
|
#
|
||||||
|
|
@ -23,6 +23,7 @@ core;core_3d_camera_mode;⭐️☆☆☆;1.0;1.0;"Ramon Santamaria";@raysan5
|
||||||
core;core_3d_camera_free;⭐️☆☆☆;1.3;1.3;"Ramon Santamaria";@raysan5
|
core;core_3d_camera_free;⭐️☆☆☆;1.3;1.3;"Ramon Santamaria";@raysan5
|
||||||
core;core_3d_camera_first_person;⭐️⭐️☆☆;1.3;1.3;"Ramon Santamaria";@raysan5
|
core;core_3d_camera_first_person;⭐️⭐️☆☆;1.3;1.3;"Ramon Santamaria";@raysan5
|
||||||
core;core_3d_camera_split_screen;⭐️⭐️⭐️☆;3.7;4.0;"Jeffery Myers";@JeffM2501
|
core;core_3d_camera_split_screen;⭐️⭐️⭐️☆;3.7;4.0;"Jeffery Myers";@JeffM2501
|
||||||
|
core;core_3d_camera_fps;⭐️⭐️⭐️☆;5.5;5.5;"Agnis Aldins";@nezvers
|
||||||
core;core_3d_picking;⭐️⭐️☆☆;1.3;4.0;"Ramon Santamaria";@raysan5
|
core;core_3d_picking;⭐️⭐️☆☆;1.3;4.0;"Ramon Santamaria";@raysan5
|
||||||
core;core_world_screen;⭐️⭐️☆☆;1.3;1.4;"Ramon Santamaria";@raysan5
|
core;core_world_screen;⭐️⭐️☆☆;1.3;1.4;"Ramon Santamaria";@raysan5
|
||||||
core;core_custom_logging;⭐️⭐️⭐️☆;2.5;2.5;"Pablo Marcos Oltra";@pamarcos
|
core;core_custom_logging;⭐️⭐️⭐️☆;2.5;2.5;"Pablo Marcos Oltra";@pamarcos
|
||||||
|
|
@ -141,7 +142,7 @@ shaders;shaders_simple_mask;⭐️⭐️☆☆;2.5;3.7;"Chris Camacho";@chriscam
|
||||||
shaders;shaders_hot_reloading;⭐️⭐️⭐️☆;3.0;3.5;"Ramon Santamaria";@raysan5
|
shaders;shaders_hot_reloading;⭐️⭐️⭐️☆;3.0;3.5;"Ramon Santamaria";@raysan5
|
||||||
shaders;shaders_mesh_instancing;⭐️⭐️⭐️⭐️;3.7;4.2;"seanpringle";@seanpringle
|
shaders;shaders_mesh_instancing;⭐️⭐️⭐️⭐️;3.7;4.2;"seanpringle";@seanpringle
|
||||||
shaders;shaders_multi_sample2d;⭐️⭐️☆☆;3.5;3.5;"Ramon Santamaria";@raysan5
|
shaders;shaders_multi_sample2d;⭐️⭐️☆☆;3.5;3.5;"Ramon Santamaria";@raysan5
|
||||||
shaders;shaders_normalmap;⭐️⭐️⭐️⭐️;5.6;5.6;"Jeremy Montgomery";@Sir_Irk
|
shaders;shaders_normal_map;⭐️⭐️⭐️⭐️;5.6;5.6;"Jeremy Montgomery";@Sir_Irk
|
||||||
shaders;shaders_spotlight;⭐️⭐️☆☆;2.5;3.7;"Chris Camacho";@chriscamacho
|
shaders;shaders_spotlight;⭐️⭐️☆☆;2.5;3.7;"Chris Camacho";@chriscamacho
|
||||||
shaders;shaders_deferred_render;⭐️⭐️⭐️⭐️;4.5;4.5;"Justin Andreas Lacoste";@27justin
|
shaders;shaders_deferred_render;⭐️⭐️⭐️⭐️;4.5;4.5;"Justin Andreas Lacoste";@27justin
|
||||||
shaders;shaders_hybrid_render;⭐️⭐️⭐️⭐️;4.2;4.2;"Buğra Alptekin Sarı";@BugraAlptekinSari
|
shaders;shaders_hybrid_render;⭐️⭐️⭐️⭐️;4.2;4.2;"Buğra Alptekin Sarı";@BugraAlptekinSari
|
||||||
|
|
@ -167,3 +168,4 @@ others;easings_testbed;⭐️⭐️⭐️☆;2.5;3.0;"Juan Miguel López";@flash
|
||||||
others;raylib_opengl_interop;⭐️⭐️⭐️⭐️;3.8;4.0;"Stephan Soller";@arkanis
|
others;raylib_opengl_interop;⭐️⭐️⭐️⭐️;3.8;4.0;"Stephan Soller";@arkanis
|
||||||
others;embedded_files_loading;⭐️⭐️☆☆;3.0;3.5;"Kristian Holmgren";@defutura
|
others;embedded_files_loading;⭐️⭐️☆☆;3.0;3.5;"Kristian Holmgren";@defutura
|
||||||
others;raymath_vector_angle;⭐️⭐️☆☆;1.0;4.6;"Ramon Santamaria";@raysan5
|
others;raymath_vector_angle;⭐️⭐️☆☆;1.0;4.6;"Ramon Santamaria";@raysan5
|
||||||
|
text;text_unicode_ranges;⭐⭐⭐⭐️;2.5;4.0;"Vlad Adrian";@demizdor
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Load 3d model with animations and play them
|
* raylib [models] example - model animation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Drawing billboards
|
* raylib [models] example - billboard render
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
@ -26,7 +26,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - billboard render");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Using bones as socket for calculating the positioning of something
|
* raylib [models] example - bone socket
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Detect basic 3d collisions (box vs sphere vs box)
|
* raylib [models] example - box collisions
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Cubicmap loading and drawing
|
* raylib [models] example - cubicmap loading and drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -25,7 +25,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubicmap loading and drawing");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Draw textured cube
|
* raylib [models] example - draw cube texture
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Draw some basic geometric shapes (cube, sphere, cylinder...)
|
* raylib [models] example - geometric shapes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Doing skinning on the gpu using a vertex shader
|
* raylib [models] example - gpu skinning
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
@ -37,7 +37,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - GPU skinning");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - gpu skinning");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Heightmap loading and drawing
|
* raylib [models] example - heightmap terrain
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
@ -25,7 +25,7 @@ int main(void)
|
||||||
int screenWidth = 800;
|
int screenWidth = 800;
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap terrain");
|
||||||
|
|
||||||
// Define our custom camera to look into our 3d world
|
// Define our custom camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Models loading
|
* raylib [models] example - models loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - loading gltf with animations
|
* raylib [models] example - loading gltf animations
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Load models M3D
|
* raylib [models] example - model loading m3d
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -31,7 +31,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - M3D model loading");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - model loading m3d");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Load models vox (MagicaVoxel)
|
* raylib [models] example - magicavoxel loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - procedural mesh generation
|
* raylib [models] example - mesh generation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh
|
* raylib [models] example - mesh picking
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
@ -89,7 +89,7 @@ int main(void)
|
||||||
|
|
||||||
// Display information about closest hit
|
// Display information about closest hit
|
||||||
RayCollision collision = { 0 };
|
RayCollision collision = { 0 };
|
||||||
char *hitObjectName = "None";
|
const char *hitObjectName = "None";
|
||||||
collision.distance = FLT_MAX;
|
collision.distance = FLT_MAX;
|
||||||
collision.hit = false;
|
collision.hit = false;
|
||||||
Color cursorColor = WHITE;
|
Color cursorColor = WHITE;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Show the difference between perspective and orthographic projection
|
* raylib [models] example - orthographic projection
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|
@ -30,7 +30,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - orthographic projection");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { { 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE };
|
Camera camera = { { 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, FOVY_PERSPECTIVE, CAMERA_PERSPECTIVE };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib example - point rendering
|
* raylib [models] example - point rendering
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Skybox loading and drawing
|
* raylib [models] example - skybox rendering
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
@ -37,7 +37,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox rendering");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Tesseract view
|
* raylib [models] example - tesseract view
|
||||||
*
|
*
|
||||||
* NOTE: This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?)
|
* NOTE: This example only works on platforms that support drag & drop (Windows, Linux, OSX, Html5?)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Waving cubes
|
* raylib [models] example - waving cubes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - Plane rotations (yaw, pitch, roll)
|
* raylib [models] example - plane rotations (yaw, pitch, roll)
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
65
examples/models/resources/shaders/glsl100/voxel_lighting.fs
Normal file
65
examples/models/resources/shaders/glsl100/voxel_lighting.fs
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
// Input from vertex shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 ambient;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 lightDot = vec3(0.0);
|
||||||
|
vec3 normal = normalize(fragNormal);
|
||||||
|
vec3 viewD = normalize(viewPos - fragPosition);
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
vec3 light = vec3(0.0);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
|
light = -normalize(lights[i].target - lights[i].position);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_POINT)
|
||||||
|
light = normalize(lights[i].position - fragPosition);
|
||||||
|
|
||||||
|
float NdotL = max(dot(normal, light), 0.0);
|
||||||
|
lightDot += lights[i].color.rgb * NdotL;
|
||||||
|
|
||||||
|
if (NdotL > 0.0)
|
||||||
|
{
|
||||||
|
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
|
||||||
|
specular += specCo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
|
||||||
|
|
||||||
|
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
|
||||||
|
|
||||||
|
gl_FragColor = finalColor;
|
||||||
|
}
|
||||||
28
examples/models/resources/shaders/glsl100/voxel_lighting.vs
Normal file
28
examples/models/resources/shaders/glsl100/voxel_lighting.vs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
// attribute vec2 vertexTexCoord;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
|
||||||
|
// Output to fragment shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
62
examples/models/resources/shaders/glsl120/voxel_lighting.fs
Normal file
62
examples/models/resources/shaders/glsl120/voxel_lighting.fs
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
#version 120
|
||||||
|
// Input from vertex shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec4 ambient;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
#define MAX_LIGHTS 4
|
||||||
|
#define LIGHT_DIRECTIONAL 0
|
||||||
|
#define LIGHT_POINT 1
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform Light lights[MAX_LIGHTS];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 lightDot = vec3(0.0);
|
||||||
|
vec3 normal = normalize(fragNormal);
|
||||||
|
vec3 viewD = normalize(viewPos - fragPosition);
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
|
||||||
|
for (int i = 0; i < MAX_LIGHTS; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
vec3 light = vec3(0.0);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_DIRECTIONAL)
|
||||||
|
light = -normalize(lights[i].target - lights[i].position);
|
||||||
|
|
||||||
|
if (lights[i].type == LIGHT_POINT)
|
||||||
|
light = normalize(lights[i].position - fragPosition);
|
||||||
|
|
||||||
|
float NdotL = max(dot(normal, light), 0.0);
|
||||||
|
lightDot += lights[i].color.rgb * NdotL;
|
||||||
|
|
||||||
|
if (NdotL > 0.0)
|
||||||
|
{
|
||||||
|
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
|
||||||
|
specular += specCo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
|
||||||
|
|
||||||
|
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
|
||||||
|
|
||||||
|
gl_FragColor = finalColor;
|
||||||
|
}
|
||||||
24
examples/models/resources/shaders/glsl120/voxel_lighting.vs
Normal file
24
examples/models/resources/shaders/glsl120/voxel_lighting.vs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#version 120
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
uniform mat4 matNormal;
|
||||||
|
|
||||||
|
// Output to fragment shader
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragColor = vertexColor;
|
||||||
|
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [easings] example - Easings Testbed
|
* raylib [easings] example - easings testbed
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [others] example - Embedded files loading (Wave and Image)
|
* raylib [others] example - embedded files loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - OpenGL point particle system
|
* raylib [others] example - OpenGL interoperatibility
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|
@ -71,7 +71,7 @@ int main(void)
|
||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - point particles");
|
InitWindow(screenWidth, screenHeight, "raylib [others] example - OpenGL interoperatibility");
|
||||||
|
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/point_particle.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/point_particle.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/point_particle.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/point_particle.fs", GLSL_VERSION));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Vector Angle
|
* raylib [math] example - vector angle
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ uniform vec4 color;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
||||||
// it. (0, 0) is the top left, (1, 1) the bottom right corner.
|
// it. (0, 0) is the top left, (1, 1) the bottom right corner
|
||||||
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges.
|
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
|
||||||
gl_FragColor = vec4(color.rgb, color.a * (1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
|
gl_FragColor = vec4(color.rgb, color.a*(1.0 - length(gl_PointCoord.xy - vec2(0.5))*2.0));
|
||||||
}
|
}
|
||||||
|
|
@ -16,9 +16,9 @@ void main()
|
||||||
float period = vertexPosition.z;
|
float period = vertexPosition.z;
|
||||||
|
|
||||||
// Calculate final vertex position (jiggle it around a bit horizontally)
|
// Calculate final vertex position (jiggle it around a bit horizontally)
|
||||||
pos += vec2(100.0, 0.0) * sin(period * currentTime);
|
pos += vec2(100.0, 0.0)*sin(period*currentTime);
|
||||||
gl_Position = mvp * vec4(pos.x, pos.y, 0.0, 1.0);
|
gl_Position = mvp*vec4(pos.x, pos.y, 0.0, 1.0);
|
||||||
|
|
||||||
// Calculate the screen space size of this particle (also vary it over time)
|
// Calculate the screen space size of this particle (also vary it over time)
|
||||||
gl_PointSize = 10.0 - 5.0 * abs(sin(period * currentTime));
|
gl_PointSize = 10.0 - 5.0*abs(sin(period*currentTime));
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ out vec4 finalColor;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
// Each point is drawn as a screen space square of gl_PointSize size. gl_PointCoord contains where we are inside of
|
||||||
// it. (0, 0) is the top left, (1, 1) the bottom right corner.
|
// it. (0, 0) is the top left, (1, 1) the bottom right corner
|
||||||
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges.
|
// Draw each point as a colored circle with alpha 1.0 in the center and 0.0 at the outer edges
|
||||||
finalColor = vec4(color.rgb, color.a * (1 - length(gl_PointCoord.xy - vec2(0.5))*2));
|
finalColor = vec4(color.rgb, color.a*(1 - length(gl_PointCoord.xy - vec2(0.5))*2));
|
||||||
}
|
}
|
||||||
|
|
@ -16,9 +16,9 @@ void main()
|
||||||
float period = vertexPosition.z;
|
float period = vertexPosition.z;
|
||||||
|
|
||||||
// Calculate final vertex position (jiggle it around a bit horizontally)
|
// Calculate final vertex position (jiggle it around a bit horizontally)
|
||||||
pos += vec2(100, 0) * sin(period * currentTime);
|
pos += vec2(100, 0)*sin(period*currentTime);
|
||||||
gl_Position = mvp * vec4(pos, 0.0, 1.0);
|
gl_Position = mvp*vec4(pos, 0.0, 1.0);
|
||||||
|
|
||||||
// Calculate the screen space size of this particle (also vary it over time)
|
// Calculate the screen space size of this particle (also vary it over time)
|
||||||
gl_PointSize = 10 - 5 * abs(sin(period * currentTime));
|
gl_PointSize = 10 - 5*abs(sin(period*currentTime));
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [rlgl] example - compute shader - Conway's Game of Life
|
* raylib [rlgl] example - compute shader - game of life
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 4.3 versions for compute shaders support,
|
* NOTE: This example requires raylib OpenGL 4.3 versions for compute shaders support,
|
||||||
* shaders used in this example are #version 430 (OpenGL 4.3)
|
* shaders used in this example are #version 430 (OpenGL 4.3)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ uniform vec4 colDiffuse;
|
||||||
|
|
||||||
// NOTE: Add your custom variables here
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
const vec2 size = vec2(800, 450); // render size
|
const vec2 size = vec2(800, 450); // Framebuffer size
|
||||||
const float samples = 5.0; // pixels per axis; higher = bigger glow, worse performance
|
const float samples = 5.0; // Pixels per axis; higher = bigger glow, worse performance
|
||||||
const float quality = 2.5; // lower = smaller glow, better quality
|
const float quality = 2.5; // Defines size factor: Lower = smaller glow, better quality
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ vec4 PostFX(sampler2D tex, vec2 uv)
|
||||||
{
|
{
|
||||||
vec4 c = vec4(0.0);
|
vec4 c = vec4(0.0);
|
||||||
float size = stitchingSize;
|
float size = stitchingSize;
|
||||||
vec2 cPos = uv * vec2(renderWidth, renderHeight);
|
vec2 cPos = uv*vec2(renderWidth, renderHeight);
|
||||||
vec2 tlPos = floor(cPos / vec2(size, size));
|
vec2 tlPos = floor(cPos/vec2(size, size));
|
||||||
tlPos *= size;
|
tlPos *= size;
|
||||||
|
|
||||||
int remX = int(mod(cPos.x, size));
|
int remX = int(mod(cPos.x, size));
|
||||||
|
|
@ -38,11 +38,11 @@ vec4 PostFX(sampler2D tex, vec2 uv)
|
||||||
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
||||||
{
|
{
|
||||||
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
||||||
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
else c = texture2D(tex, tlPos*vec2(1.0/renderWidth, 1.0/renderHeight))*1.4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
if (invert == 1) c = texture2D(tex, tlPos*vec2(1.0/renderWidth, 1.0/renderHeight))*1.4;
|
||||||
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ float angle = 0.0;
|
||||||
vec2 VectorRotateTime(vec2 v, float speed)
|
vec2 VectorRotateTime(vec2 v, float speed)
|
||||||
{
|
{
|
||||||
float time = uTime*speed;
|
float time = uTime*speed;
|
||||||
float localTime = fract(time); // The time domain this works on is 1 sec.
|
float localTime = fract(time); // The time domain this works on is 1 sec
|
||||||
|
|
||||||
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
if ((localTime >= 0.0) && (localTime < 0.25)) angle = 0.0;
|
||||||
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
else if ((localTime >= 0.25) && (localTime < 0.50)) angle = PI/4.0*sin(2.0*PI*localTime - PI/2.0);
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@ uniform sampler2D gAlbedoSpec;
|
||||||
|
|
||||||
struct Light {
|
struct Light {
|
||||||
int enabled;
|
int enabled;
|
||||||
int type; // Unused in this demo.
|
int type; // Unused in this demo
|
||||||
vec3 position;
|
vec3 position;
|
||||||
vec3 target; // Unused in this demo.
|
vec3 target; // Unused in this demo
|
||||||
vec4 color;
|
vec4 color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ void main()
|
||||||
|
|
||||||
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;
|
||||||
vec3 diffuse = max(dot(normal, lightDirection), 0.0)*albedo*lights[i].color.xyz;
|
vec3 diffuse = max(dot(normal, lightDirection), 0.0)*albedo*lights[i].color.xyz;
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ void main()
|
||||||
|
|
||||||
// Attenuation
|
// Attenuation
|
||||||
float distance = length(lights[i].position - fragPosition);
|
float distance = length(lights[i].position - fragPosition);
|
||||||
float attenuation = 1.0/(1.0 + LINEAR * distance + QUADRATIC*distance*distance);
|
float attenuation = 1.0/(1.0 + LINEAR*distance + QUADRATIC*distance*distance);
|
||||||
diffuse *= attenuation;
|
diffuse *= attenuation;
|
||||||
specular *= attenuation;
|
specular *= attenuation;
|
||||||
ambient += diffuse + specular;
|
ambient += diffuse + specular;
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@ precision mediump float;
|
||||||
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
The Sieve of Eratosthenes -- a simple shader by ProfJski
|
||||||
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
An early prime number sieve: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||||
|
|
||||||
The screen is divided into a square grid of boxes, each representing an integer value.
|
The screen is divided into a square grid of boxes, each representing an integer value
|
||||||
Each integer is tested to see if it is a prime number. Primes are colored white.
|
Each integer is tested to see if it is a prime number. Primes are colored white
|
||||||
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer.
|
Non-primes are colored with a color that indicates the smallest factor which evenly divdes our integer
|
||||||
|
|
||||||
You can change the scale variable to make a larger or smaller grid.
|
You can change the scale variable to make a larger or smaller grid
|
||||||
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers.
|
Total number of integers displayed = scale squared, so scale = 100 tests the first 10,000 integers
|
||||||
|
|
||||||
WARNING: If you make scale too large, your GPU may bog down!
|
WARNING: If you make scale too large, your GPU may bog down!
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ vec4 Colorizer(float counter, float maxSize)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = vec4(1.0);
|
vec4 color = vec4(1.0);
|
||||||
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid.
|
float scale = 1000.0; // Makes 100x100 square grid. Change this variable to make a smaller or larger grid
|
||||||
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
float value = scale*floor(fragTexCoord.y*scale) + floor(fragTexCoord.x*scale); // Group pixels into boxes representing integer values
|
||||||
int valuei = int(value);
|
int valuei = int(value);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,22 +17,22 @@ const float PI = 3.1415926535;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float aperture = 178.0;
|
float aperture = 178.0;
|
||||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
float apertureHalf = 0.5*aperture*(PI/180.0);
|
||||||
float maxFactor = sin(apertureHalf);
|
float maxFactor = sin(apertureHalf);
|
||||||
|
|
||||||
vec2 uv = vec2(0.0);
|
vec2 uv = vec2(0.0);
|
||||||
vec2 xy = 2.0 * fragTexCoord.xy - 1.0;
|
vec2 xy = 2.0*fragTexCoord.xy - 1.0;
|
||||||
float d = length(xy);
|
float d = length(xy);
|
||||||
|
|
||||||
if (d < (2.0 - maxFactor))
|
if (d < (2.0 - maxFactor))
|
||||||
{
|
{
|
||||||
d = length(xy * maxFactor);
|
d = length(xy*maxFactor);
|
||||||
float z = sqrt(1.0 - d * d);
|
float z = sqrt(1.0 - d*d);
|
||||||
float r = atan(d, z) / PI;
|
float r = atan(d, z)/PI;
|
||||||
float phi = atan(xy.y, xy.x);
|
float phi = atan(xy.y, xy.x);
|
||||||
|
|
||||||
uv.x = r * cos(phi) + 0.5;
|
uv.x = r*cos(phi) + 0.5;
|
||||||
uv.y = r * sin(phi) + 0.5;
|
uv.y = r*sin(phi) + 0.5;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
#extension GL_EXT_frag_depth : enable // Extension required for writing depth
|
||||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||||
|
|
||||||
|
|
@ -11,6 +12,7 @@ uniform vec4 colDiffuse;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||||
|
|
||||||
gl_FragColor = texelColor*colDiffuse*fragColor;
|
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||||
gl_FragDepthEXT = gl_FragCoord.z;
|
gl_FragDepthEXT = gl_FragCoord.z;
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#version 100
|
#version 100
|
||||||
|
|
||||||
#extension GL_EXT_frag_depth : enable //Extension required for writing depth
|
#extension GL_EXT_frag_depth : enable //Extension required for writing depth
|
||||||
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
|
#extension GL_OES_standard_derivatives : enable //Extension used for fwidth()
|
||||||
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
precision mediump float; // Precision required for OpenGL ES2 (WebGL)
|
||||||
|
|
||||||
|
|
||||||
// Input vertex attributes (from vertex shader)
|
// Input vertex attributes (from vertex shader)
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
|
@ -19,21 +19,22 @@ uniform vec2 screenCenter;
|
||||||
|
|
||||||
#define ZERO 0
|
#define ZERO 0
|
||||||
|
|
||||||
// https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
// SRC: https://learnopengl.com/Advanced-OpenGL/Depth-testing
|
||||||
float CalcDepth(in vec3 rd, in float Idist){
|
float CalcDepth(in vec3 rd, in float Idist)
|
||||||
|
{
|
||||||
float local_z = dot(normalize(camDir),rd)*Idist;
|
float local_z = dot(normalize(camDir),rd)*Idist;
|
||||||
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
return (1.0/(local_z) - 1.0/0.01)/(1.0/1000.0 -1.0/0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/distfunctions/
|
// SRC: https://iquilezles.org/articles/distfunctions/
|
||||||
float sdHorseshoe( in vec3 p, in vec2 c, in float r, in float le, vec2 w )
|
float sdHorseshoe(in vec3 p, in vec2 c, in float r, in float le, vec2 w)
|
||||||
{
|
{
|
||||||
p.x = abs(p.x);
|
p.x = abs(p.x);
|
||||||
float l = length(p.xy);
|
float l = length(p.xy);
|
||||||
p.xy = mat2(-c.x, c.y,
|
p.xy = mat2(-c.x, c.y,
|
||||||
c.y, c.x)*p.xy;
|
c.y, c.x)*p.xy;
|
||||||
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
|
p.xy = vec2((p.y>0.0 || p.x>0.0)?p.x:l*sign(-c.x),
|
||||||
(p.x>0.0)?p.y:l );
|
(p.x>0.0)?p.y:l);
|
||||||
p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0);
|
p.xy = vec2(p.x,abs(p.y-r))-vec2(le,0.0);
|
||||||
|
|
||||||
vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z);
|
vec2 q = vec2(length(max(p.xy,0.0)) + min(0.0,max(p.x,p.y)),p.z);
|
||||||
|
|
@ -44,67 +45,70 @@ float sdHorseshoe( in vec3 p, in vec2 c, in float r, in float le, vec2 w )
|
||||||
// r = sphere's radius
|
// r = sphere's radius
|
||||||
// h = cutting's plane's position
|
// h = cutting's plane's position
|
||||||
// t = thickness
|
// t = thickness
|
||||||
float sdSixWayCutHollowSphere( vec3 p, float r, float h, float t )
|
float sdSixWayCutHollowSphere(vec3 p, float r, float h, float t)
|
||||||
{
|
{
|
||||||
// Six way symetry Transformation
|
// Six way symetry Transformation
|
||||||
vec3 ap = abs(p);
|
vec3 ap = abs(p);
|
||||||
if(ap.x < max(ap.y, ap.z)){
|
if (ap.x < max(ap.y, ap.z)){
|
||||||
if(ap.y < ap.z) ap.xz = ap.zx;
|
if (ap.y < ap.z) ap.xz = ap.zx;
|
||||||
else ap.xy = ap.yx;
|
else ap.xy = ap.yx;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 q = vec2( length(ap.yz), ap.x );
|
vec2 q = vec2(length(ap.yz), ap.x);
|
||||||
|
|
||||||
float w = sqrt(r*r-h*h);
|
float w = sqrt(r*r-h*h);
|
||||||
|
|
||||||
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) :
|
return ((h*q.x<w*q.y) ? length(q-vec2(w,h)) : abs(length(q)-r)) - t;
|
||||||
abs(length(q)-r) ) - t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/boxfunctions
|
// SRC: https://iquilezles.org/articles/boxfunctions
|
||||||
vec2 iBox( in vec3 ro, in vec3 rd, in vec3 rad )
|
vec2 iBox(in vec3 ro, in vec3 rd, in vec3 rad)
|
||||||
{
|
{
|
||||||
vec3 m = 1.0/rd;
|
vec3 m = 1.0/rd;
|
||||||
vec3 n = m*ro;
|
vec3 n = m*ro;
|
||||||
vec3 k = abs(m)*rad;
|
vec3 k = abs(m)*rad;
|
||||||
vec3 t1 = -n - k;
|
vec3 t1 = -n - k;
|
||||||
vec3 t2 = -n + k;
|
vec3 t2 = -n + k;
|
||||||
return vec2( max( max( t1.x, t1.y ), t1.z ),
|
|
||||||
min( min( t2.x, t2.y ), t2.z ) );
|
return vec2(max(max(t1.x, t1.y), t1.z),
|
||||||
|
min(min(t2.x, t2.y), t2.z));
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 opU( vec2 d1, vec2 d2 )
|
vec2 opU(vec2 d1, vec2 d2)
|
||||||
{
|
{
|
||||||
return (d1.x<d2.x) ? d1 : d2;
|
return (d1.x<d2.x) ? d1 : d2;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 map( in vec3 pos ){
|
vec2 map(in vec3 pos)
|
||||||
vec2 res = vec2( sdHorseshoe( pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5) ), 11.5 ) ;
|
{
|
||||||
res = opU(res, vec2( sdSixWayCutHollowSphere( pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5 ), 4.5 )) ;
|
vec2 res = vec2(sdHorseshoe(pos-vec3(-1.0,0.08, 1.0), vec2(cos(1.3),sin(1.3)), 0.2, 0.3, vec2(0.03,0.5)), 11.5) ;
|
||||||
|
res = opU(res, vec2(sdSixWayCutHollowSphere(pos-vec3(0.0, 1.0, 0.0), 4.0, 3.5, 0.5), 4.5)) ;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.shadertoy.com/view/Xds3zN
|
// SRC: https://www.shadertoy.com/view/Xds3zN
|
||||||
vec2 raycast( in vec3 ro, in vec3 rd ){
|
vec2 raycast(in vec3 ro, in vec3 rd)
|
||||||
|
{
|
||||||
vec2 res = vec2(-1.0,-1.0);
|
vec2 res = vec2(-1.0,-1.0);
|
||||||
|
|
||||||
float tmin = 1.0;
|
float tmin = 1.0;
|
||||||
float tmax = 20.0;
|
float tmax = 20.0;
|
||||||
|
|
||||||
// raytrace floor plane
|
// Raytrace floor plane
|
||||||
float tp1 = (-ro.y)/rd.y;
|
float tp1 = (-ro.y)/rd.y;
|
||||||
if( tp1>0.0 )
|
if (tp1>0.0)
|
||||||
{
|
{
|
||||||
tmax = min( tmax, tp1 );
|
tmax = min(tmax, tp1);
|
||||||
res = vec2( tp1, 1.0 );
|
res = vec2(tp1, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float t = tmin;
|
float t = tmin;
|
||||||
for( int i=0; i<70 ; i++ )
|
for (int i=0; i<70 ; i++)
|
||||||
{
|
{
|
||||||
if(t>tmax) break;
|
if (t>tmax) break;
|
||||||
vec2 h = map( ro+rd*t );
|
vec2 h = map(ro+rd*t);
|
||||||
if( abs(h.x)<(0.0001*t) )
|
if (abs(h.x) < (0.0001*t))
|
||||||
{
|
{
|
||||||
res = vec2(t,h.y);
|
res = vec2(t,h.y);
|
||||||
break;
|
break;
|
||||||
|
|
@ -117,54 +121,54 @@ vec2 raycast( in vec3 ro, in vec3 rd ){
|
||||||
|
|
||||||
|
|
||||||
// https://iquilezles.org/articles/rmshadows
|
// https://iquilezles.org/articles/rmshadows
|
||||||
float calcSoftshadow( in vec3 ro, in vec3 rd, in float mint, in float tmax )
|
float calcSoftshadow(in vec3 ro, in vec3 rd, in float mint, in float tmax)
|
||||||
{
|
{
|
||||||
// bounding volume
|
// bounding volume
|
||||||
float tp = (0.8-ro.y)/rd.y; if( tp>0.0 ) tmax = min( tmax, tp );
|
float tp = (0.8-ro.y)/rd.y; if (tp>0.0) tmax = min(tmax, tp);
|
||||||
|
|
||||||
float res = 1.0;
|
float res = 1.0;
|
||||||
float t = mint;
|
float t = mint;
|
||||||
for( int i=ZERO; i<24; i++ )
|
for (int i=ZERO; i<24; i++)
|
||||||
{
|
{
|
||||||
float h = map( ro + rd*t ).x;
|
float h = map(ro + rd*t).x;
|
||||||
float s = clamp(8.0*h/t,0.0,1.0);
|
float s = clamp(8.0*h/t,0.0,1.0);
|
||||||
res = min( res, s );
|
res = min(res, s);
|
||||||
t += clamp( h, 0.01, 0.2 );
|
t += clamp(h, 0.01, 0.2);
|
||||||
if( res<0.004 || t>tmax ) break;
|
if (res<0.004 || t>tmax) break;
|
||||||
}
|
}
|
||||||
res = clamp( res, 0.0, 1.0 );
|
res = clamp(res, 0.0, 1.0);
|
||||||
return res*res*(3.0-2.0*res);
|
return res*res*(3.0-2.0*res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://iquilezles.org/articles/normalsSDF
|
// https://iquilezles.org/articles/normalsSDF
|
||||||
vec3 calcNormal( in vec3 pos )
|
vec3 calcNormal(in vec3 pos)
|
||||||
{
|
{
|
||||||
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
|
vec2 e = vec2(1.0,-1.0)*0.5773*0.0005;
|
||||||
return normalize( e.xyy*map( pos + e.xyy ).x +
|
return normalize(e.xyy*map(pos + e.xyy).x +
|
||||||
e.yyx*map( pos + e.yyx ).x +
|
e.yyx*map(pos + e.yyx).x +
|
||||||
e.yxy*map( pos + e.yxy ).x +
|
e.yxy*map(pos + e.yxy).x +
|
||||||
e.xxx*map( pos + e.xxx ).x );
|
e.xxx*map(pos + e.xxx).x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/nvscene2008/rwwtt.pdf
|
// https://iquilezles.org/articles/nvscene2008/rwwtt.pdf
|
||||||
float calcAO( in vec3 pos, in vec3 nor )
|
float calcAO(in vec3 pos, in vec3 nor)
|
||||||
{
|
{
|
||||||
float occ = 0.0;
|
float occ = 0.0;
|
||||||
float sca = 1.0;
|
float sca = 1.0;
|
||||||
for( int i=ZERO; i<5; i++ )
|
for (int i=ZERO; i<5; i++)
|
||||||
{
|
{
|
||||||
float h = 0.01 + 0.12*float(i)/4.0;
|
float h = 0.01 + 0.12*float(i)/4.0;
|
||||||
float d = map( pos + h*nor ).x;
|
float d = map(pos + h*nor).x;
|
||||||
occ += (h-d)*sca;
|
occ += (h-d)*sca;
|
||||||
sca *= 0.95;
|
sca *= 0.95;
|
||||||
if( occ>0.35 ) break;
|
if (occ>0.35) break;
|
||||||
}
|
}
|
||||||
return clamp( 1.0 - 3.0*occ, 0.0, 1.0 ) * (0.5+0.5*nor.y);
|
return clamp(1.0 - 3.0*occ, 0.0, 1.0)*(0.5+0.5*nor.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://iquilezles.org/articles/checkerfiltering
|
// https://iquilezles.org/articles/checkerfiltering
|
||||||
float checkersGradBox( in vec2 p )
|
float checkersGradBox(in vec2 p)
|
||||||
{
|
{
|
||||||
// filter kernel
|
// filter kernel
|
||||||
vec2 w = fwidth(p) + 0.001;
|
vec2 w = fwidth(p) + 0.001;
|
||||||
|
|
@ -175,7 +179,7 @@ float checkersGradBox( in vec2 p )
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.shadertoy.com/view/tdS3DG
|
// https://www.shadertoy.com/view/tdS3DG
|
||||||
vec4 render( in vec3 ro, in vec3 rd)
|
vec4 render(in vec3 ro, in vec3 rd)
|
||||||
{
|
{
|
||||||
// background
|
// background
|
||||||
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
|
vec3 col = vec3(0.7, 0.7, 0.9) - max(rd.y,0.0)*0.3;
|
||||||
|
|
@ -183,37 +187,37 @@ vec4 render( in vec3 ro, in vec3 rd)
|
||||||
// raycast scene
|
// raycast scene
|
||||||
vec2 res = raycast(ro,rd);
|
vec2 res = raycast(ro,rd);
|
||||||
float t = res.x;
|
float t = res.x;
|
||||||
float m = res.y;
|
float m = res.y;
|
||||||
if( m>-0.5 )
|
if (m>-0.5)
|
||||||
{
|
{
|
||||||
vec3 pos = ro + t*rd;
|
vec3 pos = ro + t*rd;
|
||||||
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal( pos );
|
vec3 nor = (m<1.5) ? vec3(0.0,1.0,0.0) : calcNormal(pos);
|
||||||
vec3 ref = reflect( rd, nor );
|
vec3 ref = reflect(rd, nor);
|
||||||
|
|
||||||
// material
|
// material
|
||||||
col = 0.2 + 0.2*sin( m*2.0 + vec3(0.0,1.0,2.0) );
|
col = 0.2 + 0.2*sin(m*2.0 + vec3(0.0,1.0,2.0));
|
||||||
float ks = 1.0;
|
float ks = 1.0;
|
||||||
|
|
||||||
if( m<1.5 )
|
if (m<1.5)
|
||||||
{
|
{
|
||||||
float f = checkersGradBox( 3.0*pos.xz);
|
float f = checkersGradBox(3.0*pos.xz);
|
||||||
col = 0.15 + f*vec3(0.05);
|
col = 0.15 + f*vec3(0.05);
|
||||||
ks = 0.4;
|
ks = 0.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
float occ = calcAO( pos, nor );
|
float occ = calcAO(pos, nor);
|
||||||
|
|
||||||
vec3 lin = vec3(0.0);
|
vec3 lin = vec3(0.0);
|
||||||
|
|
||||||
// sun
|
// sun
|
||||||
{
|
{
|
||||||
vec3 lig = normalize( vec3(-0.5, 0.4, -0.6) );
|
vec3 lig = normalize(vec3(-0.5, 0.4, -0.6));
|
||||||
vec3 hal = normalize( lig-rd );
|
vec3 hal = normalize(lig-rd);
|
||||||
float dif = clamp( dot( nor, lig ), 0.0, 1.0 );
|
float dif = clamp(dot(nor, lig), 0.0, 1.0);
|
||||||
//if( dif>0.0001 )
|
//if (dif>0.0001)
|
||||||
dif *= calcSoftshadow( pos, lig, 0.02, 2.5 );
|
dif *= calcSoftshadow(pos, lig, 0.02, 2.5);
|
||||||
float spe = pow( clamp( dot( nor, hal ), 0.0, 1.0 ),16.0);
|
float spe = pow(clamp(dot(nor, hal), 0.0, 1.0),16.0);
|
||||||
spe *= dif;
|
spe *= dif;
|
||||||
spe *= 0.04+0.96*pow(clamp(1.0-dot(hal,lig),0.0,1.0),5.0);
|
spe *= 0.04+0.96*pow(clamp(1.0-dot(hal,lig),0.0,1.0),5.0);
|
||||||
//spe *= 0.04+0.96*pow(clamp(1.0-sqrt(0.5*(1.0-dot(rd,lig))),0.0,1.0),5.0);
|
//spe *= 0.04+0.96*pow(clamp(1.0-sqrt(0.5*(1.0-dot(rd,lig))),0.0,1.0),5.0);
|
||||||
|
|
@ -222,35 +226,35 @@ vec4 render( in vec3 ro, in vec3 rd)
|
||||||
}
|
}
|
||||||
// sky
|
// sky
|
||||||
{
|
{
|
||||||
float dif = sqrt(clamp( 0.5+0.5*nor.y, 0.0, 1.0 ));
|
float dif = sqrt(clamp(0.5+0.5*nor.y, 0.0, 1.0));
|
||||||
dif *= occ;
|
dif *= occ;
|
||||||
float spe = smoothstep( -0.2, 0.2, ref.y );
|
float spe = smoothstep(-0.2, 0.2, ref.y);
|
||||||
spe *= dif;
|
spe *= dif;
|
||||||
spe *= 0.04+0.96*pow(clamp(1.0+dot(nor,rd),0.0,1.0), 5.0 );
|
spe *= 0.04+0.96*pow(clamp(1.0+dot(nor,rd),0.0,1.0), 5.0);
|
||||||
//if( spe>0.001 )
|
//if (spe>0.001)
|
||||||
spe *= calcSoftshadow( pos, ref, 0.02, 2.5 );
|
spe *= calcSoftshadow(pos, ref, 0.02, 2.5);
|
||||||
lin += col*0.60*dif*vec3(0.40,0.60,1.15);
|
lin += col*0.60*dif*vec3(0.40,0.60,1.15);
|
||||||
lin += 2.00*spe*vec3(0.40,0.60,1.30)*ks;
|
lin += 2.00*spe*vec3(0.40,0.60,1.30)*ks;
|
||||||
}
|
}
|
||||||
// back
|
// back
|
||||||
{
|
{
|
||||||
float dif = clamp( dot( nor, normalize(vec3(0.5,0.0,0.6))), 0.0, 1.0 )*clamp( 1.0-pos.y,0.0,1.0);
|
float dif = clamp(dot(nor, normalize(vec3(0.5,0.0,0.6))), 0.0, 1.0)*clamp(1.0-pos.y,0.0,1.0);
|
||||||
dif *= occ;
|
dif *= occ;
|
||||||
lin += col*0.55*dif*vec3(0.25,0.25,0.25);
|
lin += col*0.55*dif*vec3(0.25,0.25,0.25);
|
||||||
}
|
}
|
||||||
// sss
|
// sss
|
||||||
{
|
{
|
||||||
float dif = pow(clamp(1.0+dot(nor,rd),0.0,1.0),2.0);
|
float dif = pow(clamp(1.0+dot(nor,rd),0.0,1.0),2.0);
|
||||||
dif *= occ;
|
dif *= occ;
|
||||||
lin += col*0.25*dif*vec3(1.00,1.00,1.00);
|
lin += col*0.25*dif*vec3(1.00,1.00,1.00);
|
||||||
}
|
}
|
||||||
|
|
||||||
col = lin;
|
col = lin;
|
||||||
|
|
||||||
col = mix( col, vec3(0.7,0.7,0.9), 1.0-exp( -0.0001*t*t*t ) );
|
col = mix(col, vec3(0.7,0.7,0.9), 1.0-exp(-0.0001*t*t*t));
|
||||||
}
|
}
|
||||||
|
|
||||||
return vec4(vec3( clamp(col,0.0,1.0) ),t);
|
return vec4(vec3(clamp(col,0.0,1.0)),t);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 CalcRayDir(vec2 nCoord){
|
vec3 CalcRayDir(vec2 nCoord){
|
||||||
|
|
@ -261,11 +265,11 @@ vec3 CalcRayDir(vec2 nCoord){
|
||||||
|
|
||||||
mat3 setCamera()
|
mat3 setCamera()
|
||||||
{
|
{
|
||||||
vec3 cw = normalize(camDir);
|
vec3 cw = normalize(camDir);
|
||||||
vec3 cp = vec3(0.0, 1.0 ,0.0);
|
vec3 cp = vec3(0.0, 1.0 ,0.0);
|
||||||
vec3 cu = normalize( cross(cw,cp) );
|
vec3 cu = normalize(cross(cw,cp));
|
||||||
vec3 cv = ( cross(cu,cw) );
|
vec3 cv = (cross(cu,cw));
|
||||||
return mat3( cu, cv, cw );
|
return mat3(cu, cv, cw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
@ -275,14 +279,14 @@ void main()
|
||||||
|
|
||||||
// focal length
|
// focal length
|
||||||
float fl = length(camDir);
|
float fl = length(camDir);
|
||||||
vec3 rd = ca * normalize( vec3(nCoord,fl) );
|
vec3 rd = ca*normalize(vec3(nCoord,fl));
|
||||||
vec3 color = vec3(nCoord/2.0 + 0.5, 0.0);
|
vec3 color = vec3(nCoord/2.0 + 0.5, 0.0);
|
||||||
float depth = gl_FragCoord.z;
|
float depth = gl_FragCoord.z;
|
||||||
{
|
{
|
||||||
vec4 res = render( camPos - vec3(0.0, 0.0, 0.0) , rd );
|
vec4 res = render(camPos - vec3(0.0, 0.0, 0.0) , rd);
|
||||||
color = res.xyz;
|
color = res.xyz;
|
||||||
depth = CalcDepth(rd,res.w);
|
depth = CalcDepth(rd,res.w);
|
||||||
}
|
}
|
||||||
gl_FragColor = vec4(color , 1.0);
|
gl_FragColor = vec4(color , 1.0);
|
||||||
gl_FragDepthEXT = depth;
|
gl_FragDepthEXT = depth;
|
||||||
}
|
}
|
||||||
|
|
@ -7,13 +7,13 @@ varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragColor;
|
||||||
|
|
||||||
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
uniform vec2 c; // c.x = real, c.y = imaginary component. Equation done is z^2 + c
|
||||||
uniform vec2 offset; // Offset of the scale.
|
uniform vec2 offset; // Offset of the scale
|
||||||
uniform float zoom; // Zoom of the scale.
|
uniform float zoom; // Zoom of the scale
|
||||||
|
|
||||||
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
// NOTE: Maximum number of shader for-loop iterations depend on GPU,
|
||||||
// for example, on RasperryPi for this examply only supports up to 60
|
// for example, on RasperryPi for this examply only supports up to 60
|
||||||
const int maxIterations = 48; // Max iterations to do.
|
const int maxIterations = 255; // Max iterations to do.
|
||||||
const float colorCycles = 1.0; // Number of times the color palette repeats.
|
const float colorCycles = 1.0; // Number of times the color palette repeats.
|
||||||
|
|
||||||
// Square a complex number
|
// Square a complex number
|
||||||
vec2 ComplexSquare(vec2 z)
|
vec2 ComplexSquare(vec2 z)
|
||||||
|
|
@ -32,22 +32,22 @@ vec3 Hsv2rgb(vec3 c)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
/**********************************************************************************************
|
/**********************************************************************************************
|
||||||
Julia sets use a function z^2 + c, where c is a constant.
|
Julia sets use a function z^2 + c, where c is a constant
|
||||||
This function is iterated until the nature of the point is determined.
|
This function is iterated until the nature of the point is determined
|
||||||
|
|
||||||
If the magnitude of the number becomes greater than 2, then from that point onward
|
If the magnitude of the number becomes greater than 2, then from that point onward
|
||||||
the number will get bigger and bigger, and will never get smaller (tends towards infinity).
|
the number will get bigger and bigger, and will never get smaller (tends towards infinity)
|
||||||
2^2 = 4, 4^2 = 8 and so on.
|
2^2 = 4, 4^2 = 8 and so on
|
||||||
So at 2 we stop iterating.
|
So at 2 we stop iterating
|
||||||
|
|
||||||
If the number is below 2, we keep iterating.
|
If the number is below 2, we keep iterating
|
||||||
But when do we stop iterating if the number is always below 2 (it converges)?
|
But when do we stop iterating if the number is always below 2 (it converges)?
|
||||||
That is what maxIterations is for.
|
That is what maxIterations is for
|
||||||
Then we can divide the iterations by the maxIterations value to get a normalized value that we can
|
Then we can divide the iterations by the maxIterations value to get a normalized value
|
||||||
then map to a color.
|
that we can then map to a color
|
||||||
|
|
||||||
We use dot product (z.x * z.x + z.y * z.y) to determine the magnitude (length) squared.
|
We use dot product (z.x*z.x + z.y*z.y) to determine the magnitude (length) squared
|
||||||
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power).
|
And once the magnitude squared is > 4, then magnitude > 2 is also true (saves computational power)
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
// The pixel coordinates are scaled so they are on the mandelbrot scale
|
||||||
|
|
@ -57,7 +57,7 @@ void main()
|
||||||
z.y += offset.y;
|
z.y += offset.y;
|
||||||
|
|
||||||
int iter = 0;
|
int iter = 0;
|
||||||
for (int iterations = 0; iterations < 60; iterations++)
|
for (int iterations = 0; iterations < maxIterations; iterations++)
|
||||||
{
|
{
|
||||||
z = ComplexSquare(z) + c; // Iterate function
|
z = ComplexSquare(z) + c; // Iterate function
|
||||||
if (dot(z, z) > 4.0) break;
|
if (dot(z, z) > 4.0) break;
|
||||||
|
|
@ -65,18 +65,18 @@ void main()
|
||||||
iter = iterations;
|
iter = iterations;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Another few iterations decreases errors in the smoothing calculation.
|
// Another few iterations decreases errors in the smoothing calculation
|
||||||
// See http://linas.org/art-gallery/escape/escape.html for more information.
|
// See http://linas.org/art-gallery/escape/escape.html for more information
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
z = ComplexSquare(z) + c;
|
z = ComplexSquare(z) + c;
|
||||||
|
|
||||||
// This last part smooths the color (again see link above).
|
// This last part smooths the color (again see link above)
|
||||||
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
float smoothVal = float(iter) + 1.0 - (log(log(length(z)))/log(2.0));
|
||||||
|
|
||||||
// Normalize the value so it is between 0 and 1.
|
// Normalize the value so it is between 0 and 1
|
||||||
float norm = smoothVal/float(maxIterations);
|
float norm = smoothVal/float(maxIterations);
|
||||||
|
|
||||||
// If in set, color black. 0.999 allows for some float accuracy error.
|
// If in set, color black. 0.999 allows for some float accuracy error
|
||||||
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
if (norm > 0.999) gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
else gl_FragColor = vec4(Hsv2rgb(vec3(norm*colorCycles, 1.0, 1.0)), 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user