Exemplo n.º 1
0
        int LoadTexture(string imgFileName)
        {
            //Bitmap bmp = new Bitmap(imgFileName);
            PixelFarm.Agg.ActualImage bmp = DemoHelper.LoadImage(imgFileName);
            int texture;

            GL.GenTextures(1, out texture);
            GL.BindTexture(TextureTarget.Texture2D, texture);
            //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            //     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
            //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(image.width), static_cast<GLsizei>(image.height), 0,
            //             GL_RGBA, GL_UNSIGNED_BYTE, image.data.data());

            //var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0,
            //    bmp.Width, bmp.Height),
            //    System.Drawing.Imaging.ImageLockMode.ReadOnly,
            //    System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            var    lazyImgProvider = new PixelFarm.DrawingGL.LazyAggBitmapBufferProvider(bmp);
            IntPtr ptr             = lazyImgProvider.GetRawBufferHead();

            //var bmpdata = bmp.LockBits();
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp.Width, bmp.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, ptr);
            // bmp.UnlockBits(bmpdata);
            lazyImgProvider.ReleaseBufferHead();


            //glGenerateMipmap(GL_TEXTURE_2D);
            GL.GenerateMipmap(TextureTarget.Texture2D);
            return(texture);
        }
Exemplo n.º 2
0
        public override void Init()
        {
            UseBitmapExt = false;

            string imgFileName = "d:\\WImageTest\\lion1.png";

            if (System.IO.File.Exists(imgFileName))
            {
                lionImg = DemoHelper.LoadImage(imgFileName);
            }
        }
Exemplo n.º 3
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            //---------------------
            var atlasBuilder = new Typography.Rendering.SimpleFontAtlasBuilder();

            fontAtlas = atlasBuilder.LoadFontInfo(RootDemoPath.Path + @"\a_total.xml");


            var actualImg = DemoHelper.LoadImage(RootDemoPath.Path + @"\a_total.png");

            //var bmpdata = totalImg.LockBits(new System.Drawing.Rectangle(0, 0, totalImg.Width, totalImg.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, totalImg.PixelFormat);
            //var buffer = new int[totalImg.Width * totalImg.Height];
            //System.Runtime.InteropServices.Marshal.Copy(bmpdata.Scan0, buffer, 0, buffer.Length);
            //totalImg.UnlockBits(bmpdata);
            var glyph = new Typography.Rendering.GlyphImage(totalImg.Width, totalImg.Height);

            glyph.SetImageBuffer(PixelFarm.Agg.ActualImage.CopyImgBuffer(actualImg), false);
            fontAtlas.TotalGlyph = glyph;
        }
        protected override void OnReadyForInitGLShaderProgram()
        {
            //--------------------------------------------------------------------------
            string vs = @"
                attribute vec4 a_position;
                attribute vec2 a_texCoord;
                uniform mat4 u_mvpMatrix; 
                varying vec2 v_texCoord;
                void main()
                {
                    gl_Position = u_mvpMatrix* a_position;
                    v_texCoord =  a_texCoord;
                 }	 
                ";
            //in fs, angle on windows
            //we need to switch color component
            //because we store value in memory as BGRA
            //and gl expect input in RGBA
            string fs = @"
                      precision mediump float;
                      varying vec2 v_texCoord;
                      uniform sampler2D s_texture;
                      void main()
                      {
                         vec4 c = texture2D(s_texture, v_texCoord);                            
                         gl_FragColor =  vec4(c[2],c[1],c[0],c[3]);
                      }
                ";

            mProgram = ES2Utils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                //return false
            }

            // Get the attribute locations
            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord");
            u_matrix     = GL.GetUniformLocation(mProgram, "u_mvpMatrix");
            // Get the sampler location
            mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture");
            //// Load the texture

            PixelFarm.Agg.ActualImage bmp = DemoHelper.LoadImage(RootDemoPath.Path + @"\test001.png");
            int bmpW = bmp.Width;
            int bmpH = bmp.Height;

            mTexture = LoadTexture(bmp);
            GL.ClearColor(0, 0, 0, 0);
            //================================================================================

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ClearColor(1, 1, 1, 1);
            //setup viewport size
            int max = Math.Max(this.Width, this.Height);

            orthoViewMat = MyMat4.ortho(0, max, 0, max, 0, 1).data;
            //square viewport
            GL.Viewport(0, 0, max, max);
            imgVertices = new float[]
            {
                0, bmpH, 0,
                0, 0,
                //---------------------
                0, 0, 0,
                0, 1,
                //---------------------
                bmpW, bmpH, 0,
                1, 0,
                //---------------------
                bmpW, 0, 0,
                1, 1
            };
        }