Browse Source

ADDED: GetScreenData()

raysan5 6 years ago
parent
commit
f02a0334d8
2 changed files with 15 additions and 2 deletions
  1. 1 0
      src/raylib.h
  2. 14 2
      src/textures.c

+ 1 - 0
src/raylib.h

@@ -1095,6 +1095,7 @@ RLAPI Color *GetImageData(Image image);
 RLAPI Vector4 *GetImageDataNormalized(Image image);                                                      // Get pixel data from image as Vector4 array (float normalized)
 RLAPI Vector4 *GetImageDataNormalized(Image image);                                                      // Get pixel data from image as Vector4 array (float normalized)
 RLAPI int GetPixelDataSize(int width, int height, int format);                                           // Get pixel data size in bytes (image or texture)
 RLAPI int GetPixelDataSize(int width, int height, int format);                                           // Get pixel data size in bytes (image or texture)
 RLAPI Image GetTextureData(Texture2D texture);                                                           // Get pixel data from GPU texture and return an Image
 RLAPI Image GetTextureData(Texture2D texture);                                                           // Get pixel data from GPU texture and return an Image
+RLAPI Image GetScreenData(void);                                                                         // Get pixel data from screen buffer and return an Image (screenshot)
 RLAPI void UpdateTexture(Texture2D texture, const void *pixels);                                         // Update GPU texture with new data
 RLAPI void UpdateTexture(Texture2D texture, const void *pixels);                                         // Update GPU texture with new data
 
 
 // Image manipulation functions
 // Image manipulation functions

+ 14 - 2
src/textures.c

@@ -740,6 +740,20 @@ Image GetTextureData(Texture2D texture)
     return image;
     return image;
 }
 }
 
 
+// Get pixel data from GPU frontbuffer and return an Image (screenshot)
+RLAPI Image GetScreenData(void)
+{
+    Image image = { 0 };
+    
+    image.width = GetScreenWidth();
+    image.height = GetScreenHeight();
+    image.mipmaps = 1;
+    image.format = UNCOMPRESSED_R8G8B8A8;
+    image.data = rlReadScreenPixels(image.width, image.height);
+
+    return image;
+}
+
 // Update GPU texture with new data
 // Update GPU texture with new data
 // NOTE: pixels data must match texture.format
 // NOTE: pixels data must match texture.format
 void UpdateTexture(Texture2D texture, const void *pixels)
 void UpdateTexture(Texture2D texture, const void *pixels)
@@ -1168,8 +1182,6 @@ void ImageAlphaPremultiply(Image *image)
     ImageFormat(image, prevFormat);
     ImageFormat(image, prevFormat);
 }
 }
 
 
-
-
 #if defined(SUPPORT_IMAGE_MANIPULATION)
 #if defined(SUPPORT_IMAGE_MANIPULATION)
 // Load cubemap from image, multiple image cubemap layouts supported
 // Load cubemap from image, multiple image cubemap layouts supported
 TextureCubemap LoadTextureCubemap(Image image, int layoutType)
 TextureCubemap LoadTextureCubemap(Image image, int layoutType)