From ab01cd45bcea6942e3ba62fd32996b374de7e1c9 Mon Sep 17 00:00:00 2001 From: Ray San Date: Wed, 25 Oct 2017 12:46:26 +0200 Subject: [PATCH] Review rlReadTexturePixels() Improve second option to retrieve texture data from fbo... Still requires some testing... --- src/rlgl.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/rlgl.c b/src/rlgl.c index 6f82a84c7..35c812a6e 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -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; + 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)); - DrawModel(quad, (Vector3){ 0.0f, 0.0f, 0.0f }, 1.0f, WHITE); - - pixels = (unsigned char *)malloc(texture.width*texture.height*3*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