コード例 #1
0
        internal GLRenderSurface(int width, int height)
        {
            //-------------
            //y axis points upward (like other OpenGL)
            //x axis points to right.
            //please NOTE: left lower corner of the canvas is (0,0)
            //-------------

            this._width  = width;
            this._height = height;
            //setup viewport size,
            //we need W:H ratio= 1:1 , square viewport
            int max = Math.Max(width, height);

            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1); //this make our viewport W:H =1:1

            flipVerticalView = MyMat4.scale(1, -1) * MyMat4.translate(new OpenTK.Vector3(0, -height, 0));
            orthoAndFlip     = orthoView * flipVerticalView;
            //-----------------------------------------------------------------------
            _shareRes           = new ShaderSharedResource();
            _shareRes.OrthoView = orthoView;
            //-----------------------------------------------------------------------
            basicFillShader     = new BasicFillShader(_shareRes);
            smoothLineShader    = new SmoothLineShader(_shareRes);
            rectFillShader      = new RectFillShader(_shareRes);
            gdiImgTextureShader = new GdiImageTextureShader(_shareRes);
            gdiImgTextureWithWhiteTransparentShader = new GdiImageTextureWithWhiteTransparentShader(_shareRes);
            glyphStencilShader        = new GlyphImageStecilShader(_shareRes);
            textureSubPixRendering    = new ImageTextureWithSubPixelRenderingShader(_shareRes);
            blurShader                = new BlurShader(_shareRes);
            glesTextureShader         = new OpenGLESTextureShader(_shareRes);
            invertAlphaFragmentShader = new InvertAlphaLineSmoothShader(_shareRes); //used with stencil  ***

            conv3x3TextureShader        = new Conv3x3TextureShader(_shareRes);
            msdfShader                  = new DrawingGL.MultiChannelSdf(_shareRes);
            msdfSubPixelRenderingShader = new DrawingGL.MultiChannelSubPixelRenderingSdf(_shareRes);
            sdfShader = new DrawingGL.SingleChannelSdf(_shareRes);
            //-----------------------------------------------------------------------
            //tools

            tessTool = new TessTool();
            //-----------------------------------------------------------------------


            //GL.Enable(EnableCap.CullFace);
            //GL.FrontFace(FrontFaceDirection.Cw);
            //GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);//original **

            //GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.One);// not apply alpha to src
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha,
            //                     BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcColor, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.Zero);

            GL.ClearColor(1, 1, 1, 1);
            //-------------------------------------------------------------------------------
            GL.Viewport(0, 0, width, height);
        }
コード例 #2
0
ファイル: CanvasGL2d.cs プロジェクト: lingliy/HtmlRenderer
        FrameBuffer _currentFrameBuffer;//default = null, system provide frame buffer


        internal CanvasGL2d(int canvasW, int canvasH)
        {
            this.canvasW = canvasW;
            this.canvasH = canvasH;
            ////setup viewport size
            int max = Math.Max(canvasW, canvasH);

            ////square viewport
            orthoView        = MyMat4.ortho(0, max, 0, max, 0, 1);
            flipVerticalView = MyMat4.scale(1, -1) * MyMat4.translate(new OpenTK.Vector3(0, -max, 0));
            orthoAndFlip     = orthoView * flipVerticalView;
            //-----------------------------------------------------------------------
            shaderRes           = new CanvasToShaderSharedResource();
            shaderRes.OrthoView = orthoView;
            //-----------------------------------------------------------------------
            basicFillShader     = new BasicFillShader(shaderRes);
            smoothLineShader    = new SmoothLineShader(shaderRes);
            rectFillShader      = new RectFillShader(shaderRes);
            gdiImgTextureShader = new GdiImageTextureShader(shaderRes);
            gdiImgTextureWithWhiteTransparentShader = new GdiImageTextureWithWhiteTransparentShader(shaderRes);
            textureSubPixRendering    = new ImageTextureWithSubPixelRenderingShader(shaderRes);
            blurShader                = new BlurShader(shaderRes);
            glesTextureShader         = new OpenGLESTextureShader(shaderRes);
            invertAlphaFragmentShader = new InvertAlphaLineSmoothShader(shaderRes); //used with stencil  ***
            // tessListener.Connect(tess,
            //Tesselate.Tesselator.WindingRuleType.Odd, true);
            conv3x3TextureShader = new Conv3x3TextureShader(shaderRes);
            msdfShader           = new DrawingGL.MultiChannelSdf(shaderRes);


            msdfSubPixelRenderingShader = new DrawingGL.MultiChannelSubPixelRenderingSdf(shaderRes);
            sdfShader = new DrawingGL.SingleChannelSdf(shaderRes);
            //----
            Tesselator tess = new Tesselator();

            tess.WindingRule = Tesselator.WindingRuleType.Odd;
            tessTool         = new TessTool(tess);
            //-----------------------------------------------------------------------


            //GL.Enable(EnableCap.CullFace);
            //GL.FrontFace(FrontFaceDirection.Cw);
            //GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);//original **

            //GL.BlendFunc(BlendingFactorSrc.SrcColor, BlendingFactorDest.One);// not apply alpha to src
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcAlpha,
            //                     BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.BlendFuncSeparate(BlendingFactorSrc.SrcColor, BlendingFactorDest.OneMinusSrcColor, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.Zero);

            GL.ClearColor(1, 1, 1, 1);
            //-------------------------------------------------------------------------------
            GL.Viewport(0, 0, canvasW, canvasH);
        }
コード例 #3
0
        public void NewDrawSubImage4FromCurrentLoadedVBO(int count1, float x, float y)
        {
            a_position.LoadLatest(5, 0);
            a_texCoord.LoadLatest(5, 3 * 4);

            MyMat4 backup = _shareRes.OrthoView;
            MyMat4 mm2    = _shareRes.OrthoView * MyMat4.translate(new OpenTK.Vector3(x, y, 0));

            ////version 1
            ////1. B , yellow  result
            GL.ColorMask(false, false, true, false);
            this.SetCompo(0);
            OnSetVarsBeforeRenderer();
            u_matrix.SetData(mm2.data);


            GL.DrawElements(BeginMode.TriangleStrip, count1, DrawElementsType.UnsignedShort, 0);

            ////2. G , magenta result
            GL.ColorMask(false, true, false, false);
            this.SetCompo(1);
            OnSetVarsBeforeRenderer();
            // u_matrix.SetData(mm2.data);
            GL.DrawElements(BeginMode.TriangleStrip, count1, DrawElementsType.UnsignedShort, 0);

            //1. R , cyan result
            GL.ColorMask(true, false, false, false);//
            this.SetCompo(2);
            OnSetVarsBeforeRenderer();
            //u_matrix.SetData(mm2.data);
            GL.DrawElements(BeginMode.TriangleStrip, count1, DrawElementsType.UnsignedShort, 0);

            //restore
            GL.ColorMask(true, true, true, true);

            u_matrix.SetData(backup.data);
        }