C# 为什么我要得到一个带帧缓冲区的白色正方形?
我正在尝试将帧缓冲区的使用添加到我的OpenGL(OpenTK)项目中 在我一开始添加的初始化方法中: this.RenderBufferTex=GL.GenTexture()C# 为什么我要得到一个带帧缓冲区的白色正方形?,c#,opengl,framebuffer,opentk,C#,Opengl,Framebuffer,Opentk,我正在尝试将帧缓冲区的使用添加到我的OpenGL(OpenTK)项目中 在我一开始添加的初始化方法中: this.RenderBufferTex=GL.GenTexture() this.glc是场景运行的glc控件 在渲染之前,我添加了 GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.Buffer); 然后是GL.Clear()和所有用于绘制场景的旧代码 然后是显示渲染场景的方法: GL.BindFramebuffer(Frame
this.glc
是场景运行的glc控件
在渲染之前,我添加了
GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.Buffer);
然后是GL.Clear()和所有用于绘制场景的旧代码
然后是显示渲染场景的方法:
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.LineSmooth);
GL.Disable(EnableCap.PointSmooth);
GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
GL.Ortho(0.0, (double)this.glc.Width, 0.0, (double)this.glc.Height, 0.0, 10000.0);
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
GL.BindTexture(TextureTarget.Texture2D, this.BufferTex);
GL.Begin(BeginMode.Quads);
GL.TexCoord2(0, 0);
GL.Vertex2(0, 0);
GL.TexCoord2(1, 0);
GL.Vertex2(this.glc.Height, 0);
GL.TexCoord2(1, 1);
GL.Vertex2(this.glc.Height, this.glc.Width);
GL.TexCoord2(0, 1);
GL.Vertex2(0, this.glc.Width);
GL.End();
GL.PopMatrix();
GL.MatrixMode(MatrixMode.Projection);
GL.PopMatrix();
GL.Enable(EnableCap.DepthTest);
this.glc.SwapBuffers();
我从中得到的结果是一个白色的正方形填充了我屏幕的左侧(因此从我的屏幕高度看它似乎是正方形)
我做错了什么?您需要将纹理的GL\u minu\u过滤器和GL\u MAG\u过滤器设置为合理的值,如GL\u LINEAR或GL\u NEAREST,默认值使用mipmap,这会使纹理不完整。还有一个问题:如何更改帧缓冲区分辨率?@Cobra\u Fast您应该提出另一个问题。
GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.LineSmooth);
GL.Disable(EnableCap.PointSmooth);
GL.MatrixMode(MatrixMode.Projection);
GL.PushMatrix();
GL.LoadIdentity();
GL.Ortho(0.0, (double)this.glc.Width, 0.0, (double)this.glc.Height, 0.0, 10000.0);
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
GL.BindTexture(TextureTarget.Texture2D, this.BufferTex);
GL.Begin(BeginMode.Quads);
GL.TexCoord2(0, 0);
GL.Vertex2(0, 0);
GL.TexCoord2(1, 0);
GL.Vertex2(this.glc.Height, 0);
GL.TexCoord2(1, 1);
GL.Vertex2(this.glc.Height, this.glc.Width);
GL.TexCoord2(0, 1);
GL.Vertex2(0, this.glc.Width);
GL.End();
GL.PopMatrix();
GL.MatrixMode(MatrixMode.Projection);
GL.PopMatrix();
GL.Enable(EnableCap.DepthTest);
this.glc.SwapBuffers();