gpt4 book ai didi

c# - OpenTK 模板缓冲区

转载 作者:太空宇宙 更新时间:2023-11-03 14:05:30 34 4
gpt4 key购买 nike

我是 opengl 的新手,我正在努力让 stencilbuffer 为一个简单的案例工作;我有两种纹理,一种是位图,另一种是“ mask ”,我试图用它来隐藏位图中的某些部分。

我似乎无法让它工作,当我尝试设置模板格式以使用 GL.TexImage2D 创建我的模板纹理时,我得到一个无效的枚举,当我尝试将模板扩展附加到 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 情况(使用纹理 mask 纹理),我似乎找不到任何示例来证明这一点。

编辑:此处更新版本:http://pastebin.com/iuur2UTM

最佳答案

您无法渲染到 FBO 并期望模板操作正常工作,除非您实际上将带有模板的缓冲区附加到它。 FBO 只有您给它们的缓冲区。

由于您使用的是 FBO 的 EXT 版本,因此必须检查 EXT_packed_depth_stencil 是否存在扩大。如果存在,那么您可以执行以下操作(注意:这是 C。您必须将其转换为 OpenTK 和 C# 代码):

GLuint renderBuffer;
glGenRenderbuffers(1, &renderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_EXT, stencilTextureWidth, stencilTextureHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER, renderBuffer);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER, renderBuffer);

这应该有所帮助。

关于c# - OpenTK 模板缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9410293/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com