Я новичок в opengl и изо всех сил пытаюсь заставить работать трафаретный буфер для простого случая;
У меня есть две текстуры, одна из которых является растровым изображением, а другая - «маской», с помощью которой я пытаюсь скрыть некоторые части из растрового изображения.
Я не могу заставить это работать, когда я пытаюсь установить формат трафарета при создании моей текстуры трафарета с помощью 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);
Кажется, я не могу найти примеров, демонстрирующих это для простого двумерного случая (маскирование текстур с использованием текстур).
EDIT:
Обновленная версия здесь: http://pastebin.com/iuur2UTM