diff options
| author | Ray <[email protected]> | 2020-11-01 13:39:48 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2020-11-01 13:39:48 +0100 |
| commit | 8e15dae5ed8264565d3f94aeac7a663ce76a2e62 (patch) | |
| tree | 299a73e64ef3240746353b2353c73b284400c748 /examples/textures | |
| parent | 5f79ad9765f1d01e72b84b257911ae8dd4dbc232 (diff) | |
| download | raylib-8e15dae5ed8264565d3f94aeac7a663ce76a2e62.tar.gz raylib-8e15dae5ed8264565d3f94aeac7a663ce76a2e62.zip | |
Review contributed examples
Diffstat (limited to 'examples/textures')
| -rw-r--r-- | examples/textures/textures_blend_modes.c | 135 |
1 files changed, 64 insertions, 71 deletions
diff --git a/examples/textures/textures_blend_modes.c b/examples/textures/textures_blend_modes.c index bb19f56c..2d9b0af9 100644 --- a/examples/textures/textures_blend_modes.c +++ b/examples/textures/textures_blend_modes.c @@ -4,9 +4,11 @@ * * 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) +* This example has been created using raylib 3.5 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * +* Example contributed by Karlo Licudine (@accidentalrebel) and reviewed by Ramon Santamaria (@raysan5) +* * Copyright (c) 2020 Karlo Licudine (@accidentalrebel) * ********************************************************************************************/ @@ -15,86 +17,77 @@ int main(void) { - // Initialization - //-------------------------------------------------------------------------------------- - const int screenWidth = 800; - const int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes"); + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; - // 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) + InitWindow(screenWidth, screenHeight, "raylib [textures] example - blend modes"); - Image fgImage = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM) - Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM) + // 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) - // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM - UnloadImage(bgImage); - UnloadImage(fgImage); + Image fgImage = LoadImage("resources/cyberpunk_street_foreground.png"); // Loaded in CPU memory (RAM) + Texture2D fgTexture = LoadTextureFromImage(fgImage); // Image converted to texture, GPU memory (VRAM) - 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(); + // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + UnloadImage(bgImage); + UnloadImage(fgImage); - ClearBackground(RAYWHITE); + const int blendCountMax = 4; + BlendMode blendMode = 0; + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_SPACE)) + { + if (blendMode >= (blendCountMax - 1)) blendMode = 0; + else blendMode++; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); - BeginBlendMode(BLEND_ALPHA); - DrawTexture(bgTexture, screenWidth/2 - bgTexture.width/2, screenHeight/2 - bgTexture.height/2, WHITE); + ClearBackground(RAYWHITE); - // 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); + DrawTexture(bgTexture, screenWidth/2 - bgTexture.width/2, screenHeight/2 - bgTexture.height/2, WHITE); - EndBlendMode(); + // 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); + // Draw the texts + DrawText("Press SPACE 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; + default: break; + } + + DrawText("(c) Cyberpunk Street Environment by Luis Zuno (@ansimuz)", screenWidth - 330, screenHeight - 20, 10, GRAY); - EndDrawing(); - //---------------------------------------------------------------------------------- - } + EndDrawing(); + //---------------------------------------------------------------------------------- + } - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(fgTexture); // Unload foreground texture - UnloadTexture(bgTexture); // Unload background texture + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(fgTexture); // Unload foreground texture + UnloadTexture(bgTexture); // Unload background texture - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; } |
