public static FrameBuffer Create(int width, int height, IGraphicsContext context)
        {
            int textureHandle = context.GenTexture();

            context.BindTexture(TextureTarget.Texture2D, textureHandle);

            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, false, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)null);

            var texture = new Texture2D(context, textureHandle, width, height);

            int handle;

            context.GenFrameBuffers(1, out handle);
            context.BindFrameBuffer(FramebufferTarget.Framebuffer, handle);

            context.FrameBufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, textureHandle, 0);

            context.BindFrameBuffer(FramebufferTarget.Framebuffer, 0);
            return(new FrameBuffer(handle, texture));
        }
Beispiel #2
0
        public override Texture2D Process(Bitmap bitmap, IResourceContext context)
        {
            BitmapData       data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, Format);
            IGraphicsContext gc   = context.Locator.GetService <IGraphicsContext>();


            int id = gc.GenTexture();

            gc.BindTexture(TextureTarget.Texture2D, id);

            gc.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, false,
                          OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            bitmap.UnlockBits(data);

            //gc.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            gc.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);


            bitmap.Dispose();

            Console.WriteLine(GC.GetTotalMemory(true));

            return(new Texture2D(gc, id, data.Width, data.Height));
        }
        public void BindTexture(TextureTarget target, int id)
        {
            forwarding.BindTexture(target, id);
            CheckGLError();


            GLCALLS++;
        }
Beispiel #4
0
        public static Texture2D LoadTexture(IGraphicsContext context, Stream stream)
        {
            Bitmap     bitmap = new Bitmap(stream);
            BitmapData data   = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

            int id = context.GenTexture();

            context.BindTexture(TextureTarget.Texture2D, id);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, false,
                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            bitmap.UnlockBits(data);

            context.GenerateMipmap(GenerateMipmapTarget.Texture2D);

            return(new Texture2D(context, id, data.Width, data.Height));
        }
        public static FrameBuffer Create(int width, int height, IGraphicsContext context)
        {
            int textureHandle = context.GenTexture();
            context.BindTexture(TextureTarget.Texture2D, textureHandle);

            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            context.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            context.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, false, PixelFormat.Bgra, PixelType.UnsignedByte, (IntPtr)null);

            var texture = new Texture2D(context, textureHandle, width, height);

            int handle;
            context.GenFrameBuffers(1, out handle);
            context.BindFrameBuffer(FramebufferTarget.Framebuffer, handle);

            context.FrameBufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, textureHandle, 0);

            context.BindFrameBuffer(FramebufferTarget.Framebuffer, 0);
            return new FrameBuffer(handle, texture);
        }