protected override void OnReadyForInitGLShaderProgram()
        {
            //----------------
            //vertex shader source
            string vs = @"      
             
            attribute vec2 a_position;
            attribute vec4 a_color;
            
            varying vec4 v_color;
 
            void main()
            {   
                
                gl_Position = vec4(a_position[0],a_position[1],0,1);  
                v_color = a_color;
            }
            ";
            //fragment source
            string fs = @"
                precision mediump float;
                varying vec4 v_color;                 
                void main()
                { 
                    gl_FragColor = v_color;
                }
            ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }


            a_position = shaderProgram.GetAttrV2f("a_position");
            a_color    = shaderProgram.GetAttrV3f("a_color");
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //GL.ClearColor(0, 0, 0, 0);
            GL.ClearColor(1, 1, 1, 1);
        }
Beispiel #2
0
        protected override void OnInitGLProgram(object sender, EventArgs handler)
        {
            shaderProgram = new MiniShaderProgram();
            string vs = @"
                attribute vec3 a_position;
                attribute vec2 a_texCoord;
                varying vec2 v_texCoord;
                void main()
                {
                    gl_Position = vec4(a_position[0],a_position[1],0,1);
                    v_texCoord = a_texCoord;
                 }	 
                ";
            string fs = @"
                      precision mediump float;
                      varying vec2 v_texCoord;
                      uniform sampler2D s_texture;
                      void main()
                      {
                         gl_FragColor = texture2D(s_texture, v_texCoord);
                      }
                ";

            if (!shaderProgram.Build(vs, fs))
            {
            }

            //-------------------------------------------

            // Get the attribute locations
            a_position  = shaderProgram.GetAttrV3f("a_position");// GL.GetAttribLocation(mProgram, "a_position");
            a_textCoord = shaderProgram.GetAttrV2f("a_texCoord");
            // Get the sampler location
            s_texture = shaderProgram.GetUniform1("s_texture");
            //// Load the texture
            mTexture = ES2Utils2.CreateSimpleTexture2D();
            GL.ClearColor(0, 0, 0, 0);
            //================================================================================
        }
Beispiel #3
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            //----------------
            //vertex shader source
            string vs = @"        
            precision mediump float;
            attribute vec2 a_position;
            attribute vec3 a_color; 
            attribute vec2 a_texcoord;
            
            uniform mat4 u_mvpMatrix;
            uniform vec4 u_solidColor;
            uniform int u_useSolidColor;            

            varying vec4 v_color;
            varying vec2 v_texcoord;
             
            void main()
            {
                
                gl_Position = u_mvpMatrix* vec4(a_position[0],a_position[1],0.0,1.0);
                if(u_useSolidColor !=0)
                {
                    v_color= u_solidColor;                                       
                }
                else
                {
                    v_color = vec4(a_color,1.0);
                } 
                v_texcoord= a_texcoord;
            }
            ";
            //fragment source
            string fs = @"
                precision mediump float;
                varying vec4 v_color; 
                varying vec2 v_texcoord;                 
                void main()
                {       
                    
                    //gl_FragColor = vec4(1,v_texcoord.y,0,1);
                    gl_FragColor= v_color;
                }
            ";

            if (!shaderProgram.Build(vs, fs))
            {
                throw new NotSupportedException();
            }


            a_position      = shaderProgram.GetAttrV2f("a_position");
            a_color         = shaderProgram.GetAttrV3f("a_color");
            a_textureCoord  = shaderProgram.GetAttrV2f("a_texcoord");
            u_matrix        = shaderProgram.GetUniformMat4("u_mvpMatrix");
            u_useSolidColor = shaderProgram.GetUniform1("u_useSolidColor");
            u_solidColor    = shaderProgram.GetUniform4("u_solidColor");
            //--------------------------------------------------------------------------------
            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);

            //square viewport
            GL.Viewport(0, 0, max, max);
            orthoView = MyMat4.ortho(0, max, 0, max, 0, 1);
            //--------------------------------------------------------------------------------

            //load image
        }