Jump to content
  • Advertisement
Sign in to follow this  
iliak

[C# & OpenTK] RenderBuffer

This topic is 3415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

RenderBuffer probleme Hello, For my 2d framework (C# & openTK), I want to use RenderBuffer. Here's the class :
public class RenderBuffer
{
	/// <summary>
	/// 
	/// </summary>
	/// <param name="size"></param>
	public RenderBuffer(Size size)
	{
		Size = size;


		GL.Enable(EnableCap.DepthTest);
		GL.ClearDepth(1.0f);
		GL.DepthFunc(DepthFunction.Lequal);

		GL.Disable(EnableCap.CullFace);
		GL.PolygonMode(MaterialFace.Back, PolygonMode.Line);

		// Create Color Tex
		ColorTexture = new Texture(size);

		// Create Depth Tex
		DepthTexture = new Texture(size);
		GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.DepthComponent32, size.Width, size.Height, 0, PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);


		// Create a FBO and attach the textures
		GL.Ext.GenFramebuffers(1, out FBOHandle);
		GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FBOHandle);
		GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, ColorTexture.Handle, 0);
		GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, DepthTexture.Handle, 0);



		End();
	}


	/// <summary>
	/// 
	/// </summary>
	~RenderBuffer()
	{
		//if (ColorTexture != null)
		//   ColorTexture = null;

		//if (DepthTexture != 0)
		//   GL.DeleteTextures(1, ref DepthTexture);

		//if (FBOHandle != 0)
		//   GL.Ext.DeleteFramebuffers(1, ref FBOHandle);
	}


	/// <summary>
	/// "Binding" the render buffer
	/// </summary>
	public void Start()
	{
		GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FBOHandle);

		GL.PushAttrib(AttribMask.ViewportBit);
		GL.Viewport(0, 0, Size.Width, Size.Height);

		GL.MatrixMode(MatrixMode.Projection);
		GL.PushMatrix();
		GL.LoadIdentity();
		
		//
		// screen_1
		//
		GL.Ortho(0, Size.Width, Size.Height, 0, -1, 1);
		
		
		//
		// screen_2
		//
		//GL.Ortho(0, Size.Width, 0, Size.Height, -1, 1);
	}



	/// <summary>
	/// "Release" the render buffer
	/// </summary>
	public void End()
	{
		GL.MatrixMode(MatrixMode.Projection);
		GL.PopMatrix();

		GL.PopAttrib();
		GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
	}



	#region Properties


	/// <summary>
	/// 
	/// </summary>
	uint FBOHandle;



	/// <summary>
	/// Size of the FrameBuffer
	/// </summary>
	public Size Size
	{
		get;
		private set;
	}


	/// <summary>
	/// 
	/// </summary>
	public Texture ColorTexture
	{
		get;
		private set;
	}



	/// <summary>
	/// 
	/// </summary>
	public Texture DepthTexture
	{
		get;
		private set;
	}
	
	#endregion

}


The expected result is a white filled rectangle at (1,1 x 10,10) (at top left). In the RenderBuffer::Start(), if I use GL.Ortho(0, Size.Width, Size.Height, 0, -1, 1) here's the result : If I use GL.Ortho(0, Size.Width, 0, Size.Height, -1, 1), here's the result : In the first case, the output is good but Y inverted, in the second case, rendering is well ordered but everything is rendered in wire mode.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!