WARNING: BREAKING: Functions renamed for consistency
RENAMED: GetTextureData() -> LoadImageFromTexture() RENAMED: GetScreenData() -> LoadImageFromScreen()
This commit is contained in:
parent
5f03201616
commit
e5cf3f9555
@ -146,7 +146,7 @@ int main(void)
|
||||
// NOTE: Saving painted texture to a default named image
|
||||
if ((btnSaveMouseHover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) || IsKeyPressed(KEY_S))
|
||||
{
|
||||
Image image = GetTextureData(target.texture);
|
||||
Image image = LoadImageFromTexture(target.texture);
|
||||
ImageFlipVertical(&image);
|
||||
ExportImage(image, "my_amazing_texture_painting.png");
|
||||
UnloadImage(image);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [textures] example - Retrieve image data from texture: GetTextureData()
|
||||
* raylib [textures] example - Retrieve image data from texture: LoadImageFromTexture()
|
||||
*
|
||||
* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
|
||||
*
|
||||
@ -28,7 +28,7 @@ int main(void)
|
||||
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM)
|
||||
UnloadImage(image); // Unload image data from CPU memory (RAM)
|
||||
|
||||
image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM)
|
||||
image = LoadImageFromTexture(texture); // Load image from GPU texture (VRAM -> RAM)
|
||||
UnloadTexture(texture); // Unload texture from GPU memory (VRAM)
|
||||
|
||||
texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM)
|
||||
|
@ -1189,6 +1189,8 @@ RLAPI Image LoadImage(const char *fileName);
|
||||
RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data
|
||||
RLAPI Image LoadImageAnim(const char *fileName, int *frames); // Load image sequence from file (frames appended to image.data)
|
||||
RLAPI Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, int dataSize); // Load image from memory buffer, fileType refers to extension: i.e. '.png'
|
||||
RLAPI Image LoadImageFromTexture(Texture2D texture); // Load image from GPU texture data
|
||||
RLAPI Image LoadImageFromScreen(void); // Load image from screen buffer and (screenshot)
|
||||
RLAPI void UnloadImage(Image image); // Unload image from CPU memory (RAM)
|
||||
RLAPI bool ExportImage(Image image, const char *fileName); // Export image data to file, returns true on success
|
||||
RLAPI bool ExportImageAsCode(Image image, const char *fileName); // Export image as code file defining an array of bytes, returns true on success
|
||||
@ -1263,8 +1265,6 @@ RLAPI void UnloadTexture(Texture2D texture);
|
||||
RLAPI void UnloadRenderTexture(RenderTexture2D target); // Unload render texture from GPU memory (VRAM)
|
||||
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
|
||||
RLAPI void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels); // Update GPU texture rectangle with new data
|
||||
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)
|
||||
|
||||
// Texture configuration functions
|
||||
RLAPI void GenTextureMipmaps(Texture2D *texture); // Generate GPU mipmaps for a texture
|
||||
|
@ -385,6 +385,52 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
|
||||
return image;
|
||||
}
|
||||
|
||||
// Load image from GPU texture data
|
||||
// NOTE: Compressed texture formats not supported
|
||||
Image LoadImageFromTexture(Texture2D texture)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB)
|
||||
{
|
||||
image.data = rlReadTexturePixels(texture);
|
||||
|
||||
if (image.data != NULL)
|
||||
{
|
||||
image.width = texture.width;
|
||||
image.height = texture.height;
|
||||
image.format = texture.format;
|
||||
image.mipmaps = 1;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA,
|
||||
// coming from FBO color buffer attachment, but it seems
|
||||
// original texture format is retrieved on RPI...
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
#endif
|
||||
TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Pixel data retrieved successfully", texture.id);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve pixel data", texture.id);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve compressed pixel data", texture.id);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
// Load image from screen buffer and (screenshot)
|
||||
Image LoadImageFromScreen(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
image.width = GetScreenWidth();
|
||||
image.height = GetScreenHeight();
|
||||
image.mipmaps = 1;
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
image.data = rlReadScreenPixels(image.width, image.height);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
// Unload image from CPU memory (RAM)
|
||||
void UnloadImage(Image image)
|
||||
{
|
||||
@ -2804,52 +2850,6 @@ void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels)
|
||||
rlUpdateTexture(texture.id, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, texture.format, pixels);
|
||||
}
|
||||
|
||||
// Get pixel data from GPU texture and return an Image
|
||||
// NOTE: Compressed texture formats not supported
|
||||
Image GetTextureData(Texture2D texture)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB)
|
||||
{
|
||||
image.data = rlReadTexturePixels(texture);
|
||||
|
||||
if (image.data != NULL)
|
||||
{
|
||||
image.width = texture.width;
|
||||
image.height = texture.height;
|
||||
image.format = texture.format;
|
||||
image.mipmaps = 1;
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
// NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA,
|
||||
// coming from FBO color buffer attachment, but it seems
|
||||
// original texture format is retrieved on RPI...
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
#endif
|
||||
TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Pixel data retrieved successfully", texture.id);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve pixel data", texture.id);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve compressed pixel data", texture.id);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
// Get pixel data from GPU frontbuffer and return an Image (screenshot)
|
||||
Image GetScreenData(void)
|
||||
{
|
||||
Image image = { 0 };
|
||||
|
||||
image.width = GetScreenWidth();
|
||||
image.height = GetScreenHeight();
|
||||
image.mipmaps = 1;
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
image.data = rlReadScreenPixels(image.width, image.height);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Texture configuration functions
|
||||
//------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user