summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorBruno Cabral <[email protected]>2024-06-30 01:33:32 -0700
committerGitHub <[email protected]>2024-06-30 10:33:32 +0200
commit6e2661f92d38aa669047bcf63db8c27a1c1f6dec (patch)
tree80533b0fdc1065bd18b3ac89243d985e212a8813 /examples
parent5b8efd68ba2d8e2c707d5811a5ce7185b2bead76 (diff)
downloadraylib-6e2661f92d38aa669047bcf63db8c27a1c1f6dec.tar.gz
raylib-6e2661f92d38aa669047bcf63db8c27a1c1f6dec.zip
[rtextures] Created `ImageFromChannel()` (#4105)
* created ImageFromChannel Adds the possibility to extract a specific channel from an image * naming convention * example window height * removed threshold * removed alpha channel * channel example organization * updated channel example image
Diffstat (limited to 'examples')
-rw-r--r--examples/textures/textures_image_channel.c106
-rw-r--r--examples/textures/textures_image_channel.pngbin0 -> 234960 bytes
2 files changed, 106 insertions, 0 deletions
diff --git a/examples/textures/textures_image_channel.c b/examples/textures/textures_image_channel.c
new file mode 100644
index 00000000..39618c5f
--- /dev/null
+++ b/examples/textures/textures_image_channel.c
@@ -0,0 +1,106 @@
+/*******************************************************************************************
+*
+* raylib [textures] example - Retrive image channel (mask)
+*
+* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
+*
+* Example originally created with raylib 5.1-dev, last time updated with raylib 5.1-dev
+*
+* Example contributed by Bruno Cabral (github.com/brccabral) 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) 2024-2024 Bruno Cabral (github.com/brccabral) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include <raylib.h>
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - extract channel from image");
+
+ Image fudesumiImage = LoadImage("resources/fudesumi.png");
+
+ Image imageAlpha = ImageFromChannel(fudesumiImage, 3);
+ ImageAlphaMask(&imageAlpha, imageAlpha);
+
+ Image imageRed = ImageFromChannel(fudesumiImage, 0);
+ ImageAlphaMask(&imageRed, imageAlpha);
+
+ Image imageGreen = ImageFromChannel(fudesumiImage, 1);
+ ImageAlphaMask(&imageGreen, imageAlpha);
+
+ Image imageBlue = ImageFromChannel(fudesumiImage, 2);
+ ImageAlphaMask(&imageBlue, imageAlpha);
+
+ Image backgroundImage = GenImageChecked(screenWidth, screenHeight, screenWidth/20, screenHeight/20, ORANGE, YELLOW);
+
+ Texture2D fudesumiTexture = LoadTextureFromImage(fudesumiImage);
+ Texture2D textureAlpha = LoadTextureFromImage(imageAlpha);
+ Texture2D textureRed = LoadTextureFromImage(imageRed);
+ Texture2D textureGreen = LoadTextureFromImage(imageGreen);
+ Texture2D textureBlue = LoadTextureFromImage(imageBlue);
+ Texture2D backgroundTexture = LoadTextureFromImage(backgroundImage);
+
+ UnloadImage(fudesumiImage);
+ UnloadImage(imageAlpha);
+ UnloadImage(imageRed);
+ UnloadImage(imageGreen);
+ UnloadImage(imageBlue);
+ UnloadImage(backgroundImage);
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+
+ Rectangle fudesumiRec = {0, 0, fudesumiImage.width, fudesumiImage.height};
+
+ Rectangle fudesumiPos = {50, 10, fudesumiImage.width*0.8f, fudesumiImage.height*0.8f};
+ Rectangle redPos = { 410, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 };
+ Rectangle greenPos = { 600, 10, fudesumiPos.width / 2, fudesumiPos.height / 2 };
+ Rectangle bluePos = { 410, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 };
+ Rectangle alphaPos = { 600, 230, fudesumiPos.width / 2, fudesumiPos.height / 2 };
+
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ DrawTexture(backgroundTexture, 0, 0, WHITE);
+ DrawTexturePro(fudesumiTexture, fudesumiRec, fudesumiPos, (Vector2) {0, 0}, 0, WHITE);
+
+ DrawTexturePro(textureRed, fudesumiRec, redPos, (Vector2) {0, 0}, 0, RED);
+ DrawTexturePro(textureGreen, fudesumiRec, greenPos, (Vector2) {0, 0}, 0, GREEN);
+ DrawTexturePro(textureBlue, fudesumiRec, bluePos, (Vector2) {0, 0}, 0, BLUE);
+ DrawTexturePro(textureAlpha, fudesumiRec, alphaPos, (Vector2) {0, 0}, 0, WHITE);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(backgroundTexture);
+ UnloadTexture(fudesumiTexture);
+ UnloadTexture(textureRed);
+ UnloadTexture(textureGreen);
+ UnloadTexture(textureBlue);
+ UnloadTexture(textureAlpha);
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/textures/textures_image_channel.png b/examples/textures/textures_image_channel.png
new file mode 100644
index 00000000..55e1d2ea
--- /dev/null
+++ b/examples/textures/textures_image_channel.png
Binary files differ