diff options
| author | Ray San <raysan5@gmail.com> | 2017-10-25 12:46:26 +0200 |
|---|---|---|
| committer | Ray San <raysan5@gmail.com> | 2017-10-25 12:46:26 +0200 |
| commit | ab01cd45bcea6942e3ba62fd32996b374de7e1c9 (patch) | |
| tree | 577d066d880513301a7de637bb106511e9d11374 /src | |
| parent | 31c8c86d8e9efabd44166540a1de06d7a39d34b2 (diff) | |
| download | raylib-ab01cd45bcea6942e3ba62fd32996b374de7e1c9.tar.gz raylib-ab01cd45bcea6942e3ba62fd32996b374de7e1c9.zip | |
Review rlReadTexturePixels()
Improve second option to retrieve texture data from fbo...
Still requires some testing...
Diffstat (limited to 'src')
| -rw-r--r-- | src/rlgl.c | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -2222,32 +2222,30 @@ void *rlReadTexturePixels(Texture2D texture) glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepthf(1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, width, height); - //glMatrixMode(GL_PROJECTION); - //glLoadIdentity(); - rlOrtho(0.0, width, height, 0.0, 0.0, 1.0); - //glMatrixMode(GL_MODELVIEW); - //glLoadIdentity(); //glDisable(GL_TEXTURE_2D); - //glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); + //glDisable(GL_BLEND); + + glViewport(0, 0, width, height); + rlOrtho(0.0, width, height, 0.0, 0.0, 1.0); - Model quad; - //quad.mesh = GenMeshQuad(width, height); - quad.transform = MatrixIdentity(); - quad.shader = defaultShader; - - DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE); - - pixels = (unsigned char *)malloc(texture.width*texture.height*3*sizeof(unsigned char)); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glUseProgram(GetShaderDefault().id); + glBindTexture(GL_TEXTURE_2D, texture.id); + GenDrawQuad(); + glBindTexture(GL_TEXTURE_2D, 0); + glUseProgram(0); + + pixels = (unsigned char *)malloc(texture.width*texture.height*4*sizeof(unsigned char)); - glReadPixels(0, 0, texture.width, texture.height, GL_RGB, GL_UNSIGNED_BYTE, pixels); + glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Bind framebuffer 0, which means render to back buffer glBindFramebuffer(GL_FRAMEBUFFER, 0); - - UnloadModel(quad); + + // Reset viewport dimensions to default + glViewport(0, 0, screenWidth, screenHeight); + #endif // GET_TEXTURE_FBO_OPTION // Clean up temporal fbo |
