0

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

これから得られる結果は、画面の左側を埋める白い正方形です(したがって、画面の高さからは正方形に見えます)。

私は何が間違っているのですか?

4

1 に答える 1

2

テクスチャのGL_MIN_FILTERとGL_MAG_FILTERをGL_LINEARやGL_NEARESTのような妥当なものに設定する必要があります。デフォルトではミップマップが使用されるため、テクスチャが不完全になります。

于 2011-03-06T19:04:24.997 に答える