aboutsummaryrefslogtreecommitdiff
path: root/examples/shaders_postprocessing.c
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2016-03-30 20:09:16 +0200
committerraysan5 <raysan5@gmail.com>2016-03-30 20:09:16 +0200
commit66b096d97848eb096a043781f1f305e7189f2a00 (patch)
treecf87fdd3f4bc46dc93dcaa2f189a5d1dd1e3f32b /examples/shaders_postprocessing.c
parent1136d4222f81524c10b2319b325fcf1282bc6ec1 (diff)
downloadraylib-66b096d97848eb096a043781f1f305e7189f2a00.tar.gz
raylib-66b096d97848eb096a043781f1f305e7189f2a00.zip
Added support for render to texture (use RenderTexture2D)
Now it's possible to render to texture, old postprocessing system will be removed on next raylib version.
Diffstat (limited to 'examples/shaders_postprocessing.c')
-rw-r--r--examples/shaders_postprocessing.c36
1 files changed, 26 insertions, 10 deletions
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;