TexImage1D() private method

private TexImage1D ( uint target, int level, uint internalformat, int width, int border, uint format, uint type, IntPtr pixels ) : void
target uint
level int
internalformat uint
width int
border int
format uint
type uint
pixels IntPtr
return void
Ejemplo n.º 1
0
        /// <summary>
        /// upadte texture's content.
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="bitmap"></param>
        public static void UpdateContent(this Texture texture, Bitmap bitmap)
        {
            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            OpenGL.BindTexture((uint)texture.Target, texture.Id);
            if (texture.Target == TextureTarget.Texture1D)
            {
                OpenGL.TexImage1D((uint)texture.Target, 0, (int)OpenGL.GL_RGBA, bitmapData.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
            }
            else if (texture.Target == TextureTarget.Texture2D)
            {
                OpenGL.TexImage2D((uint)texture.Target, 0, (int)OpenGL.GL_RGBA, bitmapData.Width, bitmapData.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
            }
            else
            {
                throw new NotImplementedException();
            }
            OpenGL.BindTexture((uint)texture.Target, 0);

            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);

            //// TODO: TexSubImage2D() do not work. why?
            //BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
            //    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            //OpenGL.BindTexture(this.Target, this.Id);
            //OpenGL.TexSubImage2D(this.Target, 0, 0, 0, bitmap.Width, bitmap.Height, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
            //OpenGL.TexSubImage2D(TexSubImage2DTarget.Texture2D, 0, 0, 0, bitmap.Width, bitmap.Height, TexSubImage2DFormats.RGBA, TexSubImage2DType.UnsignedByte, bitmapData.Scan0);
            //OpenGL.BindTexture(this.Target, 0);
            //bitmap.UnlockBits(bitmapData);
        }
Ejemplo n.º 2
0
        private void DoInitialize(System.Drawing.Bitmap bitmap)
        {
            // generate texture.
            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            //GL.ActiveTexture(GL.GL_TEXTURE0);
            OpenGL.GetDelegateFor <OpenGL.glActiveTexture>()(OpenGL.GL_TEXTURE0);
            OpenGL.GenTextures(1, id);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_1D, id[0]);
            /* We require 1 byte alignment when uploading texture data */
            //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
            /* Clamping to edges is important to prevent artifacts when scaling */
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_1D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_1D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
            /* Linear filtering usually looks best for text */
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_1D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_1D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexImage1D(OpenGL.GL_TEXTURE_1D, 0, OpenGL.GL_RGBA,
                              bitmap.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                              bitmapData.Scan0);
            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_1D, 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// build texture's content with Bitmap.
        /// </summary>
        public override void Fill()
        {
            // generate texture.
            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            if (target == TextureTarget.Texture1D)
            {
                OpenGL.TexImage1D((uint)target, 0, this.internalformat, bitmap.Width, 0, this.format, this.type, bitmapData.Scan0);
            }
            else if (target == TextureTarget.Texture2D)
            {
                OpenGL.TexImage2D((uint)target, 0, this.internalformat, bitmap.Width, bitmap.Height, 0, this.format, this.type, bitmapData.Scan0);
            }
            else
            {
                throw new NotImplementedException();
            }

            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// build texture's content with Bitmap.
        /// </summary>
        public override void Build(BindTextureTarget target)
        {
            // generate texture.
            //  Lock the image bits (so that we can pass them to OGL).
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            if (target == BindTextureTarget.Texture1D)
            {
                OpenGL.TexImage1D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
            }
            else if (target == BindTextureTarget.Texture2D)
            {
                OpenGL.TexImage2D((uint)target, 0, (int)OpenGL.GL_RGBA, bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE, bitmapData.Scan0);
            }
            else
            {
                throw new NotImplementedException();
            }

            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// build texture's content with Bitmap.
        /// </summary>
        public override void Fill()
        {
            // generate texture.
            if (target == TextureTarget.Texture1D)
            {
                Bitmap bmp = null;
                for (int level = 0; level <= this.maxLevel; level++)
                {
                    if (level == 0)
                    {
                        bmp = this.bitmap;
                    }
                    else
                    {
                        bmp.Dispose();
                        int width = bmp.Width / 2;
                        if (width < 1)
                        {
                            width = 1;
                        }
                        bmp = new Bitmap(bmp, width, 1);
                    }
                    //  Lock the image bits (so that we can pass them to OGL).
                    BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                         ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    OpenGL.TexImage1D((uint)target, level, this.internalformat, bitmap.Width, 0, this.format, this.type, bitmapData.Scan0);
                    //  Unlock the image.
                    bmp.UnlockBits(bitmapData);
                }

                if (bmp != this.bitmap)
                {
                    bmp.Dispose();
                }
            }
            else if (target == TextureTarget.Texture2D)
            {
                Bitmap bmp = null;
                for (int level = 0; level <= this.maxLevel; level++)
                {
                    if (level == 0)
                    {
                        bmp = this.bitmap;
                    }
                    else
                    {
                        bmp.Dispose();
                        int width = bmp.Width / 2, height = bmp.Height / 2;
                        if (width < 1)
                        {
                            width = 1;
                        }
                        if (height < 1)
                        {
                            height = 1;
                        }
                        bmp = new Bitmap(bmp, width, height);
                    }
                    //  Lock the image bits (so that we can pass them to OGL).
                    BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                                         ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    OpenGL.TexImage2D((uint)target, level, this.internalformat, bmp.Width, bmp.Height, 0, this.format, this.type, bitmapData.Scan0);
                    //  Unlock the image.
                    bmp.UnlockBits(bitmapData);
                }

                if (bmp != this.bitmap)
                {
                    bmp.Dispose();
                }
            }
            else
            {
                throw new Exception("Unexpected TextureTarget type!");
            }
        }