
Render VBO in FBO, programm breaks
Posted Thursday, 17 March, 2011 - 13:01 by miujin inHi,
I have different VBOs in my scene and I want to render the scene in a FBO and than I want to render the texture on a Quad.
Rendering on the Quad works but if I have a VBO and render it the programm breaks down after or during SwapBuffer();
Has anyone an idea what the problem is?
private void PanelPaint(object sender, EventArgs e) { RenderInTexture(); GL.DrawBuffer(DrawBufferMode.Back); GL.Viewport(0, 0, m_panel.Width, m_panel.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.ClearColor(1f, .0f, 1f, 1f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.BindTexture(TextureTarget.Texture2D, m_fbo[0].FrameBufferID); GL.CallList(m_fbo[0].DisplayListID); GL.BindTexture(TextureTarget.Texture2D, 0); m_panel.SwapBuffers(); } private void RenderInTexture() { GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, m_fbo[0].FboID); RenderVBO(); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); } private void RenderVBO() { GL.Viewport(0, 0, m_panel.Width, m_panel.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.ClearColor(.7f, .7f, .7f, 1f); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); foreach (KTC_VBO vbo in m_vbo) { EnableArrays(vbo.Format); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo.V_ID); SetupPointer(vbo.Format); DrawArray(vbo); DisableArrays(vbo.Format); } } private void EnableArrays(KTC_VertexBufferFormat format) { switch (format) { case KTC_VertexBufferFormat.V3f: GL.EnableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.N3fV3f: GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.C4ubV3f: GL.EnableClientState(ArrayCap.ColorArray); GL.EnableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.C4ubN3fV3f: GL.EnableClientState(ArrayCap.ColorArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.VertexArray); break; } } private void SetupPointer(KTC_VertexBufferFormat format) { switch (format) { case KTC_VertexBufferFormat.V3f: GL.VertexPointer(3, VertexPointerType.Float, 3, 0); break; case KTC_VertexBufferFormat.N3fV3f: GL.NormalPointer(NormalPointerType.Float, 6 * sizeof(float), 0); GL.VertexPointer(3, VertexPointerType.Float, 6 * sizeof(float), (IntPtr)(3 * sizeof(float))); break; case KTC_VertexBufferFormat.C4ubV3f: GL.ColorPointer(4, ColorPointerType.Float, 7 * sizeof(float), 0); GL.VertexPointer(3, VertexPointerType.Float, 7 * sizeof(float), (IntPtr)(4 * sizeof(float))); break; case KTC_VertexBufferFormat.C4ubN3fV3f: GL.ColorPointer(4, ColorPointerType.Float, 10 * sizeof(float), IntPtr.Zero); GL.NormalPointer(NormalPointerType.Float, 10 * sizeof(float), (IntPtr)(4 * sizeof(float))); GL.VertexPointer(3, VertexPointerType.Float, 10 * sizeof(float), (IntPtr)(7 * sizeof(float))); break; } } private void DrawArray(KTC_VBO vbo) { switch (vbo.PrimtiveType) { case KTC_PrimitiveType.Point: GL.DrawArrays(BeginMode.Points, 0, vbo.ElementCount); break; case KTC_PrimitiveType.Line: GL.DrawArrays(BeginMode.Lines, 0, vbo.ElementCount); break; case KTC_PrimitiveType.Triangle: GL.DrawArrays(BeginMode.Triangles, 0, vbo.ElementCount); break; } } private void DisableArrays(KTC_VertexBufferFormat format) { switch (format) { case KTC_VertexBufferFormat.V3f: GL.DisableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.N3fV3f: GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.C4ubV3f: GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.VertexArray); break; case KTC_VertexBufferFormat.C4ubN3fV3f: GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.VertexArray); break; } }

