Review rlReadTexturePixels()

Improve second option to retrieve texture data from fbo...

Still requires some testing...
This commit is contained in:
Ray San 2017-10-25 12:46:26 +02:00
parent 31c8c86d8e
commit ab01cd45bc

View File

@ -2222,32 +2222,30 @@ void *rlReadTexturePixels(Texture2D texture)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepthf(1.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_TEXTURE_2D);
//glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST); 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; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//quad.mesh = GenMeshQuad(width, height); glUseProgram(GetShaderDefault().id);
quad.transform = MatrixIdentity(); glBindTexture(GL_TEXTURE_2D, texture.id);
quad.shader = defaultShader; 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); glReadPixels(0, 0, texture.width, texture.height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
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);
// Bind framebuffer 0, which means render to back buffer // Bind framebuffer 0, which means render to back buffer
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
UnloadModel(quad); // Reset viewport dimensions to default
glViewport(0, 0, screenWidth, screenHeight);
#endif // GET_TEXTURE_FBO_OPTION #endif // GET_TEXTURE_FBO_OPTION
// Clean up temporal fbo // Clean up temporal fbo