|
10 | 10 | * When choosing an OpenGL backend different than OpenGL 1.1, some internal buffer are
|
11 | 11 | * initialized on rlglInit() to accumulate vertex data
|
12 | 12 | *
|
13 |
| -* When an internal state change is required all the stored vertex data is renderer in batch, |
| 13 | +* When an internal state change is required all the stored vertex data is rendered in batch, |
14 | 14 | * additionally, rlDrawRenderBatchActive() could be called to force flushing of the batch
|
15 | 15 | *
|
16 | 16 | * Some resources are also loaded for convenience, here the complete list:
|
|
88 | 88 | *
|
89 | 89 | * LICENSE: zlib/libpng
|
90 | 90 | *
|
91 |
| -* Copyright (c) 2014-2024 Ramon Santamaria (@raysan5) |
| 91 | +* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5) |
92 | 92 | *
|
93 | 93 | * This software is provided "as-is", without any express or implied warranty. In no event
|
94 | 94 | * will the authors be held liable for any damages arising from the use of this software.
|
@@ -3666,29 +3666,37 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
3666 | 3666 | // Read screen pixel data (color buffer)
|
3667 | 3667 | unsigned char *rlReadScreenPixels(int width, int height)
|
3668 | 3668 | {
|
3669 |
| - unsigned char *screenData = (unsigned char *)RL_CALLOC(width*height*4, sizeof(unsigned char)); |
| 3669 | + unsigned char *imgData = (unsigned char *)RL_CALLOC(width*height*4, sizeof(unsigned char)); |
3670 | 3670 |
|
3671 | 3671 | // NOTE 1: glReadPixels returns image flipped vertically -> (0,0) is the bottom left corner of the framebuffer
|
3672 | 3672 | // NOTE 2: We are getting alpha channel! Be careful, it can be transparent if not cleared properly!
|
3673 |
| - glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, screenData); |
| 3673 | + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, imgData); |
3674 | 3674 |
|
3675 | 3675 | // Flip image vertically!
|
3676 |
| - unsigned char *imgData = (unsigned char *)RL_MALLOC(width*height*4*sizeof(unsigned char)); |
3677 |
| - |
3678 |
| - for (int y = height - 1; y >= 0; y--) |
| 3676 | + // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! |
| 3677 | + for (int y = height - 1; y >= height / 2; y--) |
3679 | 3678 | {
|
3680 |
| - for (int x = 0; x < (width*4); x++) |
| 3679 | + for (int x = 0; x < (width*4); x += 4) |
3681 | 3680 | {
|
3682 |
| - imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x]; // Flip line |
3683 |
| - |
3684 |
| - // Set alpha component value to 255 (no trasparent image retrieval) |
3685 |
| - // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! |
3686 |
| - if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255; |
| 3681 | + size_t s = ((height - 1) - y)*width*4 + x; |
| 3682 | + size_t e = y*width*4 + x; |
| 3683 | + |
| 3684 | + unsigned char r = imgData[s]; |
| 3685 | + unsigned char g = imgData[s+1]; |
| 3686 | + unsigned char b = imgData[s+2]; |
| 3687 | + |
| 3688 | + imgData[s] = imgData[e]; |
| 3689 | + imgData[s+1] = imgData[e+1]; |
| 3690 | + imgData[s+2] = imgData[e+2]; |
| 3691 | + imgData[s+3] = 255; // Set alpha component value to 255 (no trasparent image retrieval) |
| 3692 | + |
| 3693 | + imgData[e] = r; |
| 3694 | + imgData[e+1] = g; |
| 3695 | + imgData[e+2] = b; |
| 3696 | + imgData[e+3] = 255; // Ditto |
3687 | 3697 | }
|
3688 | 3698 | }
|
3689 | 3699 |
|
3690 |
| - RL_FREE(screenData); |
3691 |
| - |
3692 | 3700 | return imgData; // NOTE: image data should be freed
|
3693 | 3701 | }
|
3694 | 3702 |
|
|
0 commit comments