summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2021-02-06 13:15:23 +0100
committerraysan5 <[email protected]>2021-02-06 13:15:23 +0100
commitb7b718a545a2d7fad700ac4a11322423c98578d0 (patch)
tree92919bf39fb6a13045ad2fe1cf078b811ad1b9c4 /examples
parent0f309b9b16c7986c5bda65ff002b7a5b432642d4 (diff)
downloadraylib-b7b718a545a2d7fad700ac4a11322423c98578d0.tar.gz
raylib-b7b718a545a2d7fad700ac4a11322423c98578d0.zip
REVIEWED: example: Replaced GetImageData()
Diffstat (limited to 'examples')
-rw-r--r--examples/textures/textures_image_processing.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/examples/textures/textures_image_processing.c b/examples/textures/textures_image_processing.c
index 46d8354d..83d388ce 100644
--- a/examples/textures/textures_image_processing.c
+++ b/examples/textures/textures_image_processing.c
@@ -4,7 +4,7 @@
*
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
*
-* This example has been created using raylib 1.4 (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)
*
* Copyright (c) 2016 Ramon Santamaria (@raysan5)
@@ -50,9 +50,11 @@ int main(void)
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
- Image image = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
- ImageFormat(&image, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
- Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
+ Image imOrigin = LoadImage("resources/parrots.png"); // Loaded in CPU memory (RAM)
+ ImageFormat(&imOrigin, UNCOMPRESSED_R8G8B8A8); // Format image to RGBA 32bit (required for texture update) <-- ISSUE
+ Texture2D texture = LoadTextureFromImage(imOrigin); // Image converted to texture, GPU memory (VRAM)
+
+ Image imCopy = ImageCopy(imOrigin);
int currentProcess = NONE;
bool textureReload = false;
@@ -92,7 +94,7 @@ int main(void)
if (IsKeyPressed(KEY_DOWN))
{
currentProcess++;
- if (currentProcess > 7) currentProcess = 0;
+ if (currentProcess > (NUM_PROCESSES - 1)) currentProcess = 0;
textureReload = true;
}
else if (IsKeyPressed(KEY_UP))
@@ -105,27 +107,27 @@ int main(void)
// Reload texture when required
if (textureReload)
{
- UnloadImage(image); // Unload current image data
- image = LoadImage("resources/parrots.png"); // Re-load image data
-
+ UnloadImage(imCopy); // Unload image-copy data
+ imCopy = ImageCopy(imOrigin); // Restore image-copy from image-origin
+
// NOTE: Image processing is a costly CPU process to be done every frame,
// If image processing is required in a frame-basis, it should be done
// with a texture and by shaders
switch (currentProcess)
{
- case COLOR_GRAYSCALE: ImageColorGrayscale(&image); break;
- case COLOR_TINT: ImageColorTint(&image, GREEN); break;
- case COLOR_INVERT: ImageColorInvert(&image); break;
- case COLOR_CONTRAST: ImageColorContrast(&image, -40); break;
- case COLOR_BRIGHTNESS: ImageColorBrightness(&image, -80); break;
- case FLIP_VERTICAL: ImageFlipVertical(&image); break;
- case FLIP_HORIZONTAL: ImageFlipHorizontal(&image); break;
+ case COLOR_GRAYSCALE: ImageColorGrayscale(&imCopy); break;
+ case COLOR_TINT: ImageColorTint(&imCopy, GREEN); break;
+ case COLOR_INVERT: ImageColorInvert(&imCopy); break;
+ case COLOR_CONTRAST: ImageColorContrast(&imCopy, -40); break;
+ case COLOR_BRIGHTNESS: ImageColorBrightness(&imCopy, -80); break;
+ case FLIP_VERTICAL: ImageFlipVertical(&imCopy); break;
+ case FLIP_HORIZONTAL: ImageFlipHorizontal(&imCopy); break;
default: break;
}
- Color *pixels = GetImageData(image); // Get pixel data from image (RGBA 32bit)
+ Color *pixels = LoadImageColors(imCopy); // Load pixel data from image (RGBA 32bit)
UpdateTexture(texture, pixels); // Update texture with new image data
- free(pixels); // Unload pixels data from RAM
+ UnloadImageColors(pixels); // Unload pixels data from RAM
textureReload = false;
}
@@ -157,7 +159,8 @@ int main(void)
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Unload texture from VRAM
- UnloadImage(image); // Unload image from RAM
+ UnloadImage(imOrigin); // Unload image-origin from RAM
+ UnloadImage(imCopy); // Unload image-copy from RAM
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------