From 4ec4dc691f5a41ef85d8ee07295e897e368bc8c7 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 21 Dec 2018 00:17:44 +0100 Subject: Use stb_vorbis.h as header only --- examples/others/audio_standalone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/others/audio_standalone.c b/examples/others/audio_standalone.c index d6e75066..f08fbf82 100644 --- a/examples/others/audio_standalone.c +++ b/examples/others/audio_standalone.c @@ -6,7 +6,7 @@ * * DEPENDENCIES: * mini_al.h - Audio device management lib (http://kcat.strangesoft.net/openal.html) -* stb_vorbis.c - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) +* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) * jar_xm.h - XM module file loading * jar_mod.h - MOD audio file loading * dr_flac.h - FLAC audio file loading -- cgit v1.2.3 From 96207a8a026a629fcc3026efab96cf18e1302618 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 25 Dec 2018 15:17:42 +0100 Subject: REVIEWED: LoadFontEx() Changed parameters order for consistency with LoadFontData() and other functions when an array is passed by parameter and array size is the following parameter. --- examples/textures/textures_image_text.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/textures/textures_image_text.c b/examples/textures/textures_image_text.c index fb99e827..ce91fbf2 100644 --- a/examples/textures/textures_image_text.c +++ b/examples/textures/textures_image_text.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); // TTF Font loading with custom generation parameters - Font font = LoadFontEx("resources/KAISG.ttf", 64, 95, 0); + Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0); Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) -- cgit v1.2.3 From 35a6e9a07476c06e239b2cf1879bdb97fdc04b09 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 25 Dec 2018 15:18:35 +0100 Subject: Corrected issue with MOD playing Despite issue is corrected, now module loop doesn't work... --- examples/audio/audio_module_playing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/audio/audio_module_playing.c b/examples/audio/audio_module_playing.c index 671a119f..54bfa3d2 100644 --- a/examples/audio/audio_module_playing.c +++ b/examples/audio/audio_module_playing.c @@ -30,11 +30,11 @@ int main() int screenWidth = 800; int screenHeight = 450; - SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X + SetConfigFlags(FLAG_MSAA_4X_HINT); // NOTE: Try to enable MSAA 4X InitWindow(screenWidth, screenHeight, "raylib [audio] example - module playing (streaming)"); - InitAudioDevice(); // Initialize audio device + InitAudioDevice(); // Initialize audio device Color colors[14] = { ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE }; @@ -52,7 +52,7 @@ int main() circles[i].color = colors[GetRandomValue(0, 13)]; } - Music xm = LoadMusicStream("resources/mini1111.xm"); + Music xm = LoadMusicStream("resources/chiptun1.mod"); PlayMusicStream(xm); -- cgit v1.2.3 From 7b8965eb38adcbc325533acc831e3331c3efba9c Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 25 Dec 2018 15:19:25 +0100 Subject: Support float texture data on OpenGL ES 2.0 --- examples/models/models_skybox.c | 2 +- examples/models/resources/shaders/cubemap.fs | 4 ++-- examples/models/resources/shaders/cubemap.vs | 4 ++-- examples/models/resources/shaders/skybox.fs | 4 ++-- examples/models/resources/shaders/skybox.vs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index 6f6002b8..a6b233e3 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; + Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 4.0f, 1.0f, 4.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load skybox model Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); diff --git a/examples/models/resources/shaders/cubemap.fs b/examples/models/resources/shaders/cubemap.fs index 09ae62f5..e8e28536 100644 --- a/examples/models/resources/shaders/cubemap.fs +++ b/examples/models/resources/shaders/cubemap.fs @@ -9,7 +9,7 @@ #version 330 // Input vertex attributes (from vertex shader) -in vec3 fragPos; +in vec3 fragPosition; // Input uniform values uniform sampler2D equirectangularMap; @@ -28,7 +28,7 @@ vec2 SampleSphericalMap(vec3 v) void main() { // Normalize local position - vec2 uv = SampleSphericalMap(normalize(fragPos)); + vec2 uv = SampleSphericalMap(normalize(fragPosition)); // Fetch color from texture map vec3 color = texture(equirectangularMap, uv).rgb; diff --git a/examples/models/resources/shaders/cubemap.vs b/examples/models/resources/shaders/cubemap.vs index 6e0bf4e1..5721eaa2 100644 --- a/examples/models/resources/shaders/cubemap.vs +++ b/examples/models/resources/shaders/cubemap.vs @@ -16,12 +16,12 @@ uniform mat4 projection; uniform mat4 view; // Output vertex attributes (to fragment shader) -out vec3 fragPos; +out vec3 fragPosition; void main() { // Calculate fragment position based on model transformations - fragPos = vertexPosition; + fragPosition = vertexPosition; // Calculate final vertex position gl_Position = projection*view*vec4(vertexPosition, 1.0); diff --git a/examples/models/resources/shaders/skybox.fs b/examples/models/resources/shaders/skybox.fs index 0bd2f320..053a2517 100644 --- a/examples/models/resources/shaders/skybox.fs +++ b/examples/models/resources/shaders/skybox.fs @@ -9,7 +9,7 @@ #version 330 // Input vertex attributes (from vertex shader) -in vec3 fragPos; +in vec3 fragPosition; // Input uniform values uniform samplerCube environmentMap; @@ -20,7 +20,7 @@ out vec4 finalColor; void main() { // Fetch color from texture map - vec3 color = texture(environmentMap, fragPos).rgb; + vec3 color = texture(environmentMap, fragPosition).rgb; // Apply gamma correction color = color/(color + vec3(1.0)); diff --git a/examples/models/resources/shaders/skybox.vs b/examples/models/resources/shaders/skybox.vs index f40d615c..dcbe6c3d 100644 --- a/examples/models/resources/shaders/skybox.vs +++ b/examples/models/resources/shaders/skybox.vs @@ -16,12 +16,12 @@ uniform mat4 projection; uniform mat4 view; // Output vertex attributes (to fragment shader) -out vec3 fragPos; +out vec3 fragPosition; void main() { // Calculate fragment position based on model transformations - fragPos = vertexPosition; + fragPosition = vertexPosition; // Remove translation from the view matrix mat4 rotView = mat4(mat3(view)); -- cgit v1.2.3 From 01338b0a14f053d281970a32595bc531e8c70885 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Wed, 26 Dec 2018 13:26:34 +0100 Subject: WARNING: BREAKING CHANGE Added a bunch of useful text management functions. Consequently, some already available functions like `FormatText()` and `SubText()` has been renamed for consistency. Created temporal fallbacks for old names. raylib version bumped to 2.3. --- examples/shapes/shapes_logo_raylib_anim.c | 4 ++-- examples/text/text_writing_anim.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/shapes/shapes_logo_raylib_anim.c b/examples/shapes/shapes_logo_raylib_anim.c index c6d3796e..9be1d963 100644 --- a/examples/shapes/shapes_logo_raylib_anim.c +++ b/examples/shapes/shapes_logo_raylib_anim.c @@ -2,7 +2,7 @@ * * raylib [shapes] example - raylib logo animation * -* This example has been created using raylib 1.4 (www.raylib.com) +* This example has been created using raylib 2.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) @@ -140,7 +140,7 @@ int main() DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha)); - DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha)); + DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha)); } else if (state == 4) { diff --git a/examples/text/text_writing_anim.c b/examples/text/text_writing_anim.c index 5563b561..b2aba697 100644 --- a/examples/text/text_writing_anim.c +++ b/examples/text/text_writing_anim.c @@ -2,7 +2,7 @@ * * raylib [text] example - Text Writing Animation * -* This example has been created using raylib 1.4 (www.raylib.com) +* This example has been created using raylib 2.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2016 Ramon Santamaria (@raysan5) @@ -44,7 +44,7 @@ int main() ClearBackground(RAYWHITE); - DrawText(SubText(message, 0, framesCounter/10), 210, 160, 20, MAROON); + DrawText(TextSubtext(message, 0, framesCounter/10), 210, 160, 20, MAROON); DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY); DrawText("PRESS [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY); -- cgit v1.2.3 From 0619571149f1fde5500dec4b64a94541ef0981f2 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 29 Dec 2018 14:44:28 +0100 Subject: ADDED: DrawTextRec() and example --- examples/text/text_draw_inside_rectangle.c | 120 +++++++++++++++++++++++++++ examples/text/text_draw_inside_rectangle.png | Bin 0 -> 17844 bytes 2 files changed, 120 insertions(+) create mode 100644 examples/text/text_draw_inside_rectangle.c create mode 100644 examples/text/text_draw_inside_rectangle.png (limited to 'examples') diff --git a/examples/text/text_draw_inside_rectangle.c b/examples/text/text_draw_inside_rectangle.c new file mode 100644 index 00000000..e60fa5e5 --- /dev/null +++ b/examples/text/text_draw_inside_rectangle.c @@ -0,0 +1,120 @@ +/******************************************************************************************* +* +* raylib [text] example - Draw text inside a rectangle +* +* This example has been created using raylib 2.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2018 Vlad Adrian (@demizdor) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - draw text inside a rectangle"); + + char text[] = "Text cannot escape\tthis container\t...word wrap also works when active so here's\ + a long text for testing.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\ + tempor incididunt ut labore et dolore magna aliqua. Nec ullamcorper sit amet risus nullam eget felis eget."; + + bool resizing = false; + bool wordWrap = true; + + Rectangle container = { 25, 25, screenWidth - 50, screenHeight - 250}; + Rectangle resizer = { container.x + container.width - 17, container.y + container.height - 17, 14, 14 }; + + // Minimum width and heigh for the container rectangle + const int minWidth = 60; + const int minHeight = 60; + const int maxWidth = screenWidth - 50; + const int maxHeight = screenHeight - 160; + + Vector2 lastMouse = { 0, 0 }; // Stores last mouse coordinates + + Color borderColor = MAROON; // Container border color + + Font font = GetFontDefault(); // Get default system font + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_SPACE)) wordWrap = !wordWrap; + + Vector2 mouse = GetMousePosition(); + + // Check if the mouse is inside the container and toggle border color + if (CheckCollisionPointRec(mouse, container)) borderColor = Fade(MAROON, 0.4f); + else if (!resizing) borderColor = MAROON; + + // Container resizing logic + if (resizing) + { + if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) resizing = false; + + int width = container.width + (mouse.x - lastMouse.x); + container.width = (width > minWidth)? ((width < maxWidth)? width : maxWidth) : minWidth; + + int height = container.height + (mouse.y - lastMouse.y); + container.height = (height > minHeight)? ((height < maxHeight)? height : maxHeight) : minHeight; + } + else + { + // Check if we're resizing + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) && CheckCollisionPointRec(mouse, resizer)) resizing = true; + } + + // Move resizer rectangle properly + resizer.x = container.x + container.width - 17; + resizer.y = container.y + container.height - 17; + + lastMouse = mouse; // Update mouse + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawRectangleLinesEx(container, 3, borderColor); // Draw container border + + // Draw text in container (add some padding) + DrawTextRec(font, text, + (Rectangle){ container.x + 4, container.y + 4, container.width - 4, container.height - 4 }, + 20.0f, 2.0f, wordWrap, GRAY); + + DrawRectangleRec(resizer, borderColor); // Draw the resize box + + // Draw info + DrawText("Word Wrap: ", 313, screenHeight-115, 20, BLACK); + if (wordWrap) DrawText("ON", 447, screenHeight - 115, 20, RED); + else DrawText("OFF", 447, screenHeight - 115, 20, BLACK); + DrawText("Press [SPACE] to toggle word wrap", 218, screenHeight - 91, 20, GRAY); + + DrawRectangle(0, screenHeight - 54, screenWidth, 54, GRAY); + DrawText("Click hold & drag the to resize the container", 155, screenHeight - 38, 20, RAYWHITE); + DrawRectangleRec((Rectangle){ 382, screenHeight - 34, 12, 12 }, MAROON); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/examples/text/text_draw_inside_rectangle.png b/examples/text/text_draw_inside_rectangle.png new file mode 100644 index 00000000..f46b1096 Binary files /dev/null and b/examples/text/text_draw_inside_rectangle.png differ -- cgit v1.2.3 From d5735720b0cd8893320774e074694b48eb7b7d01 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Tue, 1 Jan 2019 20:53:30 +0100 Subject: Update Makefile for Emscripten --- examples/Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 53e8555d..976cfbc1 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -118,8 +118,8 @@ endif ifeq ($(PLATFORM),PLATFORM_WEB) # Emscripten required variables EMSDK_PATH = C:/emsdk - EMSCRIPTEN_VERSION = 1.38.20 - CLANG_VERSION = e1.38.20_64bit + EMSCRIPTEN_VERSION = 1.38.21 + CLANG_VERSION = e1.38.21_64bit PYTHON_VERSION = 2.7.13.1_64bit\python-2.7.13.amd64 NODE_VERSION = 8.9.1_64bit export PATH = $(EMSDK_PATH);$(EMSDK_PATH)\clang\$(CLANG_VERSION);$(EMSDK_PATH)\node\$(NODE_VERSION)\bin;$(EMSDK_PATH)\python\$(PYTHON_VERSION);$(EMSDK_PATH)\emscripten\$(EMSCRIPTEN_VERSION);C:\raylib\MinGW\bin:$$(PATH) @@ -130,23 +130,23 @@ endif # RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version. ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/win32/mingw32 + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif ifeq ($(PLATFORM_OS),LINUX) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/linux + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif ifeq ($(PLATFORM_OS),OSX) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/osx + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif ifeq ($(PLATFORM_OS),BSD) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/bsd + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif endif ifeq ($(PLATFORM),PLATFORM_RPI) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/rpi + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif ifeq ($(PLATFORM),PLATFORM_WEB) - RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/release/libs/html5 + RAYLIB_RELEASE_PATH = $(RAYLIB_PATH)/src endif # EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries @@ -249,7 +249,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter # --profiling # include information for code profiling # --preload-file resources # specify a resources folder for data compilation - CFLAGS += -Os -s USE_GLFW=3 -s USE_SDL=2 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 + CFLAGS += -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 # NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way, # we can compile same code for ALL platforms with no change required, but, working on bigger -- cgit v1.2.3 From 490e930665c7a2853f4a678aa397a7ed3551d8df Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 5 Jan 2019 17:25:35 +0100 Subject: Reviewed example --- examples/textures/textures_raw_data.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/textures/textures_raw_data.c b/examples/textures/textures_raw_data.c index b038792b..481bd66a 100644 --- a/examples/textures/textures_raw_data.c +++ b/examples/textures/textures_raw_data.c @@ -32,8 +32,8 @@ int main() UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data // Generate a checked texture by code (1024x1024 pixels) - int width = 1024; - int height = 1024; + int width = 960; + int height = 480; // Dynamic memory allocation to store pixels data (Color type) Color *pixels = (Color *)malloc(width*height*sizeof(Color)); @@ -42,8 +42,8 @@ int main() { for (int x = 0; x < width; x++) { - if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = ORANGE; - else pixels[y*height + x] = GOLD; + if (((x/32+y/32)/1)%2 == 0) pixels[y*width + x] = ORANGE; + else pixels[y*width + x] = GOLD; } } @@ -73,9 +73,9 @@ int main() DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f)); DrawTexture(fudesumi, 430, -30, WHITE); - DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN); - DrawText("GENERATED by CODE", 72, 164, 30, BROWN); - DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN); + DrawText("CHECKED TEXTURE ", 84, 85, 30, BROWN); + DrawText("GENERATED by CODE", 72, 148, 30, BROWN); + DrawText("and RAW IMAGE LOADING", 46, 210, 30, BROWN); DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN); -- cgit v1.2.3 From 5c614f69755623e346105d17c71697005bd2900c Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 5 Jan 2019 19:24:42 +0100 Subject: Some code tweaks --- examples/models/models_material_pbr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index a4a10d60..6885f753 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -156,7 +156,7 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE); mat.maps[MAP_IRRADIANCE].texture = GenTextureIrradiance(shdrIrradiance, cubemap, IRRADIANCE_SIZE); mat.maps[MAP_PREFILTER].texture = GenTexturePrefilter(shdrPrefilter, cubemap, PREFILTERED_SIZE); - mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, cubemap, BRDF_SIZE); + mat.maps[MAP_BRDF].texture = GenTextureBRDF(shdrBRDF, BRDF_SIZE); UnloadTexture(cubemap); UnloadTexture(texHDR); -- cgit v1.2.3 From f4fe7f4d4c6d25e4bcc1ea4b48af07ef49b82720 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 6 Jan 2019 15:49:29 +0100 Subject: Review BRDF texture generation Actually, that function should be redesigned... --- examples/models/resources/shaders/brdf.fs | 73 ++++++++++++++----------------- 1 file changed, 33 insertions(+), 40 deletions(-) (limited to 'examples') diff --git a/examples/models/resources/shaders/brdf.fs b/examples/models/resources/shaders/brdf.fs index 59ae384a..3e8777d2 100644 --- a/examples/models/resources/shaders/brdf.fs +++ b/examples/models/resources/shaders/brdf.fs @@ -1,12 +1,15 @@ /******************************************************************************************* * -* rPBR [shader] - Bidirectional reflectance distribution function fragment shader +* BRDF LUT Generation - Bidirectional reflectance distribution function fragment shader +* +* REF: https://github.com/HectorMF/BRDFGenerator * * Copyright (c) 2017 Victor Fisac * **********************************************************************************************/ #version 330 + #define MAX_SAMPLES 1024u // Input vertex attributes (from vertex shader) @@ -18,43 +21,30 @@ const float PI = 3.14159265359; // Output fragment color out vec4 finalColor; -float DistributionGGX(vec3 N, vec3 H, float roughness); -float RadicalInverse_VdC(uint bits); vec2 Hammersley(uint i, uint N); -vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness); +float RadicalInverseVdC(uint bits); float GeometrySchlickGGX(float NdotV, float roughness); float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness); +vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness); vec2 IntegrateBRDF(float NdotV, float roughness); -float DistributionGGX(vec3 N, vec3 H, float roughness) -{ - float a = roughness*roughness; - float a2 = a*a; - float NdotH = max(dot(N, H), 0.0); - float NdotH2 = NdotH*NdotH; - - float nom = a2; - float denom = (NdotH2*(a2 - 1.0) + 1.0); - denom = PI*denom*denom; - - return nom/denom; -} - -float RadicalInverse_VdC(uint bits) +float RadicalInverseVdC(uint bits) { - bits = (bits << 16u) | (bits >> 16u); - bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); - bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); - bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); - bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); - return float(bits) * 2.3283064365386963e-10; // / 0x100000000 + bits = (bits << 16u) | (bits >> 16u); + bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u); + bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u); + bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u); + bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u); + return float(bits) * 2.3283064365386963e-10; // / 0x100000000 } +// Compute Hammersley coordinates vec2 Hammersley(uint i, uint N) { - return vec2(float(i)/float(N), RadicalInverse_VdC(i)); + return vec2(float(i)/float(N), RadicalInverseVdC(i)); } +// Integrate number of importance samples for (roughness and NoV) vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness) { float a = roughness*roughness; @@ -85,6 +75,7 @@ float GeometrySchlickGGX(float NdotV, float roughness) return nom/denom; } +// Compute the geometry term for the BRDF given roughness squared, NoV, NoL float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) { float NdotV = max(dot(N, V), 0.0); @@ -97,29 +88,31 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness) vec2 IntegrateBRDF(float NdotV, float roughness) { - vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV); float A = 0.0; - float B = 0.0; + float B = 0.0; + vec3 V = vec3(sqrt(1.0 - NdotV*NdotV), 0.0, NdotV); vec3 N = vec3(0.0, 0.0, 1.0); - for(uint i = 0u; i < MAX_SAMPLES; i++) + for (int i = 0; i < MAX_SAMPLES; i++) { // Generate a sample vector that's biased towards the preferred alignment direction (importance sampling) - vec2 Xi = Hammersley(i, MAX_SAMPLES); - vec3 H = ImportanceSampleGGX(Xi, N, roughness); - vec3 L = normalize(2.0*dot(V, H)*H - V); - float NdotL = max(L.z, 0.0); - float NdotH = max(H.z, 0.0); - float VdotH = max(dot(V, H), 0.0); + + vec2 Xi = Hammersley(i, MAX_SAMPLES); // Compute a Hammersely coordinate + vec3 H = ImportanceSampleGGX(Xi, N, roughness); // Integrate number of importance samples for (roughness and NoV) + vec3 L = normalize(2.0*dot(V, H)*H - V); // Compute reflection vector L + + float NdotL = max(L.z, 0.0); // Compute normal dot light + float NdotH = max(H.z, 0.0); // Compute normal dot half + float VdotH = max(dot(V, H), 0.0); // Compute view dot half if (NdotL > 0.0) { - float G = GeometrySmith(N, V, L, roughness); - float G_Vis = (G*VdotH)/(NdotH*NdotV); - float Fc = pow(1.0 - VdotH, 5.0); + float G = GeometrySmith(N, V, L, roughness); // Compute the geometry term for the BRDF given roughness squared, NoV, NoL + float GVis = (G*VdotH)/(NdotH*NdotV); // Compute the visibility term given G, VoH, NoH, NoV, NoL + float Fc = pow(1.0 - VdotH, 5.0); // Compute the fresnel term given VoH - A += (1.0 - Fc)*G_Vis; - B += Fc*G_Vis; + A += (1.0 - Fc)*GVis; // Sum the result given fresnel, geometry, visibility + B += Fc*GVis; } } -- cgit v1.2.3 From adf0c6486480d601f7e20272ac43abe19233997d Mon Sep 17 00:00:00 2001 From: Marco Lizza Date: Wed, 9 Jan 2019 16:08:10 +0100 Subject: Fixing typo in examples makefile, preventing build. --- examples/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/Makefile b/examples/Makefile index 53e8555d..deeadb75 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -407,7 +407,7 @@ EXAMPLES = \ models/models_box_collisions \ models/models_billboard \ models/models_obj_loading \ - models/models_obj_viewing \ + models/models_obj_viewer \ models/models_heightmap \ models/models_cubicmap \ models/models_mesh_picking \ -- cgit v1.2.3 From 0fe56b1674c99aa75c0dd6f45d77cbff80cf218c Mon Sep 17 00:00:00 2001 From: Marco Lizza Date: Wed, 9 Jan 2019 16:20:56 +0100 Subject: Adding basic palette-switching example using uniform arrays. --- examples/CMakeLists.txt | 1 + examples/Makefile | 1 + .../resources/shaders/glsl100/palette-switch.fs | 29 ++++ .../resources/shaders/glsl120/palette-switch.fs | 27 ++++ .../resources/shaders/glsl330/palette-switch.fs | 30 ++++ examples/shaders/shaders_palette_switch.c | 160 +++++++++++++++++++++ 6 files changed, 248 insertions(+) create mode 100644 examples/shaders/resources/shaders/glsl100/palette-switch.fs create mode 100644 examples/shaders/resources/shaders/glsl120/palette-switch.fs create mode 100644 examples/shaders/resources/shaders/glsl330/palette-switch.fs create mode 100644 examples/shaders/shaders_palette_switch.c (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1c0c935c..1d4fdd79 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -52,6 +52,7 @@ if(${PLATFORM} MATCHES "Android") list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_model_shader.c) list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_postprocessing.c) list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_raymarching.c) + list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_palette_switch.c) elseif(${PLATFORM} MATCHES "Web") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1") diff --git a/examples/Makefile b/examples/Makefile index deeadb75..b652482f 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -420,6 +420,7 @@ EXAMPLES = \ shaders/shaders_custom_uniform \ shaders/shaders_postprocessing \ shaders/shaders_raymarching \ + shaders/shaders_palette_switch \ audio/audio_sound_loading \ audio/audio_music_stream \ audio/audio_module_playing \ diff --git a/examples/shaders/resources/shaders/glsl100/palette-switch.fs b/examples/shaders/resources/shaders/glsl100/palette-switch.fs new file mode 100644 index 00000000..65a7bd29 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/palette-switch.fs @@ -0,0 +1,29 @@ +#version 100 + +precision mediump float; + +const int colors = 8; + +// Input vertex attributes (from vertex shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform ivec3 palette[colors]; + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord) * fragColor; + + // Convert the (normalized) texel color RED component (GB would work, too) + // to the palette index by scaling up from [0, 1] to [0, 255]. + int index = int(texelColor.r * 255.0); + ivec3 color = palette[index]; + + // Calculate final fragment color. Note that the palette color components + // are defined in the range [0, 255] and need to be normalized to [0, 1] + // for OpenGL to work. + gl_FragColor = vec4(color / 255.0, texelColor.a); +} diff --git a/examples/shaders/resources/shaders/glsl120/palette-switch.fs b/examples/shaders/resources/shaders/glsl120/palette-switch.fs new file mode 100644 index 00000000..b4384502 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/palette-switch.fs @@ -0,0 +1,27 @@ +#version 120 + +const int colors = 8; + +// Input fragment attributes (from fragment shader) +varying vec2 fragTexCoord; +varying vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform ivec3 palette[colors]; + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord) * fragColor; + + // Convert the (normalized) texel color RED component (GB would work, too) + // to the palette index by scaling up from [0, 1] to [0, 255]. + int index = int(texelColor.r * 255.0); + ivec3 color = palette[index]; + + // Calculate final fragment color. Note that the palette color components + // are defined in the range [0, 255] and need to be normalized to [0, 1] + // for OpenGL to work. + gl_FragColor = vec4(color / 255.0, texelColor.a); +} diff --git a/examples/shaders/resources/shaders/glsl330/palette-switch.fs b/examples/shaders/resources/shaders/glsl330/palette-switch.fs new file mode 100644 index 00000000..178c42c5 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/palette-switch.fs @@ -0,0 +1,30 @@ +#version 330 + +const int colors = 8; + +// Input fragment attributes (from fragment shader) +in vec2 fragTexCoord; +in vec4 fragColor; + +// Input uniform values +uniform sampler2D texture0; +uniform ivec3 palette[colors]; + +// Output fragment color +out vec4 finalColor; + +void main() +{ + // Texel color fetching from texture sampler + vec4 texelColor = texture(texture0, fragTexCoord) * fragColor; + + // Convert the (normalized) texel color RED component (GB would work, too) + // to the palette index by scaling up from [0, 1] to [0, 255]. + int index = int(texelColor.r * 255.0); + ivec3 color = palette[index]; + + // Calculate final fragment color. Note that the palette color components + // are defined in the range [0, 255] and need to be normalized to [0, 1] + // for OpenGL to work. + finalColor = vec4(color / 255.0, texelColor.a); +} diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c new file mode 100644 index 00000000..03151b66 --- /dev/null +++ b/examples/shaders/shaders_palette_switch.c @@ -0,0 +1,160 @@ +/******************************************************************************************* +* +* raylib [shaders] example - Apply a postprocessing shader to a scene +* +* 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. +* +* 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 +* raylib comes with shaders ready for both versions, check raylib/shaders install folder +* +* This example has been created using raylib 2.x (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_DESKTOP) + #define GLSL_VERSION 330 +#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB + #define GLSL_VERSION 100 +#endif + +#define MAX_PALETTES 3 +#define COLORS_PER_PALETTE 8 +#define VALUES_PER_COLOR 3 + +static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE * VALUES_PER_COLOR] = { + { + 0, 0, 0, + 255, 0, 0, + 0, 255, 0, + 0, 0, 255, + 0, 255, 255, + 255, 0, 255, + 255, 255, 0, + 255, 255, 255, + }, + { + 4, 12, 6, + 17, 35, 24, + 30, 58, 41, + 48, 93, 66, + 77, 128, 97, + 137, 162, 87, + 190, 220, 127, + 238, 255, 204, + }, + { + 21, 25, 26, + 138, 76, 88, + 217, 98, 117, + 230, 184, 193, + 69, 107, 115, + 75, 151, 166, + 165, 189, 194, + 255, 245, 247, + } +}; + +static const char *paletteText[] = { + "3-BIT RGB", + "AMMO-8 (GameBoy-like)", + "RKBV (2-strip film)" +}; + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - palette-switch shader"); + + // Load shader to be used on some parts drawing + // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version + // NOTE 2: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader + Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/palette-switch.fs", GLSL_VERSION)); + + // Get variable (uniform) location on the shader to connect with the program + // NOTE: If uniform variable could not be found in the shader, function returns -1 + int paletteLoc = GetShaderLocation(shader, "palette"); + + // Initial index not set, will be automatically bounded below. + int currentPalette = -1; + + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + int paletteIndex = currentPalette; + if (IsKeyPressed(KEY_RIGHT)) paletteIndex++; + else if (IsKeyPressed(KEY_LEFT)) paletteIndex--; + + if (paletteIndex >= MAX_PALETTES) paletteIndex = 0; + else if (paletteIndex < 0) paletteIndex = MAX_PALETTES - 1; + + // Send new value to the shader to be used on drawing. + // Note that we are sending RGB triplets w/o the alpha channel *only* if the current + // palette index has changed (in order to save performances). + if (currentPalette != paletteIndex) { + currentPalette = paletteIndex; + SetShaderValueArrayi(shader, paletteLoc, palettes[currentPalette], VALUES_PER_COLOR, COLORS_PER_PALETTE); + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + BeginShaderMode(shader); + + // Draw horizontal screen-wide rectangles with increasing "palette index". + // The used palette index is encoded in the RGB components of the pixel. + int linesPerRectangle = screenHeight / COLORS_PER_PALETTE; + int leftover = screenHeight % COLORS_PER_PALETTE; + int y = 0; + + for (int i = 0; i < COLORS_PER_PALETTE; ++i) { + int height = linesPerRectangle; + if (leftover > 0) { + height += 1; + leftover -= 1; + } + + DrawRectangle(0, y, screenWidth, height, CLITERAL{ i, i, i, 255 }); + + y += height; + } + + EndShaderMode(); + + DrawText("CURRENT PALETTE:", 10, 15, 20, RAYWHITE); + DrawText(paletteText[currentPalette], 240, 15, 20, RED); + DrawText("< >", 540, 10, 30, DARKBLUE); + + DrawFPS(700, 15); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadShader(shader); // Unload shader + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} -- cgit v1.2.3 From 0c5bee4c9addc20b8b3c443820764854c63f76d7 Mon Sep 17 00:00:00 2001 From: Marco Lizza Date: Wed, 9 Jan 2019 16:33:09 +0100 Subject: Limiting FPS to 60 for uniformity with other examples. --- examples/shaders/shaders_palette_switch.c | 1 + 1 file changed, 1 insertion(+) (limited to 'examples') diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c index 03151b66..ad09ca73 100644 --- a/examples/shaders/shaders_palette_switch.c +++ b/examples/shaders/shaders_palette_switch.c @@ -88,6 +88,7 @@ int main() // Initial index not set, will be automatically bounded below. int currentPalette = -1; + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop -- cgit v1.2.3 From 55f8dbc755c2e31d2112e71439fef0d31e8090a6 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 10 Jan 2019 11:25:26 +0100 Subject: WARNING: Redesigned SetShaderValue() --- examples/models/models_material_pbr.c | 20 ++++++++--------- examples/models/models_skybox.c | 4 ++-- examples/models/rlights.h | 10 ++++----- examples/others/standard_lighting.c | 25 ++++++++++------------ .../resources/shaders/glsl330/palette-switch.fs | 2 +- examples/shaders/shaders_custom_uniform.c | 2 +- examples/shaders/shaders_palette_switch.c | 24 ++++++++++++--------- examples/shaders/shaders_raymarching.c | 12 +++++------ 8 files changed, 50 insertions(+), 49 deletions(-) (limited to 'examples') diff --git a/examples/models/models_material_pbr.c b/examples/models/models_material_pbr.c index 6885f753..f93c7a68 100644 --- a/examples/models/models_material_pbr.c +++ b/examples/models/models_material_pbr.c @@ -64,7 +64,7 @@ int main() // Send to material PBR shader camera view position float cameraPos[3] = { camera.position.x, camera.position.y, camera.position.z }; - SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, 3); + SetShaderValue(model.material.shader, model.material.shader.locs[LOC_VECTOR_VIEW], cameraPos, UNIFORM_VEC3); //---------------------------------------------------------------------------------- // Draw @@ -148,9 +148,9 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) Shader shdrBRDF = LoadShader(PATH_BRDF_VS, PATH_BRDF_FS); // Setup required shader locations - SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1); - SetShaderValuei(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, 1); - SetShaderValuei(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, 1); + SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); + SetShaderValue(shdrIrradiance, GetShaderLocation(shdrIrradiance, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT); + SetShaderValue(shdrPrefilter, GetShaderLocation(shdrPrefilter, "environmentMap"), (int[1]){ 0 }, UNIFORM_INT); Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); Texture2D cubemap = GenTextureCubemap(shdrCubemap, texHDR, CUBEMAP_SIZE); @@ -174,14 +174,14 @@ static Material LoadMaterialPBR(Color albedo, float metalness, float roughness) SetTextureFilter(mat.maps[MAP_OCCLUSION].texture, FILTER_BILINEAR); // Enable sample usage in shader for assigned textures - SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, 1); - SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, 1); - SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, 1); - SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, 1); - SetShaderValuei(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, 1); + SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "albedo.useSampler"), (int[1]){ 1 }, UNIFORM_INT); + SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "normals.useSampler"), (int[1]){ 1 }, UNIFORM_INT); + SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "metalness.useSampler"), (int[1]){ 1 }, UNIFORM_INT); + SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "roughness.useSampler"), (int[1]){ 1 }, UNIFORM_INT); + SetShaderValue(mat.shader, GetShaderLocation(mat.shader, "occlusion.useSampler"), (int[1]){ 1 }, UNIFORM_INT); int renderModeLoc = GetShaderLocation(mat.shader, "renderMode"); - SetShaderValuei(mat.shader, renderModeLoc, (int[1]){ 0 }, 1); + SetShaderValue(mat.shader, renderModeLoc, (int[1]){ 0 }, UNIFORM_INT); // Set up material properties color mat.maps[MAP_ALBEDO].color = albedo; diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c index a6b233e3..c7f76ecf 100644 --- a/examples/models/models_skybox.c +++ b/examples/models/models_skybox.c @@ -30,11 +30,11 @@ int main() // Load skybox shader and set required locations // NOTE: Some locations are automatically set at shader loading skybox.material.shader = LoadShader("resources/shaders/skybox.vs", "resources/shaders/skybox.fs"); - SetShaderValuei(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, 1); + SetShaderValue(skybox.material.shader, GetShaderLocation(skybox.material.shader, "environmentMap"), (int[1]){ MAP_CUBEMAP }, UNIFORM_INT); // Load cubemap shader and setup required shader locations Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs"); - SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1); + SetShaderValue(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, UNIFORM_INT); // Load HDR panorama (sphere) texture Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); diff --git a/examples/models/rlights.h b/examples/models/rlights.h index 0da3e2cb..19504473 100644 --- a/examples/models/rlights.h +++ b/examples/models/rlights.h @@ -158,20 +158,20 @@ Light CreateLight(int type, Vector3 pos, Vector3 targ, Color color, Shader shade void UpdateLightValues(Shader shader, Light light) { // Send to shader light enabled state and type - SetShaderValuei(shader, light.enabledLoc, (int[1]){ light.enabled }, 1); - SetShaderValuei(shader, light.typeLoc, (int[1]){ light.type }, 1); + SetShaderValue(shader, light.enabledLoc, &light.enabled, UNIFORM_INT); + SetShaderValue(shader, light.typeLoc, &light.type, UNIFORM_INT); // Send to shader light position values float position[3] = { light.position.x, light.position.y, light.position.z }; - SetShaderValue(shader, light.posLoc, position, 3); + SetShaderValue(shader, light.posLoc, position, UNIFORM_VEC3); // Send to shader light target position values float target[3] = { light.target.x, light.target.y, light.target.z }; - SetShaderValue(shader, light.targetLoc, target, 3); + SetShaderValue(shader, light.targetLoc, target, UNIFORM_VEC3); // Send to shader light color values float diff[4] = { (float)light.color.r/(float)255, (float)light.color.g/(float)255, (float)light.color.b/(float)255, (float)light.color.a/(float)255 }; - SetShaderValue(shader, light.colorLoc, diff, 4); + SetShaderValue(shader, light.colorLoc, diff, UNIFORM_VEC4); } #endif // RLIGHTS_IMPLEMENTATION \ No newline at end of file diff --git a/examples/others/standard_lighting.c b/examples/others/standard_lighting.c index 72890436..7034aa35 100644 --- a/examples/others/standard_lighting.c +++ b/examples/others/standard_lighting.c @@ -350,9 +350,6 @@ static void GetShaderLightsLocations(Shader shader) // Set shader uniform values for lights // NOTE: It would be far easier with shader UBOs but are not supported on OpenGL ES 2.0 -// TODO: Replace glUniform1i(), glUniform1f(), glUniform3f(), glUniform4f(): -//SetShaderValue(Shader shader, int uniformLoc, float *value, int size) -//SetShaderValuei(Shader shader, int uniformLoc, int *value, int size) static void SetShaderLightsValues(Shader shader) { int tempInt[8] = { 0 }; @@ -363,20 +360,20 @@ static void SetShaderLightsValues(Shader shader) if (i < lightsCount) { tempInt[0] = lights[i]->enabled; - SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], lights[i]->enabled); + SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], lights[i]->enabled); tempInt[0] = lights[i]->type; - SetShaderValuei(shader, lightsLocs[i][1], tempInt, 1); //glUniform1i(lightsLocs[i][1], lights[i]->type); + SetShaderValue(shader, lightsLocs[i][1], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][1], lights[i]->type); tempFloat[0] = (float)lights[i]->diffuse.r/255.0f; tempFloat[1] = (float)lights[i]->diffuse.g/255.0f; tempFloat[2] = (float)lights[i]->diffuse.b/255.0f; tempFloat[3] = (float)lights[i]->diffuse.a/255.0f; - SetShaderValue(shader, lightsLocs[i][5], tempFloat, 4); + SetShaderValue(shader, lightsLocs[i][5], tempFloat, UNIFORM_VEC4); //glUniform4f(lightsLocs[i][5], (float)lights[i]->diffuse.r/255, (float)lights[i]->diffuse.g/255, (float)lights[i]->diffuse.b/255, (float)lights[i]->diffuse.a/255); tempFloat[0] = lights[i]->intensity; - SetShaderValue(shader, lightsLocs[i][6], tempFloat, 1); + SetShaderValue(shader, lightsLocs[i][6], tempFloat, UNIFORM_FLOAT); switch (lights[i]->type) { @@ -385,10 +382,10 @@ static void SetShaderLightsValues(Shader shader) tempFloat[0] = lights[i]->position.x; tempFloat[1] = lights[i]->position.y; tempFloat[2] = lights[i]->position.z; - SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3); + SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3); tempFloat[0] = lights[i]->radius; - SetShaderValue(shader, lightsLocs[i][4], tempFloat, 1); + SetShaderValue(shader, lightsLocs[i][4], tempFloat, UNIFORM_FLOAT); //glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z); //glUniform1f(lightsLocs[i][4], lights[i]->radius); @@ -401,7 +398,7 @@ static void SetShaderLightsValues(Shader shader) tempFloat[0] = direction.x; tempFloat[1] = direction.y; tempFloat[2] = direction.z; - SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3); + SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3); //glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z); } break; @@ -410,7 +407,7 @@ static void SetShaderLightsValues(Shader shader) tempFloat[0] = lights[i]->position.x; tempFloat[1] = lights[i]->position.y; tempFloat[2] = lights[i]->position.z; - SetShaderValue(shader, lightsLocs[i][2], tempFloat, 3); + SetShaderValue(shader, lightsLocs[i][2], tempFloat, UNIFORM_VEC3); //glUniform3f(lightsLocs[i][2], lights[i]->position.x, lights[i]->position.y, lights[i]->position.z); @@ -420,11 +417,11 @@ static void SetShaderLightsValues(Shader shader) tempFloat[0] = direction.x; tempFloat[1] = direction.y; tempFloat[2] = direction.z; - SetShaderValue(shader, lightsLocs[i][3], tempFloat, 3); + SetShaderValue(shader, lightsLocs[i][3], tempFloat, UNIFORM_VEC3); //glUniform3f(lightsLocs[i][3], direction.x, direction.y, direction.z); tempFloat[0] = lights[i]->coneAngle; - SetShaderValue(shader, lightsLocs[i][7], tempFloat, 1); + SetShaderValue(shader, lightsLocs[i][7], tempFloat, UNIFORM_FLOAT); //glUniform1f(lightsLocs[i][7], lights[i]->coneAngle); } break; default: break; @@ -433,7 +430,7 @@ static void SetShaderLightsValues(Shader shader) else { tempInt[0] = 0; - SetShaderValuei(shader, lightsLocs[i][0], tempInt, 1); //glUniform1i(lightsLocs[i][0], 0); // Light disabled + SetShaderValue(shader, lightsLocs[i][0], tempInt, UNIFORM_INT); //glUniform1i(lightsLocs[i][0], 0); // Light disabled } } } diff --git a/examples/shaders/resources/shaders/glsl330/palette-switch.fs b/examples/shaders/resources/shaders/glsl330/palette-switch.fs index 178c42c5..61b532ed 100644 --- a/examples/shaders/resources/shaders/glsl330/palette-switch.fs +++ b/examples/shaders/resources/shaders/glsl330/palette-switch.fs @@ -16,7 +16,7 @@ out vec4 finalColor; void main() { // Texel color fetching from texture sampler - vec4 texelColor = texture(texture0, fragTexCoord) * fragColor; + vec4 texelColor = texture(texture0, fragTexCoord)*fragColor; // Convert the (normalized) texel color RED component (GB would work, too) // to the palette index by scaling up from [0, 1] to [0, 255]. diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c index de76a376..fbfd82d0 100644 --- a/examples/shaders/shaders_custom_uniform.c +++ b/examples/shaders/shaders_custom_uniform.c @@ -79,7 +79,7 @@ int main() swirlCenter[1] = screenHeight - mousePosition.y; // Send new value to the shader to be used on drawing - SetShaderValue(shader, swirlCenterLoc, swirlCenter, 2); + SetShaderValue(shader, swirlCenterLoc, swirlCenter, UNIFORM_VEC2); UpdateCamera(&camera); // Update camera //---------------------------------------------------------------------------------- diff --git a/examples/shaders/shaders_palette_switch.c b/examples/shaders/shaders_palette_switch.c index ad09ca73..d0b56190 100644 --- a/examples/shaders/shaders_palette_switch.c +++ b/examples/shaders/shaders_palette_switch.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [shaders] example - Apply a postprocessing shader to a scene +* raylib [shaders] example - Color palette switch * * 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. @@ -9,10 +9,10 @@ * on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders * raylib comes with shaders ready for both versions, check raylib/shaders install folder * -* This example has been created using raylib 2.x (www.raylib.com) +* This example has been created using raylib 2.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* Copyright (c) 2019 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -28,7 +28,7 @@ #define COLORS_PER_PALETTE 8 #define VALUES_PER_COLOR 3 -static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE * VALUES_PER_COLOR] = { +static const int palettes[MAX_PALETTES][COLORS_PER_PALETTE*VALUES_PER_COLOR] = { { 0, 0, 0, 255, 0, 0, @@ -74,7 +74,7 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - palette-switch shader"); + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - color palette switch"); // Load shader to be used on some parts drawing // NOTE 1: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version @@ -106,9 +106,10 @@ int main() // Send new value to the shader to be used on drawing. // Note that we are sending RGB triplets w/o the alpha channel *only* if the current // palette index has changed (in order to save performances). - if (currentPalette != paletteIndex) { + if (currentPalette != paletteIndex) + { currentPalette = paletteIndex; - SetShaderValueArrayi(shader, paletteLoc, palettes[currentPalette], VALUES_PER_COLOR, COLORS_PER_PALETTE); + SetShaderValueV(shader, paletteLoc, palettes[currentPalette], UNIFORM_IVEC3, COLORS_PER_PALETTE); } //---------------------------------------------------------------------------------- @@ -126,14 +127,17 @@ int main() int leftover = screenHeight % COLORS_PER_PALETTE; int y = 0; - for (int i = 0; i < COLORS_PER_PALETTE; ++i) { + for (int i = 0; i < COLORS_PER_PALETTE; ++i) + { int height = linesPerRectangle; - if (leftover > 0) { + + if (leftover > 0) + { height += 1; leftover -= 1; } - DrawRectangle(0, y, screenWidth, height, CLITERAL{ i, i, i, 255 }); + DrawRectangle(0, y, screenWidth, height, (Color){ i, i, i, 255 }); y += height; } diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c index d1f9d5f8..79868a2a 100644 --- a/examples/shaders/shaders_raymarching.c +++ b/examples/shaders/shaders_raymarching.c @@ -48,7 +48,7 @@ int main() int resolutionLoc = GetShaderLocation(shader, "resolution"); float resolution[2] = { screenWidth, screenHeight }; - SetShaderValue(shader, resolutionLoc, resolution, 2); + SetShaderValue(shader, resolutionLoc, resolution, UNIFORM_VEC2); float runTime = 0.0f; @@ -70,11 +70,11 @@ int main() runTime += deltaTime; // Set shader required uniform values - SetShaderValue(shader, viewEyeLoc, cameraPos, 3); - SetShaderValue(shader, viewCenterLoc, cameraTarget, 3); - SetShaderValue(shader, viewUpLoc, cameraUp, 3); - SetShaderValue(shader, deltaTimeLoc, &deltaTime, 1); - SetShaderValue(shader, runTimeLoc, &runTime, 1); + SetShaderValue(shader, viewEyeLoc, cameraPos, UNIFORM_VEC3); + SetShaderValue(shader, viewCenterLoc, cameraTarget, UNIFORM_VEC3); + SetShaderValue(shader, viewUpLoc, cameraUp, UNIFORM_VEC3); + SetShaderValue(shader, deltaTimeLoc, &deltaTime, UNIFORM_FLOAT); + SetShaderValue(shader, runTimeLoc, &runTime, UNIFORM_FLOAT); //---------------------------------------------------------------------------------- // Draw -- cgit v1.2.3 From 93471b0a7c75fc675f27fc74dfda281eb8310a7a Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 10 Jan 2019 16:32:40 +0100 Subject: WARNING: Renamed module: audio -> raudio Planning to promote raudio module as a simple and easy-to-use front-end for the amazing mini_al library, so the name change. Name comes from raylib-audio but in spanish it also remembers to word "raudo", meaning "very fast", an analogy that fits perfectly to the usefulness and performance of the library! Consequently, raylib version has been bumped to 2.4-dev. --- examples/others/audio_standalone.c | 141 ------------------------------------ examples/others/raudio_standalone.c | 141 ++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 141 deletions(-) delete mode 100644 examples/others/audio_standalone.c create mode 100644 examples/others/raudio_standalone.c (limited to 'examples') diff --git a/examples/others/audio_standalone.c b/examples/others/audio_standalone.c deleted file mode 100644 index f08fbf82..00000000 --- a/examples/others/audio_standalone.c +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************************* -* -* raylib [audio] example - Using audio module as standalone module -* -* NOTE: This example does not require any graphic device, it can run directly on console. -* -* DEPENDENCIES: -* mini_al.h - Audio device management lib (http://kcat.strangesoft.net/openal.html) -* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) -* jar_xm.h - XM module file loading -* jar_mod.h - MOD audio file loading -* dr_flac.h - FLAC audio file loading -* -* COMPILATION: -* gcc -c ..\..\src\external\mini_al.c -Wall -I. -* gcc -o audio_standalone.exe audio_standalone.c ..\..\src\audio.c ..\..\src\external\stb_vorbis.c mini_al.o / -* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 / -* -DAUDIO_STANDALONE -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG -* -* LICENSE: zlib/libpng -* -* This example is 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) 2014-2018 Ramon Santamaria (@raysan5) -* -* This software is provided "as-is", without any express or implied warranty. In no event -* will the authors be held liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, including commercial -* applications, and to alter it and redistribute it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not claim that you -* wrote the original software. If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but is not required. -* -* 2. Altered source versions must be plainly marked as such, and must not be misrepresented -* as being the original software. -* -* 3. This notice may not be removed or altered from any source distribution. -* -********************************************************************************************/ - -#include "audio.h" // Audio library - -#include // Required for: printf() - -#if defined(_WIN32) - #include // Windows only, no stardard library -#else - -// Provide kbhit() function in non-Windows platforms -#include -#include -#include -#include - -// Check if a key has been pressed -static int kbhit(void) -{ - struct termios oldt, newt; - int ch; - int oldf; - - tcgetattr(STDIN_FILENO, &oldt); - newt = oldt; - newt.c_lflag &= ~(ICANON | ECHO); - tcsetattr(STDIN_FILENO, TCSANOW, &newt); - oldf = fcntl(STDIN_FILENO, F_GETFL, 0); - fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); - - ch = getchar(); - - tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - fcntl(STDIN_FILENO, F_SETFL, oldf); - - if (ch != EOF) - { - ungetc(ch, stdin); - return 1; - } - - return 0; -} - -// Get pressed character -static char getch() { return getchar(); } - -#endif - -#define KEY_ESCAPE 27 - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - static unsigned char key; - - InitAudioDevice(); - - Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file - Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file - - Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg"); - PlayMusicStream(music); - - printf("\nPress s or d to play sounds...\n"); - //-------------------------------------------------------------------------------------- - - // Main loop - while (key != KEY_ESCAPE) - { - if (kbhit()) key = getch(); - - if (key == 's') - { - PlaySound(fxWav); - key = 0; - } - - if (key == 'd') - { - PlaySound(fxOgg); - key = 0; - } - - UpdateMusicStream(music); - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadSound(fxWav); // Unload sound data - UnloadSound(fxOgg); // Unload sound data - - UnloadMusicStream(music); // Unload music stream data - - CloseAudioDevice(); - //-------------------------------------------------------------------------------------- - - return 0; -} diff --git a/examples/others/raudio_standalone.c b/examples/others/raudio_standalone.c new file mode 100644 index 00000000..930bde85 --- /dev/null +++ b/examples/others/raudio_standalone.c @@ -0,0 +1,141 @@ +/******************************************************************************************* +* +* raylib [audio] example - Using raudio module as standalone module +* +* NOTE: This example does not require any graphic device, it can run directly on console. +* +* DEPENDENCIES: +* mini_al.h - Audio device management lib (http://kcat.strangesoft.net/openal.html) +* stb_vorbis.h - Ogg audio files loading (http://www.nothings.org/stb_vorbis/) +* jar_xm.h - XM module file loading +* jar_mod.h - MOD audio file loading +* dr_flac.h - FLAC audio file loading +* +* COMPILATION: +* gcc -c ..\..\src\external\mini_al.c -Wall -I. +* gcc -o audio_standalone.exe audio_standalone.c ..\..\src\raudio.c mini_al.o / +* -I..\..\src -I..\..\src\external -L. -Wall -std=c99 / +* -DAUDIO_STANDALONE -DSUPPORT_FILEFORMAT_WAV -DSUPPORT_FILEFORMAT_OGG +* +* LICENSE: zlib/libpng +* +* This example is 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) 2014-2019 Ramon Santamaria (@raysan5) +* +* This software is provided "as-is", without any express or implied warranty. In no event +* will the authors be held liable for any damages arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, including commercial +* applications, and to alter it and redistribute it freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not claim that you +* wrote the original software. If you use this software in a product, an acknowledgment +* in the product documentation would be appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be misrepresented +* as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +* +********************************************************************************************/ + +#include "raudio.h" // raylib audio library + +#include // Required for: printf() + +#if defined(_WIN32) + #include // Windows only, no stardard library +#else + +// Provide kbhit() function in non-Windows platforms +#include +#include +#include +#include + +// Check if a key has been pressed +static int kbhit(void) +{ + struct termios oldt, newt; + int ch; + int oldf; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + if (ch != EOF) + { + ungetc(ch, stdin); + return 1; + } + + return 0; +} + +// Get pressed character +static char getch() { return getchar(); } + +#endif + +#define KEY_ESCAPE 27 + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + static unsigned char key; + + InitAudioDevice(); + + Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file + Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file + + Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg"); + PlayMusicStream(music); + + printf("\nPress s or d to play sounds...\n"); + //-------------------------------------------------------------------------------------- + + // Main loop + while (key != KEY_ESCAPE) + { + if (kbhit()) key = getch(); + + if (key == 's') + { + PlaySound(fxWav); + key = 0; + } + + if (key == 'd') + { + PlaySound(fxOgg); + key = 0; + } + + UpdateMusicStream(music); + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadSound(fxWav); // Unload sound data + UnloadSound(fxOgg); // Unload sound data + + UnloadMusicStream(music); // Unload music stream data + + CloseAudioDevice(); + //-------------------------------------------------------------------------------------- + + return 0; +} -- cgit v1.2.3