【问题标题】:Why do I get a white square with a Framebuffer?为什么我会得到一个带有帧缓冲区的白色方块?
【发布时间】:2011-03-06 18:39:49
【问题描述】:

我正在尝试将帧缓冲区的使用添加到我的 OpenGL (OpenTK) 项目中。

进入我一开始添加的初始化方法: this.RenderBufferTex = GL.GenTexture();

GL.BindTexture(TextureTarget.Texture2D, this.BufferTex);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, this.glc.Width, this.glc.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
GL.BindTexture(TextureTarget.Texture2D, 0);

GL.GenFramebuffers(1, out this.Buffer);
GL.BindFramebuffer(FramebufferTarget.FramebufferExt, this.Buffer);
GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, this.BufferTex, 0);

this.glc 是场景运行所在的 GLControl。

在渲染之前我添加了

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();

我从中得到的结果是一个白色方块填充了我的屏幕左侧(因此从我的屏幕高度看它似乎是正方形)。

我做错了什么?

【问题讨论】:

    标签: c# opengl framebuffer opentk


    【解决方案1】:

    您需要将纹理的 GL_MIN_FILTER 和 GL_MAG_FILTER 设置为合理的值,例如 GL_LINEAR 或 GL_NEAREST,默认使用 mipmap,这会使纹理不完整。

    【讨论】:

    • 还有一个:如何更改帧缓冲分辨率?
    • @Cobra_Fast 你应该为此提出另一个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 2021-03-09
    • 1970-01-01
    相关资源
    最近更新 更多