Alternatively my code is below if someone is able to see the problem.
My working VBO render (renders my world as expected):
protected override void OnRenderFrame_VBO(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// Camera.
Matrix4 lookat = Matrix4.LookAt(this.Camera, this.Target, this.LocalUp);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
GL.Viewport(0, 0, this.Width, this.Height);
double aspect_ratio = this.Width / (double)this.Height;
OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(fov, (float)aspect_ratio, 1, 25000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref perspective);
// Colour Array.
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers.ColoursBufferId);
GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(int), IntPtr.Zero);
GL.EnableClientState(ArrayCap.ColorArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
// Vertex Data Array.
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers.VertexDataArrayBufferId);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(world.Vertices.Length * Vector3.SizeInBytes), world.Vertices, BufferUsageHint.StreamDraw);
GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
GL.EnableClientState(ArrayCap.VertexArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
// Index Array.
GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffers.ElementIndicesBufferId);
GL.DrawElements(BeginMode.Triangles, world.Indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);
this.SwapBuffers();
}
And my FBO code which is not working (renders all red):
public static void OnLoad(EventArgs e)
{
<<Working VBO creation logic here>>
// Create Color Tex
GL.GenTextures(1, out buffers.ColourTexture);
GL.BindTexture(TextureTarget.Texture2D, buffers.ColourTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, this.OffscreenFBOWidth, this.OffscreenFBOHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
// GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
// Create a FBO and attach the textures
GL.Ext.GenFramebuffers(1, out buffers.FBOHandle);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, buffers.FBOHandle);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, buffers.ColourTexture, 0);
if (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt) != FramebufferErrorCode.FramebufferCompleteExt)
{
throw new Exception(GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt).ToString());
}
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
GL.BindTexture(TextureTarget.Texture2D, 0);
}
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// Camera.
Matrix4 lookat = Matrix4.LookAt(this.Camera, this.Target, this.LocalUp);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref lookat);
GL.Viewport(0, 0, this.OffscreenFBOWidth, this.OffscreenFBOHeight);
double aspect_ratio = Width / (double)Height;
OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(fov, (float)aspect_ratio, 1, 25000);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref perspective);
// Bind FBO.
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, buffers.FBOHandle);
GL.ClearColor(0f, 0f, .7f, 0f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// Render VBO.
// Colour Array.
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers.ColoursBufferId);
GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(int), IntPtr.Zero);
GL.EnableClientState(ArrayCap.ColorArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
// Vertex Data Array.
GL.BindBuffer(BufferTarget.ArrayBuffer, buffers.VertexDataArrayBufferId);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(world.Vertices.Length * Vector3.SizeInBytes), world.Vertices, BufferUsageHint.StreamDraw);
GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);
GL.EnableClientState(ArrayCap.VertexArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
// Index Array.
GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffers.ElementIndicesBufferId);
GL.DrawElements(BeginMode.Triangles, world.Indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
GL.ClearColor(.4f, 0f, 0f, 0f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, 0);
GL.PushMatrix();
{
GL.Translate(-1.1f, 0f, 0f);
GL.BindTexture(TextureTarget.Texture2D, buffers.ColourTexture);
GL.Begin(BeginMode.Quads);
{
GL.TexCoord2(0f, 1f);
GL.Vertex2(-1.0f, 1.0f);
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(-1.0f, -1.0f);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex2(1.0f, 1.0f);
}
GL.End();
}
GL.PopMatrix();
this.SwapBuffers();
}
I’ll take any pointers…