我正在研究2D Android项目,我希望使用FBO将东西绘制为空纹理,然后在屏幕上绘制该纹理.出于调试目的,FBO附加的纹理应立即变为蓝色,因此我可以编辑该纹理,因为当前它甚至不会影响该纹理.
帧缓冲区:
public static class FrameBuffer{ private final FaustEngine engine; private final int wIDth; private final int height; private final int[] fboID = new int[1]; private final int[] renID = new int[1]; public FrameBuffer( FaustEngine Engine, int WIDth, int Height ){ engine = Engine; wIDth = WIDth; height = Height; GLES20.glGenRenderbuffers( 1, renID, 0 ); GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, renID[0] ); GLES20.glrenderbufferStorage( GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT, wIDth, height ); GLES20.glGenFramebuffers( 1, fboID, 0 ); GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, fboID[0] ); GLES20.glFramebufferRenderbuffer( GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, renID[0] ); GLES20.glBindRenderbuffer( GLES20.GL_RENDERBUFFER, 0); GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, 0); } public voID bind( int texID, int texWIDth, int texHeight ){ GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, fboID[0] ); GLES20.glFramebufferTexture2D( GLES20.GL_FRAMEBUFFER, GLES20.GL_color_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texID, 0 ); GLES20.glVIEwport( 0, 0, texWIDth, texHeight ); GLES20.glClearcolor(0f, 0f, 1f, 1f ); GLES20.glClear( GLES20.GL_color_BUFFER_BIT ); //Turn blue //Fix projection matrix Matrix.orthoM( engine.getorthoMatrix() , 0, 0, texWIDth, texHeight, 0, -1, 1 ); } public voID unbind(){ GLES20.glBindFramebuffer( GLES20.GL_FRAMEBUFFER, 0 ); GLES20.glVIEwport( 0, 0, engine.getScreenWIDth(), engine.getScreenHeight() ); //@R_301_5990@ projection matrix Matrix.orthoM( engine.getorthoMatrix() , 0, 0, engine.getScreenWIDth(), engine.getScreenHeight(), 0, -1, 1 ); }}
渲染代码:
FrameBuffer fbo = new FrameBuffer( game.getEngine(), 1024, 1024 );final int[] texIDs = new int[1];game.getEngine().createBlankTextures( texIDs, 1024, 1024 );fbo.bind( texIDs[0], 1024, 1024 );//texture should turn blue here since in the bind() function I placed a glClear with bluefbo.unbind();
纹理创建:
public voID createBlankTextures( int[] texIDs, int wIDth, int height ){ GLES20.glGenTextures( texIDs.length, texIDs, 0 ); for( int i=0; i<texIDs.length; i++ ){ GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, texIDs[i] ); GLES20.glTexParameteri( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST ); GLES20.glTexParameteri( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST ); GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, wIDth, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null ); GLES20.glGenerateMipmap( GLES20.GL_TEXTURE_2D ); }}
所以我有两个问题.
1.)我需要带有帧缓冲区的渲染缓冲区吗?我不想跟踪深度.我只想编辑一个现有的纯2D纹理.
2.)为什么不起作用?
解决方法:
如果不需要FBO渲染的深度缓冲区,则无需创建渲染缓冲区.
对于ES 2.0中的glrenderbufferStorage()的internalformat参数,GL_DEPTH_COMPONENT不是有效值.如果查看支持的值(http://www.khronos.org/opengles/sdk/docs/man/xhtml/glRenderbufferStorage.xml),则唯一的深度格式是GL_DEPTH_COMPONENT16.
与往常一样,glGetError()是您的朋友.它应该从glrenderbufferStorage()调用中指示GL_INVALID_ENUM错误.
总结以上是内存溢出为你收集整理的Java-Android Opengl ES 2.0 FrameBuffer无法正常工作全部内容,希望文章能够帮你解决Java-Android Opengl ES 2.0 FrameBuffer无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)