GenTextures() private method

private GenTextures ( int n, uint textures ) : void
n int
textures uint
return void
Exemplo n.º 1
0
        private void InitTexture(Bitmap bitmap)
        {
#if DEBUG
            var filename = string.Format("FontResource{0:yyyy-MM-dd_HH-mm-ss.ff}FontResource.log.bmp", DateTime.Now);
            bitmap.Save(filename);
#endif
            // 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.Format24bppRgb);
            //GL.ActiveTexture(GL.GL_TEXTURE0);
            OpenGL.GetDelegateFor <OpenGL.glActiveTexture>()(OpenGL.GL_TEXTURE0);
            var ids = new uint[1];
            OpenGL.GenTextures(1, ids);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, ids[0]);
            /* Clamping to edges is important to prevent artifacts when scaling */
            /* We require 1 byte alignment when uploading texture data */
            //GL.PixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
            /* Linear filtering usually looks best for text */
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RED,
                              bitmap.Width, bitmap.Height, 0, OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE,
                              bitmapData.Scan0);
            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
            this.TextureSize   = bitmap.Size;
            this.FontTextureId = ids[0];
        }
Exemplo 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_2D, 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_2D, OpenGL.GL_TEXTURE_WRAP_S, (int)OpenGL.GL_CLAMP_TO_EDGE);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_WRAP_T, (int)OpenGL.GL_CLAMP_TO_EDGE);
            /* Linear filtering usually looks best for text */
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR);
            OpenGL.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA,
                              bitmap.Width, bitmap.Height, 0, OpenGL.GL_BGRA, OpenGL.GL_UNSIGNED_BYTE,
                              bitmapData.Scan0);
            //  Unlock the image.
            bitmap.UnlockBits(bitmapData);
            OpenGL.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
        }
Exemplo n.º 3
0
 /// <summary>
 /// resources(bitmap etc.) can be disposed  after this initialization.
 /// </summary>
 public void Initialize()
 {
     if (!this.initialized)
     {
         glActiveTexture(this.ActiveTextureIndex + OpenGL.GL_TEXTURE0);
         OpenGL.GenTextures(1, id);
         TextureTarget target = this.Target;
         OpenGL.BindTexture(target, id[0]);
         this.Sampler.Bind(this.ActiveTextureIndex, target);
         this.ImageFiller.Fill();
         //OpenGL.GenerateMipmap((MipmapTarget)((uint)target));// TODO: does this work?
         //this.SamplerBuilder.Unbind(OpenGL.GL_TEXTURE0 - OpenGL.GL_TEXTURE0, this.Target);
         OpenGL.BindTexture(this.Target, 0);
         this.initialized = true;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// resources(bitmap etc.) can be disposed  after this initialization.
 /// </summary>
 public void Initialize()
 {
     if (!this.initialized)
     {
         //GL.ActiveTexture(GL.GL_TEXTURE0);
         OpenGL.GetDelegateFor <OpenGL.glActiveTexture>()(this.ActiveTexture);
         OpenGL.GenTextures(1, id);
         OpenGL.BindTexture(this.Target, id[0]);
         this.SamplerBuilder.Bind(this.ActiveTexture - OpenGL.GL_TEXTURE0, this.Target);
         this.ImageBuilder.Build(this.Target);
         OpenGL.GenerateMipmap((MipmapTarget)((uint)this.Target));// TODO: does this work?
         //this.SamplerBuilder.Unbind(OpenGL.GL_TEXTURE0 - OpenGL.GL_TEXTURE0, this.Target);
         OpenGL.BindTexture(this.Target, 0);
         this.initialized = true;
     }
 }
Exemplo n.º 5
0
        public void setFormat(uint internalfmt, int width, int height, uint format,
                              bool mipmap, bool interpol)
        {
            m_width          = width;
            m_height         = height;
            m_internalfmt    = internalfmt;
            m_fmt            = format;
            m_mipmap         = mipmap;
            m_interpol       = interpol;
            m_texture_target = OpenGL.GL_TEXTURE_2D;

            OpenGL.GenTextures(1, m_texture_id);
            OpenGL.BindTexture(m_texture_target, m_texture_id[0]);
            OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_WRAP_S, OpenGL.GL_CLAMP_TO_EDGE);
            OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_WRAP_T, OpenGL.GL_CLAMP_TO_EDGE);
            if (mipmap)
            {
                OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
                OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR_MIPMAP_LINEAR);
                OpenGL.TexParameterf(m_texture_target, OpenGL.GL_GENERATE_MIPMAP, OpenGL.GL_TRUE);
            }
            else
            {
                if (interpol)
                {
                    OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
                    OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
                }
                else
                {
                    OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_NEAREST);
                    OpenGL.TexParameterf(m_texture_target, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_NEAREST);
                }
                OpenGL.TexParameteri(m_texture_target, OpenGL.GL_GENERATE_MIPMAP, (int)OpenGL.GL_FALSE);
            }
            OpenGL.TexImage2D(m_texture_target, 0, internalfmt, width, height, 0,
                              format, OpenGL.GL_UNSIGNED_BYTE, IntPtr.Zero);
            OpenGL.BindTexture(m_texture_target, 0);
        }