aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/resources/shaders/base.vs3
-rw-r--r--examples/resources/shaders/bloom.fs3
-rw-r--r--examples/shaders_postprocessing.c36
3 files changed, 31 insertions, 11 deletions
diff --git a/examples/resources/shaders/base.vs b/examples/resources/shaders/base.vs
index b0f930b7..9b8cca69 100644
--- a/examples/resources/shaders/base.vs
+++ b/examples/resources/shaders/base.vs
@@ -3,8 +3,10 @@
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec3 vertexNormal;
+in vec4 vertexColor;
out vec2 fragTexCoord;
+out vec4 fragTintColor;
uniform mat4 mvpMatrix;
@@ -13,6 +15,7 @@ uniform mat4 mvpMatrix;
void main()
{
fragTexCoord = vertexTexCoord;
+ fragTintColor = vertexColor;
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
} \ No newline at end of file
diff --git a/examples/resources/shaders/bloom.fs b/examples/resources/shaders/bloom.fs
index 2833ce33..0a73161a 100644
--- a/examples/resources/shaders/bloom.fs
+++ b/examples/resources/shaders/bloom.fs
@@ -1,11 +1,12 @@
#version 330
in vec2 fragTexCoord;
+in vec4 fragTintColor;
out vec4 fragColor;
uniform sampler2D texture0;
-uniform vec4 fragTintColor;
+//uniform vec4 fragTintColor;
// NOTE: Add here your custom variables
diff --git a/examples/shaders_postprocessing.c b/examples/shaders_postprocessing.c
index 44829648..fabf5131 100644
--- a/examples/shaders_postprocessing.c
+++ b/examples/shaders_postprocessing.c
@@ -41,7 +41,11 @@ int main()
Shader shader = LoadShader("resources/shaders/base.vs",
"resources/shaders/bloom.fs"); // Load postpro shader
- SetPostproShader(shader); // Set fullscreen postprocessing shader
+ // NOTE: Old postprocessing system is not flexible enough despite being very easy to use
+ //SetPostproShader(shader); // Set fullscreen postprocessing shader
+
+ // New postprocessing system let the user create multiple RenderTexture2D and perform multiple render passes
+ RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);
// Setup orbital camera
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
@@ -65,15 +69,26 @@ int main()
ClearBackground(RAYWHITE);
- Begin3dMode(camera);
+ BeginTextureMode(target); // Enable render to texture RenderTexture2D
+
+ Begin3dMode(camera);
- DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
+ DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
- DrawGrid(10, 1.0f); // Draw a grid
+ DrawGrid(10, 1.0f); // Draw a grid
- End3dMode();
+ End3dMode();
+
+ DrawText("HELLO TEXTURE!!!", 120, 200, 60, RED);
+
+ EndTextureMode(); // End drawing to texture (now we have a texture available for next passes)
+
+ SetCustomShader(shader);
+ // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
+ DrawTextureRec(target.texture, (Rectangle){ 0, target.texture.height, target.texture.width, -target.texture.height }, (Vector2){ 0, 0 }, WHITE);
+ SetDefaultShader();
- DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, BLACK);
+ DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, DARKGRAY);
DrawFPS(10, 10);
@@ -83,11 +98,12 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- UnloadShader(shader); // Unload shader
- UnloadTexture(texture); // Unload texture
- UnloadModel(dwarf); // Unload model
+ UnloadShader(shader); // Unload shader
+ UnloadTexture(texture); // Unload texture
+ UnloadModel(dwarf); // Unload model
+ UnloadRenderTexture(target); // Unload render texture
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;