diff options
| author | Karlo Licudine <[email protected]> | 2020-05-22 00:30:23 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-22 02:30:23 +0200 |
| commit | a33dd87c99f03c38de0ff757fb85fa49f2011ea7 (patch) | |
| tree | 6433749c80a23905ffefa2885223620960ff8923 /examples/textures | |
| parent | c1bb051e61237ecc5faeeeb869d5c9fd5d612573 (diff) | |
| download | raylib-a33dd87c99f03c38de0ff757fb85fa49f2011ea7.tar.gz raylib-a33dd87c99f03c38de0ff757fb85fa49f2011ea7.zip | |
Added Blend Modes example. (#1261)
Diffstat (limited to 'examples/textures')
| -rw-r--r-- | examples/textures/textures_blend_modes.c | 100 | ||||
| -rw-r--r-- | examples/textures/textures_blend_modes.png | bin | 0 -> 156004 bytes |
2 files changed, 100 insertions, 0 deletions
diff --git a/examples/textures/textures_blend_modes.c b/examples/textures/textures_blend_modes.c new file mode 100644 index 00000000..bb19f56c --- /dev/null +++ b/examples/textures/textures_blend_modes.c @@ -0,0 +1,100 @@ +/******************************************************************************************* +* +* raylib [textures] example - blend modes +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* This example has been created using raylib 3.0 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2020 Karlo Licudine (@accidentalrebel) +* +********************************************************************************************/ + +#include "raylib.h" + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + Image bgImage = LoadImage("resources/cyberpunk_street_background.png"); // Loaded in CPU memory (RAM) + Texture2D bgTexture = LoadTextureFromImage(bgImage); // Image converted to texture, GPU memory (VRAM) + + Image fgImage = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM) + Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM) + + // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + UnloadImage(bgImage); + UnloadImage(fgImage); + + const int blendCountMax = 4; + BlendMode blendMode = 0; + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + int key = GetKeyPressed(); + if ((key >= 32) && (key <= 126)) + { + if ( blendMode >= blendCountMax - 1 ) + blendMode = 0; + else + blendMode++; + } + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + BeginBlendMode(BLEND_ALPHA); + DrawTexture(bgTexture, screenWidth/2 - bgTexture.width/2, screenHeight/2 - bgTexture.height/2, WHITE); + + // Apply the blend mode and then draw the foreground texture + BeginBlendMode(blendMode); + DrawTexture(fgTexture, screenWidth/2 - fgTexture.width/2, screenHeight/2 - fgTexture.height/2, WHITE); + + EndBlendMode(); + + // Draw the texts + DrawText("Press any key to change blend modes.", 310, 350, 10, GRAY); + switch ( blendMode ) + { + case BLEND_ALPHA: + DrawText("Current: BLEND_ALPHA", (screenWidth / 2) - 60, 370, 10, GRAY); + break; + case BLEND_ADDITIVE: + DrawText("Current: BLEND_ADDITIVE", (screenWidth / 2) - 60, 370, 10, GRAY); + break; + case BLEND_MULTIPLIED: + DrawText("Current: BLEND_MULTIPLIED", (screenWidth / 2) - 60, 370, 10, GRAY); + break; + case BLEND_ADD_COLORS: + DrawText("Current: BLEND_ADD_COLORS", (screenWidth / 2) - 60, 370, 10, GRAY); + break; + } + DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(fgTexture); // Unload foreground texture + UnloadTexture(bgTexture); // Unload background texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/textures/textures_blend_modes.png b/examples/textures/textures_blend_modes.png Binary files differnew file mode 100644 index 00000000..3010ace7 --- /dev/null +++ b/examples/textures/textures_blend_modes.png |
