FrameBuffer to file inside libgdx or OpenGL

孤者浪人 提交于 2019-12-11 01:16:57

问题


I am trying to take screenshots in the most efficient way. I thing using a FrameBuffer is the most efficient way of taking screenshots because i can process the data in different thread than rendering thread. How can i get the information from FrameBUffer and transfer it to a file?

FrameBuffer m_fbo;

render(){
   m_fbo = new FrameBuffer(Format.RGB565, (int)(w * m_fboScaler), (int)(h * m_fboScaler), false);
   m_fboRegion = new TextureRegion(m_fbo.getColorBufferTexture());
   m_fboRegion.flip(false, true);
   m_fbo.begin();
   ...rendering...
   m_fbo.end();
   writeTextureRegionToFile(); - i need some lines of code for the implementation of this method
}

回答1:


The FrameBuffer contents reside in memory managed by OpenGL, so you will (as far as I understand things) still need to fetch those bytes using OpenGL APIs on the render thread. Specifically, you want the ScreenUtils class to get a byte[] containing the RGBA8888 contents of your FrameBuffer.

Once you get the raw bytes, you can do any compression/conversion/output on a different thread, of course. There is a forum post that has a quick and dirty PNG writer. The Libgdx-specific (?) CIM format is also an option (see the PixmapIO class), but you'll have to convert the bytes into a Pixmap first.



来源:https://stackoverflow.com/questions/15828879/framebuffer-to-file-inside-libgdx-or-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!