
FBO and MonoTouch/iPhone
Posted Tuesday, 6 March, 2012 - 13:28 by otkmt inHello,
New to OpenTK. I have been trying to do simple render-to-texture using a fbo with no luck. All I get is a blank pink screen. Please take a look and let me know if there is an obvious mistake? Thank you!
btw. I have the same technique working with OpenGL (not ES)
using System; using OpenTK.Graphics.ES11; namespace gl { public class OffScreenRenderer { uint offscreenTexture; uint FBOHandle; int textureSize = 128; public void PrepareOffscreenBuffer() { // Create Texture GL.GenTextures(1, ref offscreenTexture); GL.BindTexture(All.Texture2D, offscreenTexture); GL.TexParameter(All.Texture2D, All.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear); GL.TexParameter(All.Texture2D, All.TextureMagFilter, (int) TextureMagFilter.Linear); GL.TexImage2D(All.Texture2D, 0, (int) All.Rgba, textureSize, textureSize, 0, All.Rgba, All.UnsignedByte, IntPtr.Zero); // Create a FBO and attach the texture GL.Oes.GenFramebuffers(1, ref FBOHandle); GL.Oes.BindFramebuffer(All.FramebufferOes, FBOHandle); GL.Oes.FramebufferTexture2D(All.FramebufferOes, All.ColorAttachment0Oes, All.Texture2D, offscreenTexture, 0); // unbind frame buffer GL.Oes.BindFramebuffer(All.FramebufferOes, 0); GL.BindTexture(All.Texture2D, 0); } public void BindOffscreenBuffer() { GL.BindTexture(All.Texture2D, 0); GL.Oes.BindFramebuffer(All.FramebufferOes, FBOHandle); GL.Viewport(0, 0, textureSize, textureSize); } public void UnBindOffscreenBuffer() { GL.Oes.BindFramebuffer(All.FramebufferOes, 0); GL.BindTexture(All.Texture2D, offscreenTexture); GL.Viewport(0, 0, 320, 240); } public void ShowOffcreenBuffer() { GL.Enable(All.Texture2D); // Render offsreen textrure to a quad GL.EnableClientState(All.VertexArray); GL.EnableClientState(All.TextureCoordArray); GL.VertexPointer(2, All.Float, 0, vertexArray); GL.TexCoordPointer(2, All.Float, 0, textureArray); GL.DrawArrays(All.TriangleStrip, 0, 4); } // float[] vertexArray = new float[]{ -0.7f, -1.0f, 1.0f, -1.0f, -0.7f, 1.0f, 1.0f, 1.0f }; float[] textureArray = new float[]{ 1, 1, 0, 1, 1, 0, 0, 0 }; } }

