summaryrefslogtreecommitdiffhomepage
path: root/examples/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'examples/shaders')
-rw-r--r--examples/shaders/shader_texture_tiling.c94
-rw-r--r--examples/shaders/shaders_custom_uniform.c2
-rw-r--r--examples/shaders/shaders_deferred_render.pngbin90692 -> 81327 bytes
-rw-r--r--examples/shaders/shaders_texture_tiling.c105
-rw-r--r--examples/shaders/shaders_texture_tiling.pngbin0 -> 139191 bytes
5 files changed, 106 insertions, 95 deletions
diff --git a/examples/shaders/shader_texture_tiling.c b/examples/shaders/shader_texture_tiling.c
deleted file mode 100644
index 868d6b8f..00000000
--- a/examples/shaders/shader_texture_tiling.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************************
-*
-* raylib [textures] example - Texture Tiling
-*
-* Example demonstrates how to tile a texture on a 3D model using raylib.
-*
-* Example contributed by Luís Almeida (https://github.com/luis605)
-*
-* 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) 2023 Luís Almeida (https://github.com/luis605)
-*
-********************************************************************************************/
-
-#include "raylib.h"
-
-//------------------------------------------------------------------------------------
-// Program main entry point
-//------------------------------------------------------------------------------------
-
-int main(void)
-{
- const int screenWidth = 800;
- const int screenHeight = 600;
-
- // Initialization
- //--------------------------------------------------------------------------------------
- InitWindow(screenWidth, screenHeight, "Raylib Texture Tiling");
-
- SetTargetFPS(60);
-
- // Load a texture
- Texture2D texture = LoadTexture("resources/raylib_logo.png");
-
- // Create a cube mesh
- Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
-
- // Load the texture onto the GPU
- Model model = LoadModelFromMesh(cube);
- model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
-
- // Set the tiling of the texture
- float tiling[2] = {3.0f, 3.0f};
- Shader shader = LoadShader(0, "resources/shaders/glsl330/tiling.fs"); // Create a custom shader in a .glsl file
- SetShaderValue(shader, GetShaderLocation(shader, "tiling"), tiling, SHADER_UNIFORM_VEC2);
- model.materials[0].shader = shader;
-
- // Camera setup
- Camera camera = { 0 };
- camera.position = (Vector3){ 3.0f, 3.0f, 3.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;
-
- // Main game loop
- while (!WindowShouldClose())
- {
- // Update
- //----------------------------------------------------------------------------------
-
- BeginDrawing();
- ClearBackground(RAYWHITE);
- UpdateCamera(&camera, CAMERA_FREE);
-
- // Draw the model
- {
- BeginMode3D(camera);
- BeginShaderMode(shader);
-
- DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE);
-
- EndShaderMode();
- EndMode3D();
- }
-
- DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
-
- EndDrawing();
- }
-
- // De-Initialization
- //--------------------------------------------------------------------------------------
-
- UnloadTexture(texture); // Unload texture
- UnloadModel(model); // Unload model
- UnloadShader(shader); // Unload shader
-
-
- CloseWindow(); // Close window and OpenGL context
-
- return 0;
-}
diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c
index 0a1a7642..b3b80400 100644
--- a/examples/shaders/shaders_custom_uniform.c
+++ b/examples/shaders/shaders_custom_uniform.c
@@ -1,6 +1,6 @@
/*******************************************************************************************
*
-* raylib [shaders] example - Apply a postprocessing shader and connect a custom uniform variable
+* raylib [shaders] example - Postprocessing with custom uniform variable
*
* 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.
diff --git a/examples/shaders/shaders_deferred_render.png b/examples/shaders/shaders_deferred_render.png
index 44129f0f..90fa0129 100644
--- a/examples/shaders/shaders_deferred_render.png
+++ b/examples/shaders/shaders_deferred_render.png
Binary files differ
diff --git a/examples/shaders/shaders_texture_tiling.c b/examples/shaders/shaders_texture_tiling.c
new file mode 100644
index 00000000..0d07bdff
--- /dev/null
+++ b/examples/shaders/shaders_texture_tiling.c
@@ -0,0 +1,105 @@
+/*******************************************************************************************
+*
+* raylib [shaders] example - texture tiling
+*
+* Example demonstrates how to tile a texture on a 3D model using raylib.
+*
+* Example contributed by Luis Almeida (@luis605) 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) 2023 Luis Almeida (@luis605)
+*
+********************************************************************************************/
+
+#include "raylib.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;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture tiling");
+
+ // Define the camera to look into our 3d world
+ Camera3D camera = { 0 };
+ camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position
+ camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; // Camera looking at point
+ camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target)
+ camera.fovy = 45.0f; // Camera field-of-view Y
+ camera.projection = CAMERA_PERSPECTIVE; // Camera projection type
+
+ // Load a cube model
+ Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f);
+ Model model = LoadModelFromMesh(cube);
+
+ // Load a texture and assign to cube model
+ Texture2D texture = LoadTexture("resources/cubicmap_atlas.png");
+ model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture;
+
+ // Set the texture tiling using a shader
+ float tiling[2] = { 3.0f, 3.0f };
+ Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/tiling.fs", GLSL_VERSION));
+ SetShaderValue(shader, GetShaderLocation(shader, "tiling"), tiling, SHADER_UNIFORM_VEC2);
+ model.materials[0].shader = shader;
+
+ DisableCursor(); // Limit cursor to relative movement inside the window
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ UpdateCamera(&camera, CAMERA_FREE);
+
+ if (IsKeyPressed('Z')) camera.target = (Vector3){ 0.0f, 0.5f, 0.0f };
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ BeginMode3D(camera);
+
+ BeginShaderMode(shader);
+ DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE);
+ EndShaderMode();
+
+ DrawGrid(10, 1.0f);
+
+ EndMode3D();
+
+ DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadModel(model); // Unload model
+ UnloadShader(shader); // Unload shader
+ UnloadTexture(texture); // Unload texture
+
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/shaders/shaders_texture_tiling.png b/examples/shaders/shaders_texture_tiling.png
new file mode 100644
index 00000000..5dfe76ef
--- /dev/null
+++ b/examples/shaders/shaders_texture_tiling.png
Binary files differ