예제 #1
0
        public RenderTexture(int width, int height, RenderTextureShader renderTextureShader)
            : this()
        {
            _width = width;
            _height = height;
            Shader = new Common.Shaders.DefaultRenderTextureShader();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FrameBuffer);

            _color.Width = width;
            _color.Height = height;
            GL.BindTexture(TextureTarget.Texture2D, _color.TextureId);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, width, height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, IntPtr.Zero); // TODO: transparent rendertextures?
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Linear);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, _color.TextureId, 0);

            _depth.Width = width;
            _depth.Height = height;
            GL.BindTexture(TextureTarget.Texture2D, _depth.TextureId);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, width, height, 0, OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Linear);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, _depth.TextureId, 0);

            GL.BindTexture(TextureTarget.Texture2D, 0);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
        }
예제 #2
0
 public RenderTextureMesh(RenderTextureShader shader)
     : base(RenderTextureVertices, RenderTextureTextureCoordinates, new float[0], RenderTextureIndices, shader)
 {
 }