コード例 #1
0
        public static void Paint(this TextureImage image, IGUIContext ctx, Rectangle dest)
        {
            if (image.IsDisposed || image.TextureID < 0)
            {
                image.LogWarning("Image is not loaded (has no TextureID).");
                return;
            }

            if (dest.Width < 0 || dest.Height < 0 || !ctx.ClipBoundStack.IsOnScreen(dest))
            {
                return;
            }

            using (new PaintWrapper(RenderingFlags.HighQuality)) {
                GL.Enable(EnableCap.Blend);
                BlendingFactor    srcBlend  = BlendingFactor.SrcAlpha;
                BlendingFactor    destBlend = BlendingFactor.OneMinusSrcAlpha;
                BlendEquationMode mode      = BlendEquationMode.FuncAdd;

                if (image.Opacity < 1)
                {
                    // Multiply
                    srcBlend  = BlendingFactor.DstColor;
                    destBlend = BlendingFactor.OneMinusSrcAlpha;
                    GL.Color4(image.Opacity, image.Opacity, image.Opacity, image.Opacity);
                }
                else
                {
                    // mandatory here,
                    // but take care not to forget the f for float
                    // otherwise there is a dangreous overloading with uint
                    // which would set a very different value
                    if (image.BlendColor != Color.Empty)
                    {
                        GL.Color4(image.BlendColor);
                    }
                    else
                    {
                        GL.Color4(1f, 1f, 1f, 1f);
                    }
                }


                GL.BlendEquation(mode);
                GL.BlendFunc(srcBlend, destBlend);

                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, image.TextureID);

                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);

                GL.Begin(PrimitiveType.Quads);

                GL.TexCoord2(0, 0);
                GL.Vertex3(dest.X, dest.Y, 0);

                GL.TexCoord2(1, 0);
                GL.Vertex3(dest.X + dest.Width, dest.Y, 0);

                GL.TexCoord2(1, 1);
                GL.Vertex3(dest.X + dest.Width, dest.Y + dest.Height, 0);

                GL.TexCoord2(0, 1);
                GL.Vertex3(dest.X, dest.Y + dest.Height, 0);

                GL.End();
            };
        }