我是新來的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