我是新来的opengl,我努力让stencilbuffer工作的一个简单的情况; 我有两个纹理,一个是位图,一个是“掩膜”,我试图从位图中隐藏一些部分。OpenTK模板缓冲区
我似乎无法得到这个工作,当我尝试使用GL.TexImage2D创建我的模具纹理时设置模板格式我得到一个无效的枚举,并且当我尝试将一个stencilextension附加到FramebufferTexture2D FBO我画我的面具在:
GL.Enable(EnableCap.StencilTest);
GL.ClearStencil(0);
GL.StencilMask(0xFFFFFFFF); // read&write
// Create stencil texture
GL.GenTextures(1, out stencilTexture);
GL.BindTexture(TextureTarget.Texture2D, stencilTexture);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, stencilTextureWidth, stencilTextureHeight, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
//DOES NOT WORK: GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.StencilIndex, stencilTextureWidth, stencilTextureHeight, 0, OpenTK.Graphics.OpenGL.PixelFormat.StencilIndex, PixelType.UnsignedByte, IntPtr.Zero);
CREATE COLORTEXTURE FROM BITMAP
// Create a FBO and attach the stencil texture
GL.Ext.GenFramebuffers(1, out fbo);
GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fbo);
GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, stencilTexture, 0);
//DOES NOT WORK?: GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.StencilAttachmentExt, TextureTarget.Texture2D, stencilTexture, 0);
DRAW SOME STUFF INTO THE STENCILTEXTURE TO FUNCTION AS A MASK
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);
DRAW COLOR TEXTURE
GL.Enable(EnableCap.StencilTest);
GL.ClearStencil(0);
GL.ColorMask(false, false, false, false);
GL.StencilFunc(StencilFunction.Always, 1, 1);
GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace);
DRAW THE STENCIL TEXTURE
GL.Disable(EnableCap.StencilTest);
我似乎无法找到证明这一点的一个简单的2D情况下(掩蔽使用纹理贴图)的任何实例。
编辑: 更新版本在这里:http://pastebin.com/iuur2UTM
这是一个非常多的代码。你能否让问题更具体? – 2012-02-23 09:37:04
对不起,我提供了整个示例,以便它可以运行,因为我不确定问题出在哪里......我编辑了原始帖子以仅包含相关部分,并链接了应该编译的完整源代码。 – Martijnh 2012-02-23 13:40:24
为什么投下来,只是因为他提供了很多代码?在阅读了很多问题后,很高兴看到人们花时间和精力解决问题并提供他们所拥有的东西。找到一个合适的答案。我讨厌添加一个评论,总是像“请张贴你的画图方法”等。这是defintely不是一个值得downvoting的问题。 – dowhilefor 2012-02-23 16:20:29