mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-06 14:19:18 -05:00
Compare commits
40 Commits
a6f29e4f19
...
17aec580f8
| Author | SHA1 | Date | |
|---|---|---|---|
| 17aec580f8 | |||
| c6171d339c | |||
| df40357f19 | |||
| 570082deba | |||
| 6792e6e2dd | |||
| 2365ac8def | |||
| 54473e2c2b | |||
| 47d1cc200d | |||
| 8da4887c2d | |||
| ea3932949c | |||
| a06962ee38 | |||
| c19c6fc6e0 | |||
| 948b48430d | |||
| 881c68e323 | |||
| ca61b8d555 | |||
| f0889a74fe | |||
| 9f07cfe0b7 | |||
| f02c7fca8a | |||
| d45b00b191 | |||
| 7e597dd574 | |||
| 9003cd32ba | |||
| 366887b863 | |||
| 64fbf07e7b | |||
| 5d4a233f52 | |||
| fd79b44920 | |||
| 5eacc872c7 | |||
| 1fadc67fb3 | |||
| ff1087480c | |||
| c91c185221 | |||
| 89e6ed2697 | |||
| fa5560881e | |||
| 36dc70443a | |||
| 1c2ecfd6ab | |||
| 5dc304b5a7 | |||
| 32026ca78b | |||
| 86d2db2aa9 | |||
| 9a578dbce0 | |||
| a94feef6d0 | |||
| 897a8fbc9f | |||
| 510dc763e9 |
6
.github/workflows/linux.yml
vendored
6
.github/workflows/linux.yml
vendored
@ -30,17 +30,17 @@ jobs:
|
|||||||
- bits: 32
|
- bits: 32
|
||||||
ARCH: "i386"
|
ARCH: "i386"
|
||||||
ARCH_NAME: "i386"
|
ARCH_NAME: "i386"
|
||||||
COMPILER_PATH: "/user/bin"
|
COMPILER_PATH: "/usr/bin"
|
||||||
runner: "ubuntu-latest"
|
runner: "ubuntu-latest"
|
||||||
- bits: 64
|
- bits: 64
|
||||||
ARCH: "x86_64"
|
ARCH: "x86_64"
|
||||||
ARCH_NAME: "amd64"
|
ARCH_NAME: "amd64"
|
||||||
COMPILER_PATH: "/user/bin"
|
COMPILER_PATH: "/usr/bin"
|
||||||
runner: "ubuntu-latest"
|
runner: "ubuntu-latest"
|
||||||
- bits: 64
|
- bits: 64
|
||||||
ARCH: "aarch64"
|
ARCH: "aarch64"
|
||||||
ARCH_NAME: "arm64"
|
ARCH_NAME: "arm64"
|
||||||
COMPILER_PATH: "/user/bin"
|
COMPILER_PATH: "/usr/bin"
|
||||||
runner: "ubuntu-24.04-arm"
|
runner: "ubuntu-24.04-arm"
|
||||||
|
|
||||||
runs-on: ${{ matrix.runner }}
|
runs-on: ${{ matrix.runner }}
|
||||||
|
|||||||
@ -145,7 +145,6 @@ These are older raylib bindings that are more than 2 versions old or have not be
|
|||||||
| [clj-raylib](https://github.com/lsevero/clj-raylib) | 3.0 | [Clojure](https://clojure.org) |
|
| [clj-raylib](https://github.com/lsevero/clj-raylib) | 3.0 | [Clojure](https://clojure.org) |
|
||||||
| [QuickJS-raylib](https://github.com/sntg-p/QuickJS-raylib) | 3.0 | [QuickJS](https://bellard.org/quickjs) |
|
| [QuickJS-raylib](https://github.com/sntg-p/QuickJS-raylib) | 3.0 | [QuickJS](https://bellard.org/quickjs) |
|
||||||
| [raylib-duktape](https://github.com/RobLoach/raylib-duktape) | 2.6 | [JavaScript (Duktape)](https://en.wikipedia.org/wiki/JavaScript) |
|
| [raylib-duktape](https://github.com/RobLoach/raylib-duktape) | 2.6 | [JavaScript (Duktape)](https://en.wikipedia.org/wiki/JavaScript) |
|
||||||
| [raylib-v7](https://github.com/Rabios/raylib-v7) | 3.5 | [JavaScript (v7)](https://en.wikipedia.org/wiki/JavaScript) |
|
|
||||||
| [raylib-chaiscript](https://github.com/RobLoach/raylib-chaiscript) | 2.6 | [ChaiScript](http://chaiscript.com) |
|
| [raylib-chaiscript](https://github.com/RobLoach/raylib-chaiscript) | 2.6 | [ChaiScript](http://chaiscript.com) |
|
||||||
| [raylib-squirrel](https://github.com/RobLoach/raylib-squirrel) | 2.5 | [Squirrel](http://www.squirrel-lang.org) |
|
| [raylib-squirrel](https://github.com/RobLoach/raylib-squirrel) | 2.5 | [Squirrel](http://www.squirrel-lang.org) |
|
||||||
| [racket-raylib-2d](https://github.com/arvyy/racket-raylib-2d) | 2.5 | [Racket](https://racket-lang.org) |
|
| [racket-raylib-2d](https://github.com/arvyy/racket-raylib-2d) | 2.5 | [Racket](https://racket-lang.org) |
|
||||||
|
|||||||
@ -28,6 +28,10 @@ Some other conventions to follow:
|
|||||||
- **ALWAYS** initialize all defined variables.
|
- **ALWAYS** initialize all defined variables.
|
||||||
- **Do not use TABS**, use 4 spaces instead.
|
- **Do not use TABS**, use 4 spaces instead.
|
||||||
- Avoid trailing spaces, please, avoid them
|
- Avoid trailing spaces, please, avoid them
|
||||||
|
- Comments always start with space + capital letter and never end with a '.', place them **before** the line(s) they refer to
|
||||||
|
```c
|
||||||
|
// This is a comment in raylib or raylib examples
|
||||||
|
```
|
||||||
- Control flow statements always are followed **by a space**:
|
- Control flow statements always are followed **by a space**:
|
||||||
```c
|
```c
|
||||||
if (condition) value = 0;
|
if (condition) value = 0;
|
||||||
|
|||||||
@ -639,6 +639,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_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching \
|
shaders/shaders_raymarching \
|
||||||
|
|||||||
@ -639,6 +639,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_palette_switch \
|
shaders/shaders_palette_switch \
|
||||||
shaders/shaders_postprocessing \
|
shaders/shaders_postprocessing \
|
||||||
shaders/shaders_raymarching \
|
shaders/shaders_raymarching \
|
||||||
@ -1201,6 +1202,14 @@ 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
|
||||||
|
$(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.fs@resources/shaders/glsl100/normalmap.fs \
|
||||||
|
--preload-file shaders/resources/models/plane.glb@resources/models/plane.glb \
|
||||||
|
--preload-file shaders/resources/tiles_diffuse.png@resources/tiles_diffuse.png \
|
||||||
|
--preload-file shaders/resources/tiles_normal.png@resources/tiles_normal.png
|
||||||
|
|
||||||
shaders/shaders_palette_switch: shaders/shaders_palette_switch.c
|
shaders/shaders_palette_switch: shaders/shaders_palette_switch.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/palette_switch.fs@resources/shaders/glsl100/palette_switch.fs
|
--preload-file shaders/resources/shaders/glsl100/palette_switch.fs@resources/shaders/glsl100/palette_switch.fs
|
||||||
|
|||||||
@ -16,8 +16,7 @@ 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: 159]
|
## EXAMPLES COLLECTION [TOTAL: 160]
|
||||||
|
|
||||||
|
|
||||||
### category: core [36]
|
### category: core [36]
|
||||||
|
|
||||||
@ -171,7 +170,7 @@ Examples using raylib models functionality, including models loading/generation
|
|||||||
| [models_bone_socket](models/models_bone_socket.c) | <img src="models/models_bone_socket.png" alt="models_bone_socket" width="80"> | ⭐⭐⭐⭐️ | 4.5 | 4.5 | [iP](https://github.com/ipzaur) |
|
| [models_bone_socket](models/models_bone_socket.c) | <img src="models/models_bone_socket.png" alt="models_bone_socket" width="80"> | ⭐⭐⭐⭐️ | 4.5 | 4.5 | [iP](https://github.com/ipzaur) |
|
||||||
| [models_tesseract_view](models/models_tesseract_view.c) | <img src="models/models_tesseract_view.png" alt="models_tesseract_view" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Timothy van der Valk](https://github.com/arceryz) |
|
| [models_tesseract_view](models/models_tesseract_view.c) | <img src="models/models_tesseract_view.png" alt="models_tesseract_view" width="80"> | ⭐⭐☆☆ | 5.6 | 5.6 | [Timothy van der Valk](https://github.com/arceryz) |
|
||||||
|
|
||||||
### category: shaders [28]
|
### category: shaders [29]
|
||||||
|
|
||||||
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.c) module.
|
Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.c) module.
|
||||||
|
|
||||||
@ -194,6 +193,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_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) |
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Mixed audio processing
|
* raylib [audio] example - mixed audio processing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -108,8 +108,6 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Sample mouse input.
|
|
||||||
mousePosition = GetMousePosition();
|
mousePosition = GetMousePosition();
|
||||||
|
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
|
||||||
@ -125,7 +123,7 @@ int main(void)
|
|||||||
// Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc.
|
// Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc.
|
||||||
if (frequency != oldFrequency)
|
if (frequency != oldFrequency)
|
||||||
{
|
{
|
||||||
// Compute wavelength. Limit size in both directions.
|
// Compute wavelength. Limit size in both directions
|
||||||
//int oldWavelength = waveLength;
|
//int oldWavelength = waveLength;
|
||||||
waveLength = (int)(22050/frequency);
|
waveLength = (int)(22050/frequency);
|
||||||
if (waveLength > MAX_SAMPLES/2) waveLength = MAX_SAMPLES/2;
|
if (waveLength > MAX_SAMPLES/2) waveLength = MAX_SAMPLES/2;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Playing sound multiple times
|
* raylib [audio] example - sound alias
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@ -31,18 +31,18 @@ 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 - playing sound multiple times");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound alias");
|
||||||
|
|
||||||
InitAudioDevice(); // Initialize audio device
|
InitAudioDevice(); // Initialize audio device
|
||||||
|
|
||||||
// load the sound list
|
// Load audio file into the first slot as the 'source' sound,
|
||||||
soundArray[0] = LoadSound("resources/sound.wav"); // Load WAV audio file into the first slot as the 'source' sound
|
// this sound owns the sample data
|
||||||
// this sound owns the sample data
|
soundArray[0] = LoadSound("resources/sound.wav");
|
||||||
for (int i = 1; i < MAX_SOUNDS; i++)
|
|
||||||
{
|
// Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
|
||||||
soundArray[i] = LoadSoundAlias(soundArray[0]); // Load an alias of the sound into slots 1-9. These do not own the sound data, but can be played
|
for (int i = 1; i < MAX_SOUNDS; i++) soundArray[i] = LoadSoundAlias(soundArray[0]);
|
||||||
}
|
|
||||||
currentSound = 0; // set the sound list to the start
|
currentSound = 0; // Set the sound list to the start
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
@ -54,14 +54,15 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyPressed(KEY_SPACE))
|
if (IsKeyPressed(KEY_SPACE))
|
||||||
{
|
{
|
||||||
PlaySound(soundArray[currentSound]); // play the next open sound slot
|
PlaySound(soundArray[currentSound]); // Play the next open sound slot
|
||||||
currentSound++; // increment the sound slot
|
currentSound++; // Increment the sound slot
|
||||||
if (currentSound >= MAX_SOUNDS) // if the sound slot is out of bounds, go back to 0
|
|
||||||
currentSound = 0;
|
|
||||||
|
|
||||||
// Note: a better way would be to look at the list for the first sound that is not playing and use that slot
|
// If the sound slot is out of bounds, go back to 0
|
||||||
|
if (currentSound >= MAX_SOUNDS) currentSound = 0;
|
||||||
|
|
||||||
|
// NOTE: Another approach would be to look at the list for the first sound
|
||||||
|
// that is not playing and use that slot
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@ -78,9 +79,8 @@ int main(void)
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
for (int i = 1; i < MAX_SOUNDS; i++)
|
for (int i = 1; i < MAX_SOUNDS; i++) UnloadSoundAlias(soundArray[i]); // Unload sound aliases
|
||||||
UnloadSoundAlias(soundArray[i]); // Unload sound aliases
|
UnloadSound(soundArray[0]); // Unload source sound data
|
||||||
UnloadSound(soundArray[0]); // Unload source sound data
|
|
||||||
|
|
||||||
CloseAudioDevice(); // Close audio device
|
CloseAudioDevice(); // Close audio device
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [audio] example - Playing spatialized 3D sound
|
* raylib [audio] example - spatialized 3D sound
|
||||||
*
|
*
|
||||||
* 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 - Playing spatialized 3D sound");
|
InitWindow(screenWidth, screenHeight, "raylib [audio] example - spatialized 3D sound");
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
* 4. PollInputEvents()
|
* 4. PollInputEvents()
|
||||||
*
|
*
|
||||||
* To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in
|
* To avoid steps 2, 3 and 4, flag SUPPORT_CUSTOM_FRAME_CONTROL can be enabled in
|
||||||
* config.h (it requires recompiling raylib). This way those steps are up to the user.
|
* config.h (it requires recompiling raylib). This way those steps are up to the user
|
||||||
*
|
*
|
||||||
* Note that enabling this flag invalidates some functions:
|
* Note that enabling this flag invalidates some functions:
|
||||||
* - GetFrameTime()
|
* - GetFrameTime()
|
||||||
|
|||||||
@ -13,12 +13,10 @@
|
|||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
//------------------------------------------------------------------------------------
|
||||||
{
|
// Module functions declaration
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
//------------------------------------------------------------------------------------
|
||||||
Vector2 pos = (Vector2){x - size.x/2, y - size.y/2 };
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
@ -31,10 +29,20 @@ 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 - highdpi");
|
||||||
SetWindowMinSize(450, 450);
|
SetWindowMinSize(450, 450);
|
||||||
|
|
||||||
|
int logicalGridDescY = 120;
|
||||||
|
int logicalGridLabelY = logicalGridDescY + 30;
|
||||||
|
int logicalGridTop = logicalGridLabelY + 30;
|
||||||
|
int logicalGridBottom = logicalGridTop + 80;
|
||||||
|
int pixelGridTop = logicalGridBottom - 20;
|
||||||
|
int pixelGridBottom = pixelGridTop + 80;
|
||||||
|
int pixelGridLabelY = pixelGridBottom + 30;
|
||||||
|
int pixelGridDescY = pixelGridLabelY + 30;
|
||||||
|
int cellSize = 50;
|
||||||
|
float cellSizePx = (float)cellSize;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -44,67 +52,60 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
int monitorCount = GetMonitorCount();
|
int monitorCount = GetMonitorCount();
|
||||||
if (monitorCount > 1 && IsKeyPressed(KEY_N)) {
|
|
||||||
SetWindowMonitor((GetCurrentMonitor() + 1) % monitorCount);
|
if ((monitorCount > 1) && IsKeyPressed(KEY_N))
|
||||||
|
{
|
||||||
|
SetWindowMonitor((GetCurrentMonitor() + 1)%monitorCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentMonitor = GetCurrentMonitor();
|
int currentMonitor = GetCurrentMonitor();
|
||||||
|
Vector2 dpiScale = GetWindowScaleDPI();
|
||||||
|
cellSizePx = ((float)cellSize)/dpiScale.x;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
Vector2 dpiScale = GetWindowScaleDPI();
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
int windowCenter = GetScreenWidth() / 2;
|
int windowCenter = GetScreenWidth()/2;
|
||||||
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
DrawTextCenter(TextFormat("Dpi Scale: %f", dpiScale.x), windowCenter, 30, 40, DARKGRAY);
|
||||||
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 16, LIGHTGRAY);
|
DrawTextCenter(TextFormat("Monitor: %d/%d ([N] next monitor)", currentMonitor+1, monitorCount), windowCenter, 70, 20, LIGHTGRAY);
|
||||||
|
|
||||||
const int logicalGridDescY = 120;
|
|
||||||
const int logicalGridLabelY = logicalGridDescY + 30;
|
|
||||||
const int logicalGridTop = logicalGridLabelY + 30;
|
|
||||||
const int logicalGridBottom = logicalGridTop + 80;
|
|
||||||
const int pixelGridTop = logicalGridBottom - 20;
|
|
||||||
const int pixelGridBottom = pixelGridTop + 80;
|
|
||||||
const int pixelGridLabelY = pixelGridBottom + 30;
|
|
||||||
const int pixelGridDescY = pixelGridLabelY + 30;
|
|
||||||
|
|
||||||
const int cellSize = 50;
|
|
||||||
const float cellSizePx = ((float)cellSize) / dpiScale.x;
|
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
DrawTextCenter(TextFormat("Window is %d \"logical points\" wide", GetScreenWidth()), windowCenter, logicalGridDescY, 20, ORANGE);
|
||||||
|
|
||||||
bool odd = true;
|
bool odd = true;
|
||||||
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetScreenWidth(); i += cellSize, odd = !odd)
|
||||||
if (odd) {
|
{
|
||||||
DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
if (odd) DrawRectangle(i, logicalGridTop, cellSize, logicalGridBottom-logicalGridTop, ORANGE);
|
||||||
}
|
|
||||||
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 12, LIGHTGRAY);
|
DrawTextCenter(TextFormat("%d", i), i, logicalGridLabelY, 10, LIGHTGRAY);
|
||||||
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
DrawLine(i, logicalGridLabelY + 10, i, logicalGridBottom, GRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
odd = true;
|
odd = true;
|
||||||
const int minTextSpace = 30;
|
const int minTextSpace = 30;
|
||||||
int last_text_x = -minTextSpace;
|
int lastTextX = -minTextSpace;
|
||||||
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd) {
|
for (int i = cellSize; i < GetRenderWidth(); i += cellSize, odd = !odd)
|
||||||
int x = (int)(((float)i) / dpiScale.x);
|
{
|
||||||
if (odd) {
|
int x = (int)(((float)i)/dpiScale.x);
|
||||||
DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom-pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
if (odd) DrawRectangle(x, pixelGridTop, (int)cellSizePx, pixelGridBottom - pixelGridTop, CLITERAL(Color){ 0, 121, 241, 100 });
|
||||||
}
|
|
||||||
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
DrawLine(x, pixelGridTop, (int)(((float)i) / dpiScale.x), pixelGridLabelY - 10, GRAY);
|
||||||
if (x - last_text_x >= minTextSpace) {
|
|
||||||
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 12, LIGHTGRAY);
|
if ((x - lastTextX) >= minTextSpace)
|
||||||
last_text_x = x;
|
{
|
||||||
|
DrawTextCenter(TextFormat("%d", i), x, pixelGridLabelY, 10, LIGHTGRAY);
|
||||||
|
lastTextX = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
DrawTextCenter(TextFormat("Window is %d \"physical pixels\" wide", GetRenderWidth()), windowCenter, pixelGridDescY, 20, BLUE);
|
||||||
|
|
||||||
{
|
const char *text = "Can you see this?";
|
||||||
const char *text = "Can you see this?";
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, 20, 3);
|
||||||
Vector2 size = MeasureTextEx(GetFontDefault(), text, 16, 3);
|
Vector2 pos = (Vector2){ GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5 };
|
||||||
Vector2 pos = (Vector2){GetScreenWidth() - size.x - 5, GetScreenHeight() - size.y - 5};
|
DrawTextEx(GetFontDefault(), text, pos, 20, 3, LIGHTGRAY);
|
||||||
DrawTextEx(GetFontDefault(), text, pos, 16, 3, LIGHTGRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -117,3 +118,13 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module functions definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void DrawTextCenter(const char *text, int x, int y, int fontSize, Color color)
|
||||||
|
{
|
||||||
|
Vector2 size = MeasureTextEx(GetFontDefault(), text, (float)fontSize, 3);
|
||||||
|
Vector2 pos = (Vector2){ x - size.x/2, y - size.y/2 };
|
||||||
|
DrawTextEx(GetFontDefault(), text, pos, (float)fontSize, 3, color);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [core] example - Generates a random sequence
|
* raylib [core] example - generate random sequence
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
@ -43,7 +43,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 - Generates a random sequence");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - generate random sequence");
|
||||||
|
|
||||||
int rectCount = 20;
|
int rectCount = 20;
|
||||||
float rectSize = (float)screenWidth/rectCount;
|
float rectSize = (float)screenWidth/rectCount;
|
||||||
|
|||||||
@ -43,7 +43,8 @@ int main(void)
|
|||||||
Camera2D screenSpaceCamera = { 0 }; // Smoothing camera
|
Camera2D screenSpaceCamera = { 0 }; // Smoothing camera
|
||||||
screenSpaceCamera.zoom = 1.0f;
|
screenSpaceCamera.zoom = 1.0f;
|
||||||
|
|
||||||
RenderTexture2D target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight); // This is where we'll draw all our objects.
|
// Load render texture to draw all our objects
|
||||||
|
RenderTexture2D target = LoadRenderTexture(virtualScreenWidth, virtualScreenHeight);
|
||||||
|
|
||||||
Rectangle rec01 = { 70.0f, 35.0f, 20.0f, 20.0f };
|
Rectangle rec01 = { 70.0f, 35.0f, 20.0f, 20.0f };
|
||||||
Rectangle rec02 = { 90.0f, 55.0f, 30.0f, 10.0f };
|
Rectangle rec02 = { 90.0f, 55.0f, 30.0f, 10.0f };
|
||||||
|
|||||||
50
examples/core/resources/shaders/glsl120/distortion.fs
Normal file
50
examples/core/resources/shaders/glsl120/distortion.fs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
uniform vec2 leftLensCenter;
|
||||||
|
uniform vec2 rightLensCenter;
|
||||||
|
uniform vec2 leftScreenCenter;
|
||||||
|
uniform vec2 rightScreenCenter;
|
||||||
|
uniform vec2 scale;
|
||||||
|
uniform vec2 scaleIn;
|
||||||
|
uniform vec4 deviceWarpParam;
|
||||||
|
uniform vec4 chromaAbParam;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Compute lens distortion
|
||||||
|
vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter;
|
||||||
|
vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter;
|
||||||
|
vec2 theta = (fragTexCoord - lensCenter)*scaleIn;
|
||||||
|
float rSq = theta.x*theta.x + theta.y*theta.y;
|
||||||
|
vec2 theta1 = theta*(deviceWarpParam.x + deviceWarpParam.y*rSq + deviceWarpParam.z*rSq*rSq + deviceWarpParam.w*rSq*rSq*rSq);
|
||||||
|
vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq);
|
||||||
|
vec2 tcBlue = lensCenter + scale*thetaBlue;
|
||||||
|
|
||||||
|
if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue)))
|
||||||
|
{
|
||||||
|
// Set black fragment for everything outside the lens border
|
||||||
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Compute color chroma aberration
|
||||||
|
float blue = texture2D(texture0, tcBlue).b;
|
||||||
|
vec2 tcGreen = lensCenter + scale*theta1;
|
||||||
|
float green = texture2D(texture0, tcGreen).g;
|
||||||
|
|
||||||
|
vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq);
|
||||||
|
vec2 tcRed = lensCenter + scale*thetaRed;
|
||||||
|
|
||||||
|
float red = texture2D(texture0, tcRed).r;
|
||||||
|
gl_FragColor = vec4(red, green, blue, 1.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -141,6 +141,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_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
|
||||||
|
|||||||
@ -6,30 +6,30 @@
|
|||||||
|
|
||||||
1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
|
1. File naming: <module>_<description> - Lower case filename, words separated by underscore,
|
||||||
no more than 3-4 words in total to describe the example. <module> referes to the primary
|
no more than 3-4 words in total to describe the example. <module> referes to the primary
|
||||||
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio).
|
raylib module the example is more related with (code, shapes, textures, models, shaders, raudio)
|
||||||
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
|
i.e: core_input_multitouch, shapes_lines_bezier, shaders_palette_switch
|
||||||
|
|
||||||
2. Follow below template structure, example info should list the module, the short description
|
2. Follow below template structure, example info should list the module, the short description
|
||||||
and the author of the example, twitter or github info could be also provided for the author.
|
and the author of the example, twitter or github info could be also provided for the author
|
||||||
Short description should also be used on the title of the window.
|
Short description should also be used on the title of the window
|
||||||
|
|
||||||
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
|
3. Code should be organized by sections:[Initialization]- [Update] - [Draw] - [De-Initialization]
|
||||||
Place your code between the dotted lines for every section, please don't mix update logic with drawing
|
Place your code between the dotted lines for every section, please don't mix update logic with drawing
|
||||||
and remember to unload all loaded resources.
|
and remember to unload all loaded resources
|
||||||
|
|
||||||
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
|
4. Code should follow raylib conventions: https://github.com/raysan5/raylib/wiki/raylib-coding-conventions
|
||||||
Try to be very organized, using line-breaks appropiately.
|
Try to be very organized, using line-breaks appropiately
|
||||||
|
|
||||||
5. Add comments to the specific parts of code the example is focus on.
|
5. Add comments to the specific parts of code the example is focus on
|
||||||
Don't abuse with comments, try to be clear and impersonal on the comments.
|
Don't abuse with comments, try to be clear and impersonal on the comments
|
||||||
|
|
||||||
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies.
|
6. Try to keep the example simple, under 300 code lines if possible. Try to avoid external dependencies
|
||||||
Try to avoid defining functions outside the main(). Example should be as self-contained as possible.
|
Try to avoid defining functions outside the main(). Example should be as self-contained as possible
|
||||||
|
|
||||||
7. About external resources, they should be placed in a [resources] folder and those resources
|
7. About external resources, they should be placed in a [resources] folder and those resources
|
||||||
should be open and free for use and distribution. Avoid propietary content.
|
should be open and free for use and distribution. Avoid propietary content
|
||||||
|
|
||||||
8. Try to keep the example simple but with a creative touch.
|
8. Try to keep the example simple but with a creative touch
|
||||||
Simple but beautiful examples are more appealing to users!
|
Simple but beautiful examples are more appealing to users!
|
||||||
|
|
||||||
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
|
9. In case of additional information is required, just come to raylib Discord channel: example-contributions
|
||||||
@ -37,7 +37,7 @@
|
|||||||
10. Have fun!
|
10. Have fun!
|
||||||
|
|
||||||
The following files should be updated when adding a new example, it's planned to create some
|
The following files should be updated when adding a new example, it's planned to create some
|
||||||
script to automatize this process but not available yet.
|
script to automatize this process but not available yet
|
||||||
|
|
||||||
- raylib/examples/<category>/<category>_example_name.c
|
- raylib/examples/<category>/<category>_example_name.c
|
||||||
- raylib/examples/<category>/<category>_example_name.png
|
- raylib/examples/<category>/<category>_example_name.png
|
||||||
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [<module>] example - <name>
|
* raylib [<module>] example - <name/short description>
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
*
|
*
|
||||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
||||||
* in the same position as they would be in edit mode and the scale of your models is
|
* in the same position as they would be in edit mode and the scale of your models is
|
||||||
* set to 0. Scaling can be done from the export menu.
|
* set to 0. Scaling can be done from the export menu
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ int main(void)
|
|||||||
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
|
Vector3 billPositionStatic = { 0.0f, 2.0f, 0.0f }; // Position of static billboard
|
||||||
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
|
Vector3 billPositionRotating = { 1.0f, 2.0f, 1.0f }; // Position of rotating billboard
|
||||||
|
|
||||||
// Entire billboard texture, source is used to take a segment from a larger texture.
|
// Entire billboard texture, source is used to take a segment from a larger texture
|
||||||
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
|
Rectangle source = { 0.0f, 0.0f, (float)bill.width, (float)bill.height };
|
||||||
|
|
||||||
// NOTE: Billboard locked on axis-Y
|
// NOTE: Billboard locked on axis-Y
|
||||||
@ -54,7 +54,7 @@ int main(void)
|
|||||||
Vector2 origin = Vector2Scale(size, 0.5f);
|
Vector2 origin = Vector2Scale(size, 0.5f);
|
||||||
|
|
||||||
// Distance is needed for the correct billboard draw order
|
// Distance is needed for the correct billboard draw order
|
||||||
// Larger distance (further away from the camera) should be drawn prior to smaller distance.
|
// Larger distance (further away from the camera) should be drawn prior to smaller distance
|
||||||
float distanceStatic;
|
float distanceStatic;
|
||||||
float distanceRotating;
|
float distanceRotating;
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
|
|||||||
@ -7,11 +7,11 @@
|
|||||||
* NOTE: raylib supports multiple models file formats:
|
* NOTE: raylib supports multiple models file formats:
|
||||||
*
|
*
|
||||||
* - OBJ > Text file format. Must include vertex position-texcoords-normals information,
|
* - OBJ > Text file format. Must include vertex position-texcoords-normals information,
|
||||||
* if files references some .mtl materials file, it will be loaded (or try to).
|
* if files references some .mtl materials file, it will be loaded (or try to)
|
||||||
* - GLTF > Text/binary file format. Includes lot of information and it could
|
* - GLTF > Text/binary file format. Includes lot of information and it could
|
||||||
* also reference external files, raylib will try loading mesh and materials data.
|
* also reference external files, raylib will try loading mesh and materials data
|
||||||
* - IQM > Binary file format. Includes mesh vertex data but also animation data,
|
* - IQM > Binary file format. Includes mesh vertex data but also animation data,
|
||||||
* raylib can load .iqm animations.
|
* raylib can load .iqm animations
|
||||||
* - VOX > Binary file format. MagikaVoxel mesh format:
|
* - VOX > Binary file format. MagikaVoxel mesh format:
|
||||||
* https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
|
* https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
|
||||||
* - M3D > Binary file format. Model 3D format:
|
* - M3D > Binary file format. Model 3D format:
|
||||||
|
|||||||
@ -119,7 +119,7 @@ int main(void)
|
|||||||
// without a -1, we would always draw a cube at the origin
|
// without a -1, we would always draw a cube at the origin
|
||||||
for (int i = 0; i < model.boneCount - 1; i++)
|
for (int i = 0; i < model.boneCount - 1; i++)
|
||||||
{
|
{
|
||||||
// By default the model is loaded in bind-pose by LoadModel().
|
// By default the model is loaded in bind-pose by LoadModel()
|
||||||
// But if UpdateModelAnimation() has been called at least once
|
// But if UpdateModelAnimation() has been called at least once
|
||||||
// then the model is already in animation pose, so we need the animated skeleton
|
// then the model is already in animation pose, so we need the animated skeleton
|
||||||
if (!animPlaying || !animsCount)
|
if (!animPlaying || !animsCount)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
const char* voxFileNames[] = {
|
const char *voxFileNames[] = {
|
||||||
"resources/models/vox/chr_knight.vox",
|
"resources/models/vox/chr_knight.vox",
|
||||||
"resources/models/vox/chr_sword.vox",
|
"resources/models/vox/chr_sword.vox",
|
||||||
"resources/models/vox/monu9.vox",
|
"resources/models/vox/monu9.vox",
|
||||||
@ -57,24 +57,23 @@ int main(void)
|
|||||||
camera.fovy = 45.0f; // Camera field-of-view Y
|
camera.fovy = 45.0f; // Camera field-of-view Y
|
||||||
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
// Load MagicaVoxel files
|
// Load MagicaVoxel files
|
||||||
Model models[MAX_VOX_FILES] = { 0 };
|
Model models[MAX_VOX_FILES] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_VOX_FILES; i++)
|
for (int i = 0; i < MAX_VOX_FILES; i++)
|
||||||
{
|
{
|
||||||
// Load VOX file and measure time
|
// Load VOX file and measure time
|
||||||
double t0 = GetTime() * 1000.0;
|
double t0 = GetTime()*1000.0;
|
||||||
models[i] = LoadModel(voxFileNames[i]);
|
models[i] = LoadModel(voxFileNames[i]);
|
||||||
double t1 = GetTime() * 1000.0;
|
double t1 = GetTime()*1000.0;
|
||||||
|
|
||||||
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
TraceLog(LOG_WARNING, TextFormat("[%s] File loaded in %.3f ms", voxFileNames[i], t1 - t0));
|
||||||
|
|
||||||
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
// Compute model translation matrix to center model on draw position (0, 0 , 0)
|
||||||
BoundingBox bb = GetModelBoundingBox(models[i]);
|
BoundingBox bb = GetModelBoundingBox(models[i]);
|
||||||
Vector3 center = { 0 };
|
Vector3 center = { 0 };
|
||||||
center.x = bb.min.x + (((bb.max.x - bb.min.x) / 2));
|
center.x = bb.min.x + (((bb.max.x - bb.min.x)/2));
|
||||||
center.z = bb.min.z + (((bb.max.z - bb.min.z) / 2));
|
center.z = bb.min.z + (((bb.max.z - bb.min.z)/2));
|
||||||
|
|
||||||
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
Matrix matTranslate = MatrixTranslate(-center.x, 0, -center.z);
|
||||||
models[i].transform = matTranslate;
|
models[i].transform = matTranslate;
|
||||||
@ -82,7 +81,6 @@ int main(void)
|
|||||||
|
|
||||||
int currentModel = 0;
|
int currentModel = 0;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
// Load voxel shader
|
// Load voxel shader
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/voxel_lighting.vs", GLSL_VERSION),
|
||||||
TextFormat("resources/shaders/glsl%i/voxel_lighting.fs", GLSL_VERSION));
|
TextFormat("resources/shaders/glsl%i/voxel_lighting.fs", GLSL_VERSION));
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [models] example - rlgl module usage with push/pop matrix transformations
|
* raylib [models] example - rlgl solar system
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -41,7 +41,7 @@ int main(void)
|
|||||||
const float moonRadius = 0.16f;
|
const float moonRadius = 0.16f;
|
||||||
const float moonOrbitRadius = 1.5f;
|
const float moonOrbitRadius = 1.5f;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - rlgl module usage with push/pop matrix transformations");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - rlgl solar system");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|||||||
27
examples/models/resources/shaders/glsl120/cubemap.fs
Normal file
27
examples/models/resources/shaders/glsl120/cubemap.fs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D equirectangularMap;
|
||||||
|
|
||||||
|
vec2 SampleSphericalMap(vec3 v)
|
||||||
|
{
|
||||||
|
vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
|
||||||
|
uv *= vec2(0.1591, 0.3183);
|
||||||
|
uv += 0.5;
|
||||||
|
return uv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Normalize local position
|
||||||
|
vec2 uv = SampleSphericalMap(normalize(fragPosition));
|
||||||
|
|
||||||
|
// Fetch color from texture map
|
||||||
|
vec3 color = texture2D(equirectangularMap, uv).rgb;
|
||||||
|
|
||||||
|
// Calculate final fragment color
|
||||||
|
gl_FragColor = vec4(color, 1.0);
|
||||||
|
}
|
||||||
20
examples/models/resources/shaders/glsl120/cubemap.vs
Normal file
20
examples/models/resources/shaders/glsl120/cubemap.vs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 matProjection;
|
||||||
|
uniform mat4 matView;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Calculate fragment position based on model transformations
|
||||||
|
fragPosition = vertexPosition;
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = matProjection*matView*vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
18
examples/models/resources/shaders/glsl120/skinning.fs
Normal file
18
examples/models/resources/shaders/glsl120/skinning.fs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Fetch color from texture sampler
|
||||||
|
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
||||||
|
|
||||||
|
// Calculate final fragment color
|
||||||
|
gl_FragColor = texelColor*colDiffuse*fragColor;
|
||||||
|
}
|
||||||
59
examples/models/resources/shaders/glsl120/skinning.vs
Normal file
59
examples/models/resources/shaders/glsl120/skinning.vs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
#define MAX_BONE_NUM 64
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
attribute vec4 vertexBoneIds;
|
||||||
|
attribute vec4 vertexBoneWeights;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 boneMatrices[MAX_BONE_NUM];
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
int boneIndex0 = int(vertexBoneIds.x);
|
||||||
|
int boneIndex1 = int(vertexBoneIds.y);
|
||||||
|
int boneIndex2 = int(vertexBoneIds.z);
|
||||||
|
int boneIndex3 = int(vertexBoneIds.w);
|
||||||
|
|
||||||
|
// WARNING: OpenGL ES 2.0 does not support automatic matrix transposing, neither transpose() function
|
||||||
|
mat4 boneMatrixTransposed0 = mat4(
|
||||||
|
vec4(boneMatrices[boneIndex0][0].x, boneMatrices[boneIndex0][1].x, boneMatrices[boneIndex0][2].x, boneMatrices[boneIndex0][3].x),
|
||||||
|
vec4(boneMatrices[boneIndex0][0].y, boneMatrices[boneIndex0][1].y, boneMatrices[boneIndex0][2].y, boneMatrices[boneIndex0][3].y),
|
||||||
|
vec4(boneMatrices[boneIndex0][0].z, boneMatrices[boneIndex0][1].z, boneMatrices[boneIndex0][2].z, boneMatrices[boneIndex0][3].z),
|
||||||
|
vec4(boneMatrices[boneIndex0][0].w, boneMatrices[boneIndex0][1].w, boneMatrices[boneIndex0][2].w, boneMatrices[boneIndex0][3].w));
|
||||||
|
mat4 boneMatrixTransposed1 = mat4(
|
||||||
|
vec4(boneMatrices[boneIndex1][0].x, boneMatrices[boneIndex1][1].x, boneMatrices[boneIndex1][2].x, boneMatrices[boneIndex1][3].x),
|
||||||
|
vec4(boneMatrices[boneIndex1][0].y, boneMatrices[boneIndex1][1].y, boneMatrices[boneIndex1][2].y, boneMatrices[boneIndex1][3].y),
|
||||||
|
vec4(boneMatrices[boneIndex1][0].z, boneMatrices[boneIndex1][1].z, boneMatrices[boneIndex1][2].z, boneMatrices[boneIndex1][3].z),
|
||||||
|
vec4(boneMatrices[boneIndex1][0].w, boneMatrices[boneIndex1][1].w, boneMatrices[boneIndex1][2].w, boneMatrices[boneIndex1][3].w));
|
||||||
|
mat4 boneMatrixTransposed2 = mat4(
|
||||||
|
vec4(boneMatrices[boneIndex2][0].x, boneMatrices[boneIndex2][1].x, boneMatrices[boneIndex2][2].x, boneMatrices[boneIndex2][3].x),
|
||||||
|
vec4(boneMatrices[boneIndex2][0].y, boneMatrices[boneIndex2][1].y, boneMatrices[boneIndex2][2].y, boneMatrices[boneIndex2][3].y),
|
||||||
|
vec4(boneMatrices[boneIndex2][0].z, boneMatrices[boneIndex2][1].z, boneMatrices[boneIndex2][2].z, boneMatrices[boneIndex2][3].z),
|
||||||
|
vec4(boneMatrices[boneIndex2][0].w, boneMatrices[boneIndex2][1].w, boneMatrices[boneIndex2][2].w, boneMatrices[boneIndex2][3].w));
|
||||||
|
mat4 boneMatrixTransposed3 = mat4(
|
||||||
|
vec4(boneMatrices[boneIndex3][0].x, boneMatrices[boneIndex3][1].x, boneMatrices[boneIndex3][2].x, boneMatrices[boneIndex3][3].x),
|
||||||
|
vec4(boneMatrices[boneIndex3][0].y, boneMatrices[boneIndex3][1].y, boneMatrices[boneIndex3][2].y, boneMatrices[boneIndex3][3].y),
|
||||||
|
vec4(boneMatrices[boneIndex3][0].z, boneMatrices[boneIndex3][1].z, boneMatrices[boneIndex3][2].z, boneMatrices[boneIndex3][3].z),
|
||||||
|
vec4(boneMatrices[boneIndex3][0].w, boneMatrices[boneIndex3][1].w, boneMatrices[boneIndex3][2].w, boneMatrices[boneIndex3][3].w));
|
||||||
|
|
||||||
|
vec4 skinnedPosition =
|
||||||
|
vertexBoneWeights.x*(boneMatrixTransposed0*vec4(vertexPosition, 1.0)) +
|
||||||
|
vertexBoneWeights.y*(boneMatrixTransposed1*vec4(vertexPosition, 1.0)) +
|
||||||
|
vertexBoneWeights.z*(boneMatrixTransposed2*vec4(vertexPosition, 1.0)) +
|
||||||
|
vertexBoneWeights.w*(boneMatrixTransposed3*vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
gl_Position = mvp*skinnedPosition;
|
||||||
|
}
|
||||||
29
examples/models/resources/shaders/glsl120/skybox.fs
Normal file
29
examples/models/resources/shaders/glsl120/skybox.fs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform samplerCube environmentMap;
|
||||||
|
uniform bool vflipped;
|
||||||
|
uniform bool doGamma;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Fetch color from texture map
|
||||||
|
vec4 texelColor = vec4(0.0);
|
||||||
|
|
||||||
|
if (vflipped) texelColor = textureCube(environmentMap, vec3(fragPosition.x, -fragPosition.y, fragPosition.z));
|
||||||
|
else texelColor = textureCube(environmentMap, fragPosition);
|
||||||
|
|
||||||
|
vec3 color = vec3(texelColor.x, texelColor.y, texelColor.z);
|
||||||
|
|
||||||
|
if (doGamma) // Apply gamma correction
|
||||||
|
{
|
||||||
|
color = color/(color + vec3(1.0));
|
||||||
|
color = pow(color, vec3(1.0/2.2));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate final fragment color
|
||||||
|
gl_FragColor = vec4(color, 1.0);
|
||||||
|
}
|
||||||
24
examples/models/resources/shaders/glsl120/skybox.vs
Normal file
24
examples/models/resources/shaders/glsl120/skybox.vs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 matProjection;
|
||||||
|
uniform mat4 matView;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Calculate fragment position based on model transformations
|
||||||
|
fragPosition = vertexPosition;
|
||||||
|
|
||||||
|
// Remove translation from the view matrix
|
||||||
|
mat4 rotView = mat4(mat3(matView));
|
||||||
|
vec4 clipPos = matProjection*rotView*vec4(vertexPosition, 1.0);
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = clipPos;
|
||||||
|
}
|
||||||
@ -221,10 +221,12 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// NoEase function, used when "no easing" is selected for any axis. It just ignores all parameters besides b.
|
// NoEase function, used when "no easing" is selected for any axis
|
||||||
|
// It just ignores all parameters besides b
|
||||||
static float NoEase(float t, float b, float c, float d)
|
static float NoEase(float t, float b, float c, float d)
|
||||||
{
|
{
|
||||||
float burn = t + b + c + d; // Hack to avoid compiler warning (about unused variables)
|
// Hack to avoid compiler warning (about unused variables)
|
||||||
|
float burn = t + b + c + d;
|
||||||
d += burn;
|
d += burn;
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
|
|||||||
@ -16,13 +16,13 @@
|
|||||||
********************************************************************************************
|
********************************************************************************************
|
||||||
*
|
*
|
||||||
* Mixes raylib and plain OpenGL code to draw a GL_POINTS based particle system. The
|
* Mixes raylib and plain OpenGL code to draw a GL_POINTS based particle system. The
|
||||||
* primary point is to demonstrate raylib and OpenGL interop.
|
* primary point is to demonstrate raylib and OpenGL interop
|
||||||
*
|
*
|
||||||
* rlgl batched draw operations internally so we have to flush the current batch before
|
* rlgl batched draw operations internally so we have to flush the current batch before
|
||||||
* doing our own OpenGL work (rlDrawRenderBatchActive()).
|
* doing our own OpenGL work (rlDrawRenderBatchActive())
|
||||||
*
|
*
|
||||||
* The example also demonstrates how to get the current model view projection matrix of
|
* The example also demonstrates how to get the current model view projection matrix of
|
||||||
* raylib. That way raylib cameras and so on work as expected.
|
* raylib. That way raylib cameras and so on work as expected
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
@ -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 - point particles");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - point particles");
|
||||||
|
|
||||||
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));
|
||||||
@ -87,13 +87,13 @@ int main(void)
|
|||||||
particles[i].x = (float)GetRandomValue(20, screenWidth - 20);
|
particles[i].x = (float)GetRandomValue(20, screenWidth - 20);
|
||||||
particles[i].y = (float)GetRandomValue(50, screenHeight - 20);
|
particles[i].y = (float)GetRandomValue(50, screenHeight - 20);
|
||||||
|
|
||||||
// Give each particle a slightly different period. But don't spread it to much.
|
// Give each particle a slightly different period. But don't spread it to much
|
||||||
// This way the particles line up every so often and you get a glimps of what is going on.
|
// This way the particles line up every so often and you get a glimps of what is going on
|
||||||
particles[i].period = (float)GetRandomValue(10, 30)/10.0f;
|
particles[i].period = (float)GetRandomValue(10, 30)/10.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a plain OpenGL vertex buffer with the data and an vertex array object
|
// Create a plain OpenGL vertex buffer with the data and an vertex array object
|
||||||
// that feeds the data from the buffer into the vertexPosition shader attribute.
|
// that feeds the data from the buffer into the vertexPosition shader attribute
|
||||||
GLuint vao = 0;
|
GLuint vao = 0;
|
||||||
GLuint vbo = 0;
|
GLuint vbo = 0;
|
||||||
glGenVertexArrays(1, &vao);
|
glGenVertexArrays(1, &vao);
|
||||||
|
|||||||
@ -23,11 +23,11 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
// IMPORTANT: This must match gol*.glsl GOL_WIDTH constant.
|
// IMPORTANT: This must match gol*.glsl GOL_WIDTH constant
|
||||||
// This must be a multiple of 16 (check golLogic compute dispatch).
|
// This must be a multiple of 16 (check golLogic compute dispatch)
|
||||||
#define GOL_WIDTH 768
|
#define GOL_WIDTH 768
|
||||||
|
|
||||||
// Maximum amount of queued draw commands (squares draw from mouse down events).
|
// Maximum amount of queued draw commands (squares draw from mouse down events)
|
||||||
#define MAX_BUFFERED_TRANSFERTS 48
|
#define MAX_BUFFERED_TRANSFERTS 48
|
||||||
|
|
||||||
// Game Of Life Update Command
|
// Game Of Life Update Command
|
||||||
@ -51,9 +51,12 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
InitWindow(GOL_WIDTH, GOL_WIDTH, "raylib [rlgl] example - compute shader - game of life");
|
const int screenWidth = GOL_WIDTH;
|
||||||
|
const int screenHeight = GOL_WIDTH;
|
||||||
|
|
||||||
const Vector2 resolution = { GOL_WIDTH, GOL_WIDTH };
|
InitWindow(screenWidth, screenHeight, "raylib [rlgl] example - compute shader - game of life");
|
||||||
|
|
||||||
|
const Vector2 resolution = { screenWidth, screenHeight };
|
||||||
unsigned int brushSize = 8;
|
unsigned int brushSize = 8;
|
||||||
|
|
||||||
// Game of Life logic compute shader
|
// Game of Life logic compute shader
|
||||||
@ -157,7 +160,7 @@ int main(void)
|
|||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
// Unload shader buffers objects.
|
// Unload shader buffers objects
|
||||||
rlUnloadShaderBuffer(ssboA);
|
rlUnloadShaderBuffer(ssboA);
|
||||||
rlUnloadShaderBuffer(ssboB);
|
rlUnloadShaderBuffer(ssboB);
|
||||||
rlUnloadShaderBuffer(ssboTransfert);
|
rlUnloadShaderBuffer(ssboTransfert);
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* Example originally created with raylib 1.6, last time updated with raylib 4.0
|
* Example originally created with raylib 1.6, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
* WARNING: This example is intended only for PLATFORM_DESKTOP and OpenGL 3.3 Core profile.
|
* WARNING: This example is intended only for PLATFORM_DESKTOP and OpenGL 3.3 Core profile
|
||||||
* It could work on other platforms if redesigned for those platforms (out-of-scope)
|
* It could work on other platforms if redesigned for those platforms (out-of-scope)
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
@ -48,7 +48,7 @@
|
|||||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||||
* as being the original software.
|
* as being the original software.
|
||||||
*
|
*
|
||||||
* 3. This notice may not be removed or altered from any source distribution.
|
* 3. This notice may not be removed or altered from any source distribution
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
|
|||||||
64
examples/shaders/resources/shaders/glsl100/normalmap.fs
Normal file
64
examples/shaders/resources/shaders/glsl100/normalmap.fs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform bool useNormalMap;
|
||||||
|
uniform float specularExponent;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texelColor = texture(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
vec3 viewDir = normalize(viewPos - fragPosition);
|
||||||
|
vec3 lightDir = normalize(lightPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 normal;
|
||||||
|
if (useNormalMap)
|
||||||
|
{
|
||||||
|
normal = texture(normalMap, vec2(fragTexCoord.x, fragTexCoord.y)).rgb;
|
||||||
|
|
||||||
|
//Transform normal values to the range -1.0 ... 1.0
|
||||||
|
normal = normalize(normal * 2.0 - 1.0);
|
||||||
|
|
||||||
|
//Transform the normal from tangent-space to world-space for lighting calculation
|
||||||
|
normal = normalize(normal * TBN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
normal = normalize(fragNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 tint = colDiffuse * fragColor;
|
||||||
|
|
||||||
|
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 lightDot = lightColor * NdotL;
|
||||||
|
|
||||||
|
float specCo = 0.0;
|
||||||
|
|
||||||
|
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewDir, reflect(-lightDir, normal))), specularExponent); // 16 refers to shine
|
||||||
|
|
||||||
|
specular += specCo;
|
||||||
|
|
||||||
|
finalColor = (texelColor * ((tint + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += texelColor * (vec4(1.0, 1.0, 1.0, 1.0) / 40.0) * tint;
|
||||||
|
|
||||||
|
// Gamma correction
|
||||||
|
gl_FragColor = pow(finalColor, vec4(1.0 / 2.2));
|
||||||
|
}
|
||||||
76
examples/shaders/resources/shaders/glsl100/normalmap.vs
Normal file
76
examples/shaders/resources/shaders/glsl100/normalmap.vs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#version 100
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexTangent;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-inverse
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
|
||||||
|
float b01 = a22 * a11 - a12 * a21;
|
||||||
|
float b11 = -a22 * a10 + a12 * a20;
|
||||||
|
float b21 = a21 * a10 - a11 * a20;
|
||||||
|
|
||||||
|
float det = a00 * b01 + a01 * b11 + a02 * b21;
|
||||||
|
|
||||||
|
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
|
||||||
|
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
|
||||||
|
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-transpose
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Compute binormal from vertex normal and tangent. W component is the tangent handedness
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
|
||||||
|
|
||||||
|
// Compute fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
|
||||||
|
// Compute fragment position based on model transformations
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
//Create TBN matrix for transforming the normal map values from tangent-space to world-space
|
||||||
|
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||||
|
|
||||||
|
vec3 fragTangent = normalize(normalMatrix * vertexTangent.xyz);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal) * fragNormal);
|
||||||
|
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix * vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
28
examples/shaders/resources/shaders/glsl120/depth.fs
Normal file
28
examples/shaders/resources/shaders/glsl120/depth.fs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D depthTexture;
|
||||||
|
uniform bool flipY;
|
||||||
|
|
||||||
|
float nearPlane = 0.1;
|
||||||
|
float farPlane = 100.0;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Handle potential Y-flipping
|
||||||
|
vec2 texCoord = fragTexCoord;
|
||||||
|
if (flipY)
|
||||||
|
texCoord.y = 1.0 - texCoord.y;
|
||||||
|
|
||||||
|
// Sample depth texture
|
||||||
|
float depth = texture2D(depthTexture, texCoord).r;
|
||||||
|
|
||||||
|
// Linearize depth
|
||||||
|
float linearDepth = (2.0*nearPlane)/(farPlane + nearPlane - depth*(farPlane - nearPlane));
|
||||||
|
|
||||||
|
// Output final color
|
||||||
|
gl_FragColor = vec4(vec3(linearDepth), 1.0);
|
||||||
|
}
|
||||||
62
examples/shaders/resources/shaders/glsl120/normalmap.fs
Normal file
62
examples/shaders/resources/shaders/glsl120/normalmap.fs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform bool useNormalMap;
|
||||||
|
uniform float specularExponent;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texelColor = texture(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
vec3 viewDir = normalize(viewPos - fragPosition);
|
||||||
|
vec3 lightDir = normalize(lightPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 normal;
|
||||||
|
if (useNormalMap)
|
||||||
|
{
|
||||||
|
normal = texture(normalMap, vec2(fragTexCoord.x, fragTexCoord.y)).rgb;
|
||||||
|
|
||||||
|
//Transform normal values to the range -1.0 ... 1.0
|
||||||
|
normal = normalize(normal * 2.0 - 1.0);
|
||||||
|
|
||||||
|
//Transform the normal from tangent-space to world-space for lighting calculation
|
||||||
|
normal = normalize(normal * TBN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
normal = normalize(fragNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 tint = colDiffuse * fragColor;
|
||||||
|
|
||||||
|
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 lightDot = lightColor * NdotL;
|
||||||
|
|
||||||
|
float specCo = 0.0;
|
||||||
|
|
||||||
|
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewDir, reflect(-lightDir, normal))), specularExponent); // 16 refers to shine
|
||||||
|
|
||||||
|
specular += specCo;
|
||||||
|
|
||||||
|
finalColor = (texelColor * ((tint + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += texelColor * (vec4(1.0, 1.0, 1.0, 1.0) / 40.0) * tint;
|
||||||
|
|
||||||
|
// Gamma correction
|
||||||
|
gl_FragColor = pow(finalColor, vec4(1.0 / 2.2));
|
||||||
|
}
|
||||||
76
examples/shaders/resources/shaders/glsl120/normalmap.vs
Normal file
76
examples/shaders/resources/shaders/glsl120/normalmap.vs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#version 120
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexTangent;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying mat3 TBN;
|
||||||
|
|
||||||
|
// NOTE: Add your custom variables here
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-inverse
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
|
||||||
|
float b01 = a22 * a11 - a12 * a21;
|
||||||
|
float b11 = -a22 * a10 + a12 * a20;
|
||||||
|
float b21 = a21 * a10 - a11 * a20;
|
||||||
|
|
||||||
|
float det = a00 * b01 + a01 * b11 + a02 * b21;
|
||||||
|
|
||||||
|
return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11),
|
||||||
|
b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10),
|
||||||
|
b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/glslify/glsl-transpose
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Compute binormal from vertex normal and tangent. W component is the tangent handedness
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
|
||||||
|
|
||||||
|
// Compute fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
|
||||||
|
// Compute fragment position based on model transformations
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
//Create TBN matrix for transforming the normal map values from tangent-space to world-space
|
||||||
|
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||||
|
|
||||||
|
vec3 fragTangent = normalize(normalMatrix * vertexTangent.xyz);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal) * fragNormal);
|
||||||
|
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix * vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
67
examples/shaders/resources/shaders/glsl330/normalmap.fs
Normal file
67
examples/shaders/resources/shaders/glsl330/normalmap.fs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input vertex attributes (from vertex shader)
|
||||||
|
in vec3 fragPosition;
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
in vec4 fragColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform sampler2D normalMap;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform vec4 tintColor;
|
||||||
|
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform bool useNormalMap;
|
||||||
|
uniform float specularExponent;
|
||||||
|
|
||||||
|
// Output fragment color
|
||||||
|
out vec4 finalColor;
|
||||||
|
|
||||||
|
in mat3 TBN;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texelColor = texture(texture0, vec2(fragTexCoord.x, fragTexCoord.y));
|
||||||
|
vec3 specular = vec3(0.0);
|
||||||
|
vec3 viewDir = normalize(viewPos - fragPosition);
|
||||||
|
vec3 lightDir = normalize(lightPos - fragPosition);
|
||||||
|
|
||||||
|
vec3 normal;
|
||||||
|
if (useNormalMap)
|
||||||
|
{
|
||||||
|
normal = texture(normalMap, vec2(fragTexCoord.x, fragTexCoord.y)).rgb;
|
||||||
|
|
||||||
|
//Transform normal values to the range -1.0 ... 1.0
|
||||||
|
normal = normalize(normal * 2.0 - 1.0);
|
||||||
|
|
||||||
|
//Transform the normal from tangent-space to world-space for lighting calculation
|
||||||
|
normal = normalize(normal * TBN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
normal = normalize(fragNormal);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 tint = colDiffuse * fragColor;
|
||||||
|
|
||||||
|
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
float NdotL = max(dot(normal, lightDir), 0.0);
|
||||||
|
vec3 lightDot = lightColor * NdotL;
|
||||||
|
|
||||||
|
float specCo = 0.0;
|
||||||
|
|
||||||
|
if (NdotL > 0.0) specCo = pow(max(0.0, dot(viewDir, reflect(-lightDir, normal))), specularExponent); // 16 refers to shine
|
||||||
|
|
||||||
|
specular += specCo;
|
||||||
|
|
||||||
|
finalColor = (texelColor * ((tint + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
|
||||||
|
finalColor += texelColor * (vec4(1.0, 1.0, 1.0, 1.0) / 40.0) * tint;
|
||||||
|
|
||||||
|
// Gamma correction
|
||||||
|
finalColor = pow(finalColor, vec4(1.0 / 2.2));
|
||||||
|
//finalColor = vec4(normal, 1.0);
|
||||||
|
}
|
||||||
48
examples/shaders/resources/shaders/glsl330/normalmap.vs
Normal file
48
examples/shaders/resources/shaders/glsl330/normalmap.vs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#version 330
|
||||||
|
|
||||||
|
// Input vertex attributes
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
in vec4 vertexTangent;
|
||||||
|
in vec4 vertexColor;
|
||||||
|
|
||||||
|
// Input uniform values
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
|
||||||
|
// Output vertex attributes (to fragment shader)
|
||||||
|
out vec3 fragPosition;
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec3 fragNormal; //used for when normal mapping is toggled off
|
||||||
|
out vec4 fragColor;
|
||||||
|
out mat3 TBN;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Compute binormal from vertex normal and tangent. W component is the tangent handedness
|
||||||
|
vec3 vertexBinormal = cross(vertexNormal, vertexTangent.xyz) * vertexTangent.w;
|
||||||
|
|
||||||
|
// Compute fragment normal based on normal transformations
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
|
||||||
|
// Compute fragment position based on model transformations
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
|
||||||
|
//Create TBN matrix for transforming the normal map values from tangent-space to world-space
|
||||||
|
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||||
|
|
||||||
|
vec3 fragTangent = normalize(normalMatrix * vertexTangent.xyz);
|
||||||
|
fragTangent = normalize(fragTangent - dot(fragTangent, fragNormal) * fragNormal);
|
||||||
|
|
||||||
|
vec3 fragBinormal = normalize(normalMatrix * vertexBinormal);
|
||||||
|
fragBinormal = cross(fragNormal, fragTangent);
|
||||||
|
|
||||||
|
TBN = transpose(mat3(fragTangent, fragBinormal, fragNormal));
|
||||||
|
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
BIN
examples/shaders/resources/tiles_diffuse.png
Normal file
BIN
examples/shaders/resources/tiles_diffuse.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 528 KiB |
BIN
examples/shaders/resources/tiles_normal.png
Normal file
BIN
examples/shaders/resources/tiles_normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 663 KiB |
@ -5,9 +5,9 @@
|
|||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 3.0, last time updated with raylib 4.2
|
* Example originally created with raylib 3.0, last time updated with raylib 4.2
|
||||||
*
|
*
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -99,44 +99,44 @@ int main(void)
|
|||||||
|
|
||||||
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
// NOTE: Vertex positions are stored in a texture for simplicity. A better approach would use a depth texture
|
||||||
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
// (instead of a detph renderbuffer) to reconstruct world positions in the final render shader via clip-space position,
|
||||||
// depth, and the inverse view/projection matrices.
|
// depth, and the inverse view/projection matrices
|
||||||
|
|
||||||
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios.
|
// 16-bit precision ensures OpenGL ES 3 compatibility, though it may lack precision for real scenarios
|
||||||
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
// But as mentioned above, the positions could be reconstructed instead of stored. If not targeting OpenGL ES
|
||||||
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`.
|
// and you wish to maintain this approach, consider using `RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32`
|
||||||
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
gBuffer.positionTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||||
|
|
||||||
// Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility.
|
// Similarly, 16-bit precision is used for normals ensures OpenGL ES 3 compatibility
|
||||||
// This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations.
|
// This is generally sufficient, but a 16-bit fixed-point format offer a better uniform precision in all orientations
|
||||||
gBuffer.normalTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
gBuffer.normalTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R16G16B16, 1);
|
||||||
|
|
||||||
// Albedo (diffuse color) and specular strength can be combined into one texture.
|
// Albedo (diffuse color) and specular strength can be combined into one texture
|
||||||
// The color in RGB, and the specular strength in the alpha channel.
|
// The color in RGB, and the specular strength in the alpha channel
|
||||||
gBuffer.albedoSpecTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
gBuffer.albedoSpecTexture = rlLoadTexture(NULL, screenWidth, screenHeight, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1);
|
||||||
|
|
||||||
// Activate the draw buffers for our framebuffer
|
// Activate the draw buffers for our framebuffer
|
||||||
rlActiveDrawBuffers(3);
|
rlActiveDrawBuffers(3);
|
||||||
|
|
||||||
// Now we attach our textures to the framebuffer.
|
// Now we attach our textures to the framebuffer
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.positionTexture, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.normalTexture, RL_ATTACHMENT_COLOR_CHANNEL1, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
|
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.albedoSpecTexture, RL_ATTACHMENT_COLOR_CHANNEL2, RL_ATTACHMENT_TEXTURE2D, 0);
|
||||||
|
|
||||||
// Finally we attach the depth buffer.
|
// Finally we attach the depth buffer
|
||||||
gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true);
|
gBuffer.depthRenderbuffer = rlLoadTextureDepth(screenWidth, screenHeight, true);
|
||||||
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
rlFramebufferAttach(gBuffer.framebuffer, gBuffer.depthRenderbuffer, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);
|
||||||
|
|
||||||
// Make sure our framebuffer is complete.
|
// Make sure our framebuffer is complete
|
||||||
// NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have
|
// NOTE: rlFramebufferComplete() automatically unbinds the framebuffer, so we don't have
|
||||||
// to rlDisableFramebuffer() here.
|
// to rlDisableFramebuffer() here
|
||||||
if (!rlFramebufferComplete(gBuffer.framebuffer))
|
if (!rlFramebufferComplete(gBuffer.framebuffer))
|
||||||
{
|
{
|
||||||
TraceLog(LOG_WARNING, "Framebuffer is not complete");
|
TraceLog(LOG_WARNING, "Framebuffer is not complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we initialize the sampler2D uniform's in the deferred shader.
|
// Now we initialize the sampler2D uniform's in the deferred shader
|
||||||
// We do this by setting the uniform's values to the texture units that
|
// We do this by setting the uniform's values to the texture units that
|
||||||
// we later bind our g-buffer textures to.
|
// we later bind our g-buffer textures to
|
||||||
rlEnableShader(deferredShader.id);
|
rlEnableShader(deferredShader.id);
|
||||||
int texUnitPosition = 0;
|
int texUnitPosition = 0;
|
||||||
int texUnitNormal = 1;
|
int texUnitNormal = 1;
|
||||||
@ -219,7 +219,7 @@ int main(void)
|
|||||||
rlDisableColorBlend();
|
rlDisableColorBlend();
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
// NOTE: We have to use rlEnableShader here. `BeginShaderMode` or thus `rlSetShader`
|
||||||
// will not work, as they won't immediately load the shader program.
|
// will not work, as they won't immediately load the shader program
|
||||||
rlEnableShader(gbufferShader.id);
|
rlEnableShader(gbufferShader.id);
|
||||||
// When drawing a model here, make sure that the material's shaders
|
// When drawing a model here, make sure that the material's shaders
|
||||||
// are set to the gbuffer shader!
|
// are set to the gbuffer shader!
|
||||||
@ -236,7 +236,7 @@ int main(void)
|
|||||||
EndMode3D();
|
EndMode3D();
|
||||||
rlEnableColorBlend();
|
rlEnableColorBlend();
|
||||||
|
|
||||||
// Go back to the default framebuffer (0) and draw our deferred shading.
|
// Go back to the default framebuffer (0) and draw our deferred shading
|
||||||
rlDisableFramebuffer();
|
rlDisableFramebuffer();
|
||||||
rlClearScreenBuffers(); // Clear color & depth buffer
|
rlClearScreenBuffers(); // Clear color & depth buffer
|
||||||
|
|
||||||
@ -264,10 +264,10 @@ int main(void)
|
|||||||
rlEnableColorBlend();
|
rlEnableColorBlend();
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
// As a last step, we now copy over the depth buffer from our g-buffer to the default framebuffer.
|
// As a last step, we now copy over the depth buffer from our g-buffer to the default framebuffer
|
||||||
rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebuffer);
|
rlBindFramebuffer(RL_READ_FRAMEBUFFER, gBuffer.framebuffer);
|
||||||
rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0);
|
rlBindFramebuffer(RL_DRAW_FRAMEBUFFER, 0);
|
||||||
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
rlBlitFramebuffer(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, 0x00000100); // GL_DEPTH_BUFFER_BIT
|
||||||
rlDisableFramebuffer();
|
rlDisableFramebuffer();
|
||||||
|
|
||||||
// Since our shader is now done and disabled, we can draw spheres
|
// Since our shader is now done and disabled, we can draw spheres
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Sieve of Eratosthenes
|
* raylib [shaders] example - sieve of Eratosthenes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve.
|
* NOTE: Sieve of Eratosthenes, the earliest known (ancient Greek) prime number sieve
|
||||||
*
|
*
|
||||||
* "Sift the twos and sift the threes,
|
* "Sift the twos and sift the threes,
|
||||||
* The Sieve of Eratosthenes.
|
* The Sieve of Eratosthenes.
|
||||||
@ -12,9 +12,9 @@
|
|||||||
* the numbers that are left are prime."
|
* the numbers that are left are prime."
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
@ -45,7 +45,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 - Sieve of Eratosthenes");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - sieve of Eratosthenes");
|
||||||
|
|
||||||
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 3.7
|
* Example originally created with raylib 2.5, last time updated with raylib 3.7
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Hot reloading
|
* raylib [shaders] example - hot reloading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330
|
* NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330
|
||||||
* is currently supported. OpenGL ES 2.0 platforms are not supported at the moment.
|
* is currently supported. OpenGL ES 2.0 platforms are not supported at the moment
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 3.0, last time updated with raylib 3.5
|
* Example originally created with raylib 3.0, last time updated with raylib 3.5
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Hybrid Rendering
|
* raylib [shaders] example - hybrid rendering
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -61,15 +61,15 @@ int main(void)
|
|||||||
// You are required to write depth for all shaders if one shader does it
|
// You are required to write depth for all shaders if one shader does it
|
||||||
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
|
Shader shdrRaster = LoadShader(0, TextFormat("resources/shaders/glsl%i/hybrid_raster.fs", GLSL_VERSION));
|
||||||
|
|
||||||
// Declare Struct used to store camera locs.
|
// Declare Struct used to store camera locs
|
||||||
RayLocs marchLocs = {0};
|
RayLocs marchLocs = {0};
|
||||||
|
|
||||||
// Fill the struct with shader locs.
|
// Fill the struct with shader locs
|
||||||
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
|
marchLocs.camPos = GetShaderLocation(shdrRaymarch, "camPos");
|
||||||
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
marchLocs.camDir = GetShaderLocation(shdrRaymarch, "camDir");
|
||||||
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
|
marchLocs.screenCenter = GetShaderLocation(shdrRaymarch, "screenCenter");
|
||||||
|
|
||||||
// Transfer screenCenter position to shader. Which is used to calculate ray direction.
|
// Transfer screenCenter position to shader. Which is used to calculate ray direction
|
||||||
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
|
Vector2 screenCenter = {.x = screenWidth/2.0f, .y = screenHeight/2.0f};
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
SetShaderValue(shdrRaymarch, marchLocs.screenCenter , &screenCenter , SHADER_UNIFORM_VEC2);
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ int main(void)
|
|||||||
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
.projection = CAMERA_PERSPECTIVE // Camera projection type
|
||||||
};
|
};
|
||||||
|
|
||||||
// Camera FOV is pre-calculated in the camera Distance.
|
// Camera FOV is pre-calculated in the camera distance
|
||||||
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
float camDist = 1.0f/(tanf(camera.fovy*0.5f*DEG2RAD));
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
@ -98,10 +98,10 @@ int main(void)
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
UpdateCamera(&camera, CAMERA_ORBITAL);
|
UpdateCamera(&camera, CAMERA_ORBITAL);
|
||||||
|
|
||||||
// Update Camera Postion in the ray march shader.
|
// Update Camera Postion in the ray march shader
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
SetShaderValue(shdrRaymarch, marchLocs.camPos, &(camera.position), RL_SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
// Update Camera Looking Vector. Vector length determines FOV.
|
// Update Camera Looking Vector. Vector length determines FOV
|
||||||
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
Vector3 camDir = Vector3Scale( Vector3Normalize( Vector3Subtract(camera.target, camera.position)) , camDist);
|
||||||
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
SetShaderValue(shdrRaymarch, marchLocs.camDir, &(camDir), RL_SHADER_UNIFORM_VEC3);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -113,7 +113,7 @@ int main(void)
|
|||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
|
|
||||||
// Raymarch Scene
|
// Raymarch Scene
|
||||||
rlEnableDepthTest(); //Manually enable Depth Test to handle multiple rendering methods.
|
rlEnableDepthTest(); // Manually enable Depth Test to handle multiple rendering methods
|
||||||
BeginShaderMode(shdrRaymarch);
|
BeginShaderMode(shdrRaymarch);
|
||||||
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
DrawRectangleRec((Rectangle){0,0, (float)screenWidth, (float)screenHeight},WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
* Example originally created with raylib 2.5, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
@ -109,7 +109,7 @@ int main(void)
|
|||||||
SetShaderValue(shader, cLoc, c, SHADER_UNIFORM_VEC2);
|
SetShaderValue(shader, cLoc, c, SHADER_UNIFORM_VEC2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If "R" is pressed, reset zoom and offset.
|
// If "R" is pressed, reset zoom and offset
|
||||||
if (IsKeyPressed(KEY_R))
|
if (IsKeyPressed(KEY_R))
|
||||||
{
|
{
|
||||||
zoom = startingZoom;
|
zoom = startingZoom;
|
||||||
@ -125,17 +125,16 @@ int main(void)
|
|||||||
if (IsKeyPressed(KEY_RIGHT)) incrementSpeed++;
|
if (IsKeyPressed(KEY_RIGHT)) incrementSpeed++;
|
||||||
else if (IsKeyPressed(KEY_LEFT)) incrementSpeed--;
|
else if (IsKeyPressed(KEY_LEFT)) incrementSpeed--;
|
||||||
|
|
||||||
// If either left or right button is pressed, zoom in/out.
|
// If either left or right button is pressed, zoom in/out
|
||||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) || IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
|
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) || IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
|
||||||
{
|
{
|
||||||
// Change zoom. If Mouse left -> zoom in. Mouse right -> zoom out.
|
// Change zoom. If Mouse left -> zoom in. Mouse right -> zoom out
|
||||||
zoom *= IsMouseButtonDown(MOUSE_BUTTON_LEFT)? zoomSpeed : 1.0f/zoomSpeed;
|
zoom *= IsMouseButtonDown(MOUSE_BUTTON_LEFT)? zoomSpeed : 1.0f/zoomSpeed;
|
||||||
|
|
||||||
const Vector2 mousePos = GetMousePosition();
|
const Vector2 mousePos = GetMousePosition();
|
||||||
Vector2 offsetVelocity;
|
Vector2 offsetVelocity;
|
||||||
// Find the velocity at which to change the camera. Take the distance of the mouse
|
// Find the velocity at which to change the camera. Take the distance of the mouse
|
||||||
// from the center of the screen as the direction, and adjust magnitude based on
|
// from the center of the screen as the direction, and adjust magnitude based on the current zoom
|
||||||
// the current zoom.
|
|
||||||
offsetVelocity.x = (mousePos.x/(float)screenWidth - 0.5f)*offsetSpeedMul/zoom;
|
offsetVelocity.x = (mousePos.x/(float)screenWidth - 0.5f)*offsetSpeedMul/zoom;
|
||||||
offsetVelocity.y = (mousePos.y/(float)screenHeight - 0.5f)*offsetSpeedMul/zoom;
|
offsetVelocity.y = (mousePos.y/(float)screenHeight - 0.5f)*offsetSpeedMul/zoom;
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3).
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
*
|
*
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Multiple sample2D with default batch system
|
* raylib [shaders] example - multi sample2D
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
@ -38,7 +38,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib - multiple sample2D");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - multi sample2D");
|
||||||
|
|
||||||
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
|
Image imRed = GenImageColor(800, 450, (Color){ 255, 0, 0, 255 });
|
||||||
Texture texRed = LoadTextureFromImage(imRed);
|
Texture texRed = LoadTextureFromImage(imRed);
|
||||||
|
|||||||
173
examples/shaders/shaders_normalmap.c
Normal file
173
examples/shaders/shaders_normalmap.c
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [shaders] example - normalmap
|
||||||
|
*
|
||||||
|
* Example complexity rating: [★★★★] 4/4
|
||||||
|
*
|
||||||
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
|
*
|
||||||
|
* Example originally created with raylib 5.6, last time updated with raylib 5.6
|
||||||
|
*
|
||||||
|
* Example contributed by Jeremy Montgomery (@Sir_Irk) 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 Jeremy Montgomery (@Sir_Irk) and Ramon Santamaria (@raysan5)
|
||||||
|
*k
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include <raylib.h>
|
||||||
|
|
||||||
|
#include <raymath.h>
|
||||||
|
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
#define GLSL_VERSION 330
|
||||||
|
#else // PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
|
#define GLSL_VERSION 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Program main entry point
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - normal map");
|
||||||
|
|
||||||
|
Camera camera = { 0 };
|
||||||
|
camera.position = (Vector3){ 0.0f, 2.0f, -4.0f };
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
camera.fovy = 45.0f;
|
||||||
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
// Load basic normal map lighting shader
|
||||||
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/normalmap.vs", GLSL_VERSION),
|
||||||
|
TextFormat("resources/shaders/glsl%i/normalmap.fs", GLSL_VERSION));
|
||||||
|
|
||||||
|
// Get some required shader locations
|
||||||
|
shader.locs[SHADER_LOC_MAP_NORMAL] = GetShaderLocation(shader, "normalMap");
|
||||||
|
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||||
|
|
||||||
|
// NOTE: "matModel" location name is automatically assigned on shader loading,
|
||||||
|
// no need to get the location again if using that uniform name
|
||||||
|
// shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
|
||||||
|
|
||||||
|
// This example uses just 1 point light
|
||||||
|
Vector3 lightPosition = { 0.0f, 1.0f, 0.0f };
|
||||||
|
int lightPosLoc = GetShaderLocation(shader, "lightPos");
|
||||||
|
|
||||||
|
// Load a plane model that has proper normals and tangents
|
||||||
|
Model plane = LoadModel("resources/models/plane.glb");
|
||||||
|
|
||||||
|
// Set the plane model's shader and texture maps
|
||||||
|
plane.materials[0].shader = shader;
|
||||||
|
plane.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = LoadTexture("resources/tiles_diffuse.png");
|
||||||
|
plane.materials[0].maps[MATERIAL_MAP_NORMAL].texture = LoadTexture("resources/tiles_normal.png");
|
||||||
|
|
||||||
|
// Generate Mipmaps and use TRILINEAR filtering to help with texture aliasing
|
||||||
|
GenTextureMipmaps(&plane.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture);
|
||||||
|
GenTextureMipmaps(&plane.materials[0].maps[MATERIAL_MAP_NORMAL].texture);
|
||||||
|
|
||||||
|
SetTextureFilter(plane.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture, TEXTURE_FILTER_TRILINEAR);
|
||||||
|
SetTextureFilter(plane.materials[0].maps[MATERIAL_MAP_NORMAL].texture, TEXTURE_FILTER_TRILINEAR);
|
||||||
|
|
||||||
|
// Specular exponent AKA shininess of the material
|
||||||
|
float specularExponent = 8.0f;
|
||||||
|
int specularExponentLoc = GetShaderLocation(shader, "specularExponent");
|
||||||
|
|
||||||
|
// Allow toggling the normal map on and off for comparison purposes
|
||||||
|
int useNormalMap = 1;
|
||||||
|
int useNormalMapLoc = GetShaderLocation(shader, "useNormalMap");
|
||||||
|
|
||||||
|
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
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Move the light around on the X and Z axis using WASD keys
|
||||||
|
Vector3 direction = { 0 };
|
||||||
|
if (IsKeyDown(KEY_W)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, 1.0f });
|
||||||
|
if (IsKeyDown(KEY_S)) direction = Vector3Add(direction, (Vector3){ 0.0f, 0.0f, -1.0f });
|
||||||
|
if (IsKeyDown(KEY_D)) direction = Vector3Add(direction, (Vector3){ -1.0f, 0.0f, 0.0f });
|
||||||
|
if (IsKeyDown(KEY_A)) direction = Vector3Add(direction, (Vector3){ 1.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
|
direction = Vector3Normalize(direction);
|
||||||
|
lightPosition = Vector3Add(lightPosition, Vector3Scale(direction, GetFrameTime()*3.0f));
|
||||||
|
|
||||||
|
// Increase/Decrease the specular exponent(shininess)
|
||||||
|
if (IsKeyDown(KEY_UP)) specularExponent = Clamp(specularExponent + 40.0f*GetFrameTime(), 2.0f, 128.0f);
|
||||||
|
if (IsKeyDown(KEY_DOWN)) specularExponent = Clamp(specularExponent - 40.0f*GetFrameTime(), 2.0f, 128.0f);
|
||||||
|
|
||||||
|
// Toggle normal map on and off
|
||||||
|
if (IsKeyPressed(KEY_N)) useNormalMap = !useNormalMap;
|
||||||
|
|
||||||
|
// Spin plane model at a constant rate
|
||||||
|
plane.transform = MatrixRotateY(GetTime()*0.5f);
|
||||||
|
|
||||||
|
// Update shader values
|
||||||
|
float lightPos[3] = {lightPosition.x, lightPosition.y, lightPosition.z};
|
||||||
|
SetShaderValue(shader, lightPosLoc, lightPos, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
|
float camPos[3] = {camera.position.x, camera.position.y, camera.position.z};
|
||||||
|
SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], camPos, SHADER_UNIFORM_VEC3);
|
||||||
|
|
||||||
|
SetShaderValue(shader, specularExponentLoc, &specularExponent, SHADER_UNIFORM_FLOAT);
|
||||||
|
|
||||||
|
SetShaderValue(shader, useNormalMapLoc, &useNormalMap, SHADER_UNIFORM_INT);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
BeginMode3D(camera);
|
||||||
|
|
||||||
|
BeginShaderMode(shader);
|
||||||
|
|
||||||
|
DrawModel(plane, Vector3Zero(), 2.0f, WHITE);
|
||||||
|
|
||||||
|
EndShaderMode();
|
||||||
|
|
||||||
|
// Draw sphere to show light position
|
||||||
|
DrawSphereWires(lightPosition, 0.2f, 8, 8, ORANGE);
|
||||||
|
|
||||||
|
EndMode3D();
|
||||||
|
|
||||||
|
Color textColor = (useNormalMap) ? DARKGREEN : RED;
|
||||||
|
const char *toggleStr = (useNormalMap) ? "On" : "Off";
|
||||||
|
DrawText(TextFormat("Use key [N] to toggle normal map: %s", toggleStr), 10, 10, 10, textColor);
|
||||||
|
|
||||||
|
int yOffset = 24;
|
||||||
|
DrawText("Use keys [W][A][S][D] to move the light", 10, 10 + yOffset*1, 10, BLACK);
|
||||||
|
DrawText("Use keys [Up][Down] to change specular exponent", 10, 10 + yOffset*2, 10, BLACK);
|
||||||
|
DrawText(TextFormat("Specular Exponent: %.2f", specularExponent), 10, 10 + yOffset*3, 10, BLUE);
|
||||||
|
|
||||||
|
DrawFPS(screenWidth - 80, 10);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader);
|
||||||
|
UnloadModel(plane);
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/shaders/shaders_normalmap.png
Normal file
BIN
examples/shaders/shaders_normalmap.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 373 KiB |
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330
|
* NOTE: This example requires raylib OpenGL 3.3 for shaders support and only #version 330
|
||||||
* is currently supported. OpenGL ES 2.0 platforms are not supported at the moment.
|
* is currently supported. OpenGL ES 2.0 platforms are not supported at the moment
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.0, last time updated with raylib 4.2
|
* Example originally created with raylib 2.0, last time updated with raylib 4.2
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Rounded Rectangle
|
* raylib [shaders] example - rounded rectangle
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@ -24,9 +24,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Declare custom Structs
|
// Structs definition
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Rounded rectangle data
|
// Rounded rectangle data
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector4 cornerRadius; // Individual corner radius (top-left, top-right, bottom-left, bottom-right)
|
Vector4 cornerRadius; // Individual corner radius (top-left, top-right, bottom-left, bottom-right)
|
||||||
@ -54,7 +53,6 @@ typedef struct {
|
|||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// Module Functions Declaration
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Create a rounded rectangle and set uniform locations
|
// Create a rounded rectangle and set uniform locations
|
||||||
static RoundedRectangle CreateRoundedRectangle(Vector4 cornerRadius, float shadowRadius, Vector2 shadowOffset, float shadowScale, float borderThickness, Shader shader);
|
static RoundedRectangle CreateRoundedRectangle(Vector4 cornerRadius, float shadowRadius, Vector2 shadowOffset, float shadowScale, float borderThickness, Shader shader);
|
||||||
|
|
||||||
@ -71,11 +69,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
const Color rectangleColor = BLUE;
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - rounded rectangle");
|
||||||
const Color shadowColor = DARKBLUE;
|
|
||||||
const Color borderColor = SKYBLUE;
|
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Rounded Rectangle");
|
|
||||||
|
|
||||||
// Load the shader
|
// Load the shader
|
||||||
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base.vs", GLSL_VERSION),
|
Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base.vs", GLSL_VERSION),
|
||||||
@ -94,6 +88,10 @@ int main(void)
|
|||||||
// Update shader uniforms
|
// Update shader uniforms
|
||||||
UpdateRoundedRectangle(roundedRectangle, shader);
|
UpdateRoundedRectangle(roundedRectangle, shader);
|
||||||
|
|
||||||
|
const Color rectangleColor = BLUE;
|
||||||
|
const Color shadowColor = DARKBLUE;
|
||||||
|
const Color borderColor = SKYBLUE;
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -124,8 +122,6 @@ int main(void)
|
|||||||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Draw rectangle shadow using shader
|
// Draw rectangle shadow using shader
|
||||||
rec = (Rectangle){ 50, 200, 110, 60 };
|
rec = (Rectangle){ 50, 200, 110, 60 };
|
||||||
DrawRectangleLines((int)rec.x - 20, (int)rec.y - 20, (int)rec.width + 40, (int)rec.height + 40, DARKGRAY);
|
DrawRectangleLines((int)rec.x - 20, (int)rec.y - 20, (int)rec.width + 40, (int)rec.height + 40, DARKGRAY);
|
||||||
@ -143,8 +139,6 @@ int main(void)
|
|||||||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Draw rectangle's border using shader
|
// Draw rectangle's border using shader
|
||||||
rec = (Rectangle){ 50, 330, 110, 60 };
|
rec = (Rectangle){ 50, 330, 110, 60 };
|
||||||
DrawRectangleLines((int)rec.x - 20, (int)rec.y - 20, (int)rec.width + 40, (int)rec.height + 40, DARKGRAY);
|
DrawRectangleLines((int)rec.x - 20, (int)rec.y - 20, (int)rec.width + 40, (int)rec.height + 40, DARKGRAY);
|
||||||
@ -162,8 +156,6 @@ int main(void)
|
|||||||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||||
EndShaderMode();
|
EndShaderMode();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Draw one more rectangle with all three colors
|
// Draw one more rectangle with all three colors
|
||||||
rec = (Rectangle){ 240, 80, 500, 300 };
|
rec = (Rectangle){ 240, 80, 500, 300 };
|
||||||
DrawRectangleLines((int)rec.x - 30, (int)rec.y - 30, (int)rec.width + 60, (int)rec.height + 60, DARKGRAY);
|
DrawRectangleLines((int)rec.x - 30, (int)rec.y - 30, (int)rec.width + 60, (int)rec.height + 60, DARKGRAY);
|
||||||
|
|||||||
@ -44,7 +44,7 @@ int main(void)
|
|||||||
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
// Shadows are a HUGE topic, and this example shows an extremely simple implementation of the shadowmapping algorithm,
|
// Shadows are a HUGE topic, and this example shows an extremely simple implementation of the shadowmapping algorithm,
|
||||||
// which is the industry standard for shadows. This algorithm can be extended in a ridiculous number of ways to improve
|
// which is the industry standard for shadows. This algorithm can be extended in a ridiculous number of ways to improve
|
||||||
// realism and also adapt it for different scenes. This is pretty much the simplest possible implementation.
|
// realism and also adapt it for different scenes. This is pretty much the simplest possible implementation
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shadowmap");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shadowmap");
|
||||||
|
|
||||||
Camera3D cam = (Camera3D){ 0 };
|
Camera3D cam = (Camera3D){ 0 };
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -20,13 +20,13 @@
|
|||||||
*
|
*
|
||||||
* The right hand side of the screen there is just enough light to see whats
|
* The right hand side of the screen there is just enough light to see whats
|
||||||
* going on without the spot light, great for a stealth type game where you
|
* going on without the spot light, great for a stealth type game where you
|
||||||
* have to avoid the spotlights.
|
* have to avoid the spotlights
|
||||||
*
|
*
|
||||||
* The left hand side of the screen is in pitch dark except for where the spotlights are.
|
* The left hand side of the screen is in pitch dark except for where the spotlights are
|
||||||
*
|
*
|
||||||
* Although this example doesn't scale like the letterbox example, you could integrate
|
* Although this example doesn't scale like the letterbox example, you could integrate
|
||||||
* the two techniques, but by scaling the actual colour of the render texture rather
|
* the two techniques, but by scaling the actual colour of the render texture rather
|
||||||
* than using alpha as a mask.
|
* than using alpha as a mask
|
||||||
*
|
*
|
||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tell the shader how wide the screen is so we can have
|
// Tell the shader how wide the screen is so we can have
|
||||||
// a pitch black half and a dimly lit half.
|
// a pitch black half and a dimly lit half
|
||||||
unsigned int wLoc = GetShaderLocation(shdrSpot, "screenWidth");
|
unsigned int wLoc = GetShaderLocation(shdrSpot, "screenWidth");
|
||||||
float sw = (float)GetScreenWidth();
|
float sw = (float)GetScreenWidth();
|
||||||
SetShaderValue(shdrSpot, wLoc, &sw, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(shdrSpot, wLoc, &sw, SHADER_UNIFORM_FLOAT);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Apply an shdrOutline to a texture
|
* raylib [shaders] example - texture outline
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.0, last time updated with raylib 4.0
|
* Example originally created with raylib 4.0, last time updated with raylib 4.0
|
||||||
*
|
*
|
||||||
@ -36,7 +36,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 - Apply an outline to a texture");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture outline");
|
||||||
|
|
||||||
Texture2D texture = LoadTexture("resources/fudesumi.png");
|
Texture2D texture = LoadTexture("resources/fudesumi.png");
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* Example demonstrates how to tile a texture on a 3D model using raylib.
|
* Example demonstrates how to tile a texture on a 3D model using raylib
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
* Example originally created with raylib 4.5, last time updated with raylib 4.5
|
||||||
*
|
*
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support,
|
||||||
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version.
|
* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version
|
||||||
*
|
*
|
||||||
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example
|
||||||
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shader] example - render depth texture
|
* raylib [shaders] example - render depth texture
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@ -36,7 +36,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shader] example - render depth texture");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - render depth texture");
|
||||||
|
|
||||||
// Init camera
|
// Init camera
|
||||||
Camera camera = { 0 };
|
Camera camera = { 0 };
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shaders] example - Depth buffer writing
|
* raylib [shaders] example - depth buffer writing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -22,12 +22,6 @@
|
|||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Macro Helpers
|
// Macro Helpers
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define SCREEN_WIDTH 800
|
|
||||||
#define SCREEN_HEIGHT 450
|
|
||||||
|
|
||||||
#define CENTER_X SCREEN_WIDTH * 0.5
|
|
||||||
#define CENTER_Y SCREEN_HEIGHT * 0.5 - 100
|
|
||||||
|
|
||||||
// Constant for Simulation
|
// Constant for Simulation
|
||||||
#define SIMULATION_STEPS 30
|
#define SIMULATION_STEPS 30
|
||||||
#define G 9.81
|
#define G 9.81
|
||||||
@ -45,32 +39,32 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||||
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [shapes] example - Double Pendulum");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - double pendulum");
|
||||||
|
|
||||||
// Simulation Paramters
|
// Simulation Paramters
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
float l1 = 15, m1 = 0.2, theta1 = DEG2RAD * 170, w1 = 0;
|
float l1 = 15, m1 = 0.2, theta1 = DEG2RAD * 170, w1 = 0;
|
||||||
float l2 = 15, m2 = 0.1, theta2 = DEG2RAD * 0, w2 = 0;
|
float l2 = 15, m2 = 0.1, theta2 = DEG2RAD * 0, w2 = 0;
|
||||||
float lengthScaler = 0.1;
|
float lengthScaler = 0.1;
|
||||||
float totalM = m1 + m2;
|
float totalM = m1 + m2;
|
||||||
|
|
||||||
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
Vector2 previousPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
||||||
previousPosition.x += CENTER_X;
|
previousPosition.x += (screenWidth/2);
|
||||||
previousPosition.y += CENTER_Y;
|
previousPosition.y += (screenHeight/2 - 100);
|
||||||
|
|
||||||
// Scale length
|
// Scale length
|
||||||
float L1 = l1 * lengthScaler;
|
float L1 = l1 * lengthScaler;
|
||||||
float L2 = l2 * lengthScaler;
|
float L2 = l2 * lengthScaler;
|
||||||
|
|
||||||
// Draw Parameters
|
// Draw parameters
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
int lineThick = 20, trailThick = 2;
|
int lineThick = 20, trailThick = 2;
|
||||||
float fateAlpha = 0.01;
|
float fateAlpha = 0.01;
|
||||||
|
|
||||||
// Create Framebuffer
|
// Create framebuffer
|
||||||
//--------------------------------------------------------------------------------------
|
RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
|
||||||
RenderTexture2D target = LoadRenderTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
||||||
SetTextureFilter(target.texture, TEXTURE_FILTER_BILINEAR);
|
SetTextureFilter(target.texture, TEXTURE_FILTER_BILINEAR);
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
@ -80,60 +74,56 @@ int main(void)
|
|||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
float step = dt / SIMULATION_STEPS, step2 = step * step;
|
float step = dt / SIMULATION_STEPS, step2 = step * step;
|
||||||
|
|
||||||
// Update Physics - larger steps = better approximation
|
// Update Physics - larger steps = better approximation
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
for (int i = 0; i < SIMULATION_STEPS; ++i)
|
for (int i = 0; i < SIMULATION_STEPS; ++i)
|
||||||
{
|
{
|
||||||
float delta = theta1 - theta2;
|
float delta = theta1 - theta2;
|
||||||
float sinD = sin(delta), cosD = cos(delta), cos2D = cos(2 * delta);
|
float sinD = sinf(delta), cosD = cosf(delta), cos2D = cosf(2*delta);
|
||||||
float ww1 = w1 * w1, ww2 = w2 * w2;
|
float ww1 = w1 * w1, ww2 = w2 * w2;
|
||||||
|
|
||||||
// Calculate a1
|
// Calculate a1
|
||||||
float a1 = (-G * (2 * m1 + m2) * sin(theta1)
|
float a1 = (-G*(2*m1 + m2)*sinf(theta1)
|
||||||
- m2 * G * sin(theta1 - 2 * theta2)
|
- m2*G*sinf(theta1 - 2*theta2)
|
||||||
- 2 * sinD * m2 * (ww2 * L2 + ww1 * L1 * cosD))
|
- 2*sinD*m2*(ww2*L2 + ww1*L1*cosD))
|
||||||
/ (L1 * (2 * m1 + m2 - m2 * cos2D));
|
/ (L1*(2*m1 + m2 - m2*cos2D));
|
||||||
|
|
||||||
// Calculate a2
|
// Calculate a2
|
||||||
float a2 = (2 * sinD * (ww1 * L1 * totalM
|
float a2 = (2*sinD*(ww1*L1*totalM
|
||||||
+ G * totalM * cos(theta1)
|
+ G*totalM*cosf(theta1)
|
||||||
+ ww2 * L2 * m2 * cosD))
|
+ ww2*L2*m2*cosD))
|
||||||
/ (L2 * (2 * m1 + m2 - m2 * cos2D));
|
/ (L2*(2*m1 + m2 - m2*cos2D));
|
||||||
|
|
||||||
// Update thetas
|
// Update thetas
|
||||||
theta1 += w1 * step + 0.5 * a1 * step2;
|
theta1 += w1*step + 0.5f*a1*step2;
|
||||||
theta2 += w2 * step + 0.5 * a2 * step2;
|
theta2 += w2*step + 0.5f*a2*step2;
|
||||||
|
|
||||||
// Update omegas
|
// Update omegas
|
||||||
w1 += a1 * step;
|
w1 += a1*step;
|
||||||
w2 += a2 * step;
|
w2 += a2*step;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Calculate position
|
// Calculate position
|
||||||
Vector2 currentPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
Vector2 currentPosition = CalculateDoublePendulumEndPoint(l1, theta1, l2, theta2);
|
||||||
currentPosition.x += CENTER_X;
|
currentPosition.x += screenWidth/2;
|
||||||
currentPosition.y += CENTER_Y;
|
currentPosition.y += screenHeight/2 - 100;
|
||||||
|
|
||||||
// Draw to framebuffer
|
// Draw to render texture
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
BeginTextureMode(target);
|
BeginTextureMode(target);
|
||||||
|
|
||||||
// Draw a transparent rectangle - smaller alpha = longer trails
|
// Draw a transparent rectangle - smaller alpha = longer trails
|
||||||
DrawRectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Fade(BLACK, fateAlpha));
|
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, fateAlpha));
|
||||||
|
|
||||||
// Draw trail
|
// Draw trail
|
||||||
DrawCircleV(previousPosition, trailThick, RED);
|
DrawCircleV(previousPosition, trailThick, RED);
|
||||||
DrawLineEx(previousPosition, currentPosition, trailThick * 2, RED);
|
DrawLineEx(previousPosition, currentPosition, trailThick * 2, RED);
|
||||||
|
|
||||||
EndTextureMode();
|
EndTextureMode();
|
||||||
//----------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// Update previous position
|
// Update previous position
|
||||||
previousPosition = currentPosition;
|
previousPosition = currentPosition;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -141,17 +131,16 @@ int main(void)
|
|||||||
|
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
// Draw Trails Texture
|
// Draw trails texture
|
||||||
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height },
|
DrawTextureRec(target.texture, (Rectangle){ 0, 0, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
|
||||||
(Vector2){ 0, 0 }, WHITE);
|
|
||||||
|
|
||||||
// Draw Double Pendulum
|
// Draw double pendulum
|
||||||
DrawRectanglePro((Rectangle){ CENTER_X, CENTER_Y, 10 * l1, lineThick },
|
DrawRectanglePro((Rectangle){ screenWidth/2, screenHeight/2 - 100, 10 * l1, lineThick },
|
||||||
(Vector2){0, lineThick * 0.5}, 90 - RAD2DEG * theta1, RAYWHITE);
|
(Vector2){0, lineThick * 0.5}, 90 - RAD2DEG * theta1, RAYWHITE);
|
||||||
|
|
||||||
Vector2 endpoint1 = CalculatePendulumEndPoint(l1, theta1);
|
Vector2 endpoint1 = CalculatePendulumEndPoint(l1, theta1);
|
||||||
DrawRectanglePro((Rectangle){ CENTER_X + endpoint1.x, CENTER_Y + endpoint1.y, 10 * l2, lineThick },
|
DrawRectanglePro((Rectangle){ screenWidth/2 + endpoint1.x, screenHeight/2 - 100 + endpoint1.y, 10 * l2, lineThick },
|
||||||
(Vector2){0, lineThick * 0.5}, 90 - RAD2DEG * theta2, RAYWHITE);
|
(Vector2){0, lineThick * 0.5}, 90 - RAD2DEG * theta2, RAYWHITE);
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
* NOTE: This example requires 'easings.h' library, provided on raylib/src. Just copy
|
* NOTE: This example requires 'easings.h' library, provided on raylib/src. Just copy
|
||||||
* the library to same directory as example or make sure it's available on include path.
|
* the library to same directory as example or make sure it's available on include path
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 2.0, last time updated with raylib 2.5
|
* Example originally created with raylib 2.0, last time updated with raylib 2.5
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Draw raylib logo using basic shapes
|
* raylib [shapes] example - draw raylib logo using basic shapes
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [shapes] example - Rectangle advanced
|
* raylib [shapes] example - advanced rectangle drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -265,10 +265,10 @@ static void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, fl
|
|||||||
rlSetTexture(0);
|
rlSetTexture(0);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Here we use the 'Diagram' to guide ourselves to which point receives what color.
|
// Here we use the 'Diagram' to guide ourselves to which point receives what color
|
||||||
// By choosing the color correctly associated with a pointe the gradient effect
|
// By choosing the color correctly associated with a pointe the gradient effect
|
||||||
// will naturally come from OpenGL interpolation.
|
// will naturally come from OpenGL interpolation
|
||||||
// But this time instead of Quad, we think in triangles.
|
// But this time instead of Quad, we think in triangles
|
||||||
|
|
||||||
rlBegin(RL_TRIANGLES);
|
rlBegin(RL_TRIANGLES);
|
||||||
// Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner
|
// Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Codepoints loading
|
* raylib [text] example - text codepoints loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@ -39,7 +39,7 @@ int main(void)
|
|||||||
InitWindow(screenWidth, screenHeight, "raylib [text] example - codepoints loading");
|
InitWindow(screenWidth, screenHeight, "raylib [text] example - codepoints loading");
|
||||||
|
|
||||||
// Convert each utf-8 character into its
|
// Convert each utf-8 character into its
|
||||||
// corresponding codepoint in the font file.
|
// corresponding codepoint in the font file
|
||||||
int codepointCount = 0;
|
int codepointCount = 0;
|
||||||
int *codepoints = LoadCodepoints(text, &codepointCount);
|
int *codepoints = LoadCodepoints(text, &codepointCount);
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Draw 3d
|
* raylib [text] example - drawing 3d text
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
* NOTE: Draw a 2D text in 3D space, each letter is drawn in a quad (or 2 quads if backface is set)
|
* NOTE: Draw a 2D text in 3D space, each letter is drawn in a quad (or 2 quads if backface is set)
|
||||||
* where the texture coodinates of each quad map to the texture coordinates of the glyphs
|
* where the texture coodinates of each quad map to the texture coordinates of the glyphs
|
||||||
* inside the font texture.
|
* inside the font texture
|
||||||
*
|
*
|
||||||
* A more efficient approach, i believe, would be to render the text in a render texture and
|
* A more efficient approach, i believe, would be to render the text in a render texture and
|
||||||
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
* map that texture to a plane and render that, or maybe a shader but my method allows more
|
||||||
* flexibility...for example to change position of each letter individually to make somethink
|
* flexibility...for example to change position of each letter individually to make somethink
|
||||||
* like a wavy text effect.
|
* like a wavy text effect
|
||||||
*
|
*
|
||||||
* Special thanks to:
|
* Special thanks to:
|
||||||
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
|
* @Nighten for the DrawTextStyle() code https://github.com/NightenDushi/Raylib_DrawTextStyle
|
||||||
@ -71,7 +71,7 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font
|
|||||||
// Draw a 2D text in 3D space and wave the parts that start with '~~' and end with '~~'
|
// Draw a 2D text in 3D space and wave the parts that start with '~~' and end with '~~'
|
||||||
// This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle
|
// This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle
|
||||||
static void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, WaveTextConfig *config, float time, Color tint);
|
static void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, WaveTextConfig *config, float time, Color tint);
|
||||||
// Measure a text in 3D ignoring the `~~` chars.
|
// Measure a text in 3D ignoring the `~~` chars
|
||||||
static Vector3 MeasureTextWave3D(Font font, const char *text, float fontSize, float fontSpacing, float lineSpacing);
|
static Vector3 MeasureTextWave3D(Font font, const char *text, float fontSize, float fontSpacing, float lineSpacing);
|
||||||
// Generates a nice color with a random hue
|
// Generates a nice color with a random hue
|
||||||
static Color GenerateRandomColor(float s, float v);
|
static Color GenerateRandomColor(float s, float v);
|
||||||
@ -562,7 +562,7 @@ static void DrawText3D(Font font, const char *text, Vector3 position, float font
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a 2D text in 3D space and wave the parts that start with `~~` and end with `~~`.
|
// Draw a 2D text in 3D space and wave the parts that start with `~~` and end with `~~`
|
||||||
// This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle
|
// This is a modified version of the original code by @Nighten found here https://github.com/NightenDushi/Raylib_DrawTextStyle
|
||||||
static void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, WaveTextConfig* config, float time, Color tint)
|
static void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSize, float fontSpacing, float lineSpacing, bool backface, WaveTextConfig* config, float time, Color tint)
|
||||||
{
|
{
|
||||||
@ -625,7 +625,7 @@ static void DrawTextWave3D(Font font, const char *text, Vector3 position, float
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Measure a text in 3D ignoring the `~~` chars.
|
// Measure a text in 3D ignoring the `~~` chars
|
||||||
static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
static Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, float fontSpacing, float lineSpacing)
|
||||||
{
|
{
|
||||||
int len = TextLength(text);
|
int len = TextLength(text);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Font filters
|
* raylib [text] example - font texture filters
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Font SDF loading
|
* raylib [text] example - font SDF loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Sprite font loading
|
* raylib [text] example - sprite font loading
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
@ -12,7 +12,7 @@
|
|||||||
* - Rectangles must be defined by a MAGENTA color background
|
* - Rectangles must be defined by a MAGENTA color background
|
||||||
*
|
*
|
||||||
* Following those constraints, a font can be provided just by an image,
|
* Following those constraints, a font can be provided just by an image,
|
||||||
* this is quite handy to avoid additional font descriptor files (like BMFonts use).
|
* this is quite handy to avoid additional font descriptor files (like BMFonts use)
|
||||||
*
|
*
|
||||||
* Example originally created with raylib 1.0, last time updated with raylib 1.0
|
* Example originally created with raylib 1.0, last time updated with raylib 1.0
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Text formatting
|
* raylib [text] example - text formating
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Input Box
|
* raylib [text] example - text input box
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@ -63,7 +63,7 @@ int main(void)
|
|||||||
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
|
if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS))
|
||||||
{
|
{
|
||||||
name[letterCount] = (char)key;
|
name[letterCount] = (char)key;
|
||||||
name[letterCount+1] = '\0'; // Add null terminator at the end of the string.
|
name[letterCount+1] = '\0'; // Add null terminator at the end of the string
|
||||||
letterCount++;
|
letterCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Rectangle bounds
|
* raylib [text] example - rectangle bounds
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -179,9 +179,9 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
|||||||
|
|
||||||
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
||||||
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
||||||
// and change states again and again recursively until the end of the text (or until we get outside of the container).
|
// and change states again and again recursively until the end of the text (or until we get outside of the container)
|
||||||
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
||||||
// and begin drawing on the next line before we can get outside the container.
|
// and begin drawing on the next line before we can get outside the container
|
||||||
if (state == MEASURE_STATE)
|
if (state == MEASURE_STATE)
|
||||||
{
|
{
|
||||||
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Unicode
|
* raylib [text] example - unicode text drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -378,9 +378,9 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec,
|
|||||||
|
|
||||||
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
||||||
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
||||||
// and change states again and again recursively until the end of the text (or until we get outside of the container).
|
// and change states again and again recursively until the end of the text (or until we get outside of the container)
|
||||||
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
||||||
// and begin drawing on the next line before we can get outside the container.
|
// and begin drawing on the next line before we can get outside the container
|
||||||
if (state == MEASURE_STATE)
|
if (state == MEASURE_STATE)
|
||||||
{
|
{
|
||||||
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [text] example - Text Writing Animation
|
* raylib [text] example - text writing animation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Background scrolling
|
* raylib [textures] example - background scrolling
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Bunnymark
|
* raylib [textures] example - bunnymark
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw part of the texture tiled
|
* raylib [textures] example - draw texture tiled
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
@ -22,7 +22,7 @@
|
|||||||
#define MARGIN_SIZE 8 // Size for the margins
|
#define MARGIN_SIZE 8 // Size for the margins
|
||||||
#define COLOR_SIZE 16 // Size of the color select buttons
|
#define COLOR_SIZE 16 // Size of the color select buttons
|
||||||
|
|
||||||
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest.
|
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest
|
||||||
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint);
|
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
@ -36,7 +36,7 @@ int main(void)
|
|||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE); // Make the window resizable
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - Draw part of a texture tiled");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - draw texture tiled");
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Texture texPattern = LoadTexture("resources/patterns.png");
|
Texture texPattern = LoadTexture("resources/patterns.png");
|
||||||
@ -173,7 +173,7 @@ int main(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest.
|
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest
|
||||||
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
|
void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
|
||||||
{
|
{
|
||||||
if ((texture.id <= 0) || (scale <= 0.0f)) return; // Wanna see a infinite loop?!...just delete this line!
|
if ((texture.id <= 0) || (scale <= 0.0f)) return; // Wanna see a infinite loop?!...just delete this line!
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Fog of war
|
* raylib [textures] example - fog of war
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Retrive image channel (mask)
|
* raylib [textures] example - extract image channel
|
||||||
*
|
*
|
||||||
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
||||||
*
|
*
|
||||||
@ -75,9 +75,9 @@ int main(void)
|
|||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Draw
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// TODO...
|
// Nothing to update...
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
@ -104,6 +104,7 @@ int main(void)
|
|||||||
UnloadTexture(textureGreen);
|
UnloadTexture(textureGreen);
|
||||||
UnloadTexture(textureBlue);
|
UnloadTexture(textureBlue);
|
||||||
UnloadTexture(textureAlpha);
|
UnloadTexture(textureAlpha);
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image loading and drawing on it
|
* raylib [textures] example - image loading and drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Procedural images generation
|
* raylib [textures] example - procedural images generation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image loading and texture creation
|
* raylib [textures] example - image kernel convolution
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★★] 4/4
|
* Example complexity rating: [★★★★] 4/4
|
||||||
*
|
*
|
||||||
@ -19,20 +19,14 @@
|
|||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module functions declaration
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void NormalizeKernel(float *kernel, int size);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
void NormalizeKernel(float *kernel, int size)
|
|
||||||
{
|
|
||||||
float sum = 0.0f;
|
|
||||||
for (int i = 0; i < size; i++) sum += kernel[i];
|
|
||||||
|
|
||||||
if (sum != 0.0f)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < size; i++) kernel[i] /= sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
@ -42,22 +36,25 @@ int main(void)
|
|||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image convolution");
|
||||||
|
|
||||||
Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
|
Image image = LoadImage("resources/cat.png"); // Loaded in CPU memory (RAM)
|
||||||
|
|
||||||
float gaussiankernel[] = {
|
float gaussiankernel[] = {
|
||||||
1.0f, 2.0f, 1.0f,
|
1.0f, 2.0f, 1.0f,
|
||||||
2.0f, 4.0f, 2.0f,
|
2.0f, 4.0f, 2.0f,
|
||||||
1.0f, 2.0f, 1.0f };
|
1.0f, 2.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
float sobelkernel[] = {
|
float sobelkernel[] = {
|
||||||
1.0f, 0.0f, -1.0f,
|
1.0f, 0.0f, -1.0f,
|
||||||
2.0f, 0.0f, -2.0f,
|
2.0f, 0.0f, -2.0f,
|
||||||
1.0f, 0.0f, -1.0f };
|
1.0f, 0.0f, -1.0f
|
||||||
|
};
|
||||||
|
|
||||||
float sharpenkernel[] = {
|
float sharpenkernel[] = {
|
||||||
0.0f, -1.0f, 0.0f,
|
0.0f, -1.0f, 0.0f,
|
||||||
-1.0f, 5.0f, -1.0f,
|
-1.0f, 5.0f, -1.0f,
|
||||||
0.0f, -1.0f, 0.0f };
|
0.0f, -1.0f, 0.0f
|
||||||
|
};
|
||||||
|
|
||||||
NormalizeKernel(gaussiankernel, 9);
|
NormalizeKernel(gaussiankernel, 9);
|
||||||
NormalizeKernel(sharpenkernel, 9);
|
NormalizeKernel(sharpenkernel, 9);
|
||||||
@ -132,3 +129,17 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// Module functions definition
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
static void NormalizeKernel(float *kernel, int size)
|
||||||
|
{
|
||||||
|
float sum = 0.0f;
|
||||||
|
for (int i = 0; i < size; i++) sum += kernel[i];
|
||||||
|
|
||||||
|
if (sum != 0.0f)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < size; i++) kernel[i] /= sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image loading and texture creation
|
* raylib [textures] example - image loading and texture creation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image Rotation
|
* raylib [textures] example - image rotation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
@ -27,7 +27,7 @@ int main(void)
|
|||||||
const int screenWidth = 800;
|
const int screenWidth = 800;
|
||||||
const int screenHeight = 450;
|
const int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture rotation");
|
InitWindow(screenWidth, screenHeight, "raylib [textures] example - image rotation");
|
||||||
|
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Image image45 = LoadImage("resources/raylib_logo.png");
|
Image image45 = LoadImage("resources/raylib_logo.png");
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Image text drawing using TTF generated font
|
* raylib [textures] example - image text drawing using TTF generated font
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Texture loading and drawing
|
* raylib [textures] example - texture loading and drawing
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Mouse painting
|
* raylib [textures] example - mouse painting
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -71,7 +71,7 @@ int main(void)
|
|||||||
// Activate one particle every frame and Update active particles
|
// Activate one particle every frame and Update active particles
|
||||||
// NOTE: Particles initial position should be mouse position when activated
|
// NOTE: Particles initial position should be mouse position when activated
|
||||||
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
|
// NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0)
|
||||||
// NOTE: When a particle disappears, active = false and it can be reused.
|
// NOTE: When a particle disappears, active = false and it can be reused
|
||||||
for (int i = 0; i < MAX_PARTICLES; i++)
|
for (int i = 0; i < MAX_PARTICLES; i++)
|
||||||
{
|
{
|
||||||
if (!mouseTail[i].active)
|
if (!mouseTail[i].active)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw Textured Polygon
|
* raylib [textures] example - draw textured polygon
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★☆☆☆] 1/4
|
* Example complexity rating: [★☆☆☆] 1/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Load textures from raw data
|
* raylib [textures] example - load textures from raw data
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Sprite animation
|
* raylib [textures] example - sprite animation
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★☆☆] 2/4
|
* Example complexity rating: [★★☆☆] 2/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Texture source and destination rectangles
|
* raylib [textures] example - texture source and destination rectangles
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*******************************************************************************************
|
/*******************************************************************************************
|
||||||
*
|
*
|
||||||
* raylib [textures] example - Draw a texture along a segmented curve
|
* raylib [textures] example - draw texture along segmented curve
|
||||||
*
|
*
|
||||||
* Example complexity rating: [★★★☆] 3/4
|
* Example complexity rating: [★★★☆] 3/4
|
||||||
*
|
*
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user