2011-03-06 16 views
0

OpenGL(OpenTK)プロジェクトにFramebuffersの使用を追加しようとしています。なぜフレームバッファで白い四角形が得られますか?

私は最初のところに追加しました: 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は私がシーンを描画するためのGL.Clear続い

GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.Buffer); 

()とすべての私の古いコードを追加してレンダリングする前にGLControlシーンが実行されている。

です。

そして、レンダリングされたシーンを表示するための方法:

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

は、私はここから取得しています結果は、私の画面の左部分を(充填白い正方形であるので、私の画面の高さから正方形のように見えます)。

私は間違っていますか?

答えて

2

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

+0

もう1つ:フレームバッファの解像度を変更するにはどうすればよいですか? –

+1

@Cobra_Fast別の質問をする必要があります。 –

関連する問題