Ejemplo n.º 1
0
        protected override void OnInitGLProgram(object sender, EventArgs args)
        {
            string vs = @"
                uniform float u_offset;
                attribute vec4 a_position;
                attribute vec2 a_texCoord;
                varying vec2 v_texCoord;
                void main()
                {
                    gl_Position = a_position;
                    gl_Position.x += u_offset;
                     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);
                 }
            ";

            mProgram = ES2Utils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                //error
                throw new NotSupportedException();
            }
            //mProgram = CompileProgram(vs, fs);
            //if (!mProgram)
            //{
            //    return false;
            //}

            //// Get the attribute locations
            //mPositionLoc = glGetAttribLocation(mProgram, "a_position");
            //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord");
            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord");
            //// Get the sampler location
            //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
            mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture");
            //// Get the offset location
            //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset");
            mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset");
            //// Load the texture
            mTexture = ES2Utils2.CreateMipMappedTexture2D();
            //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.ClearColor(0, 0, 0, 0);

            isGLInit = true;
            this.EnableAnimationTimer = true;
        }
Ejemplo n.º 2
0
        protected override void OnInitGLProgram(object sender, EventArgs args)
        {
            string vs = @"
                 uniform float u_offset;
                 attribute vec4 a_position;
                 attribute vec2 a_texCoord;
                 varying vec2 v_texCoord; 
                 void main()
                 {
                        gl_Position = a_position;
                        gl_Position.x += u_offset;
                        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);
                 }
            ";

            mProgram = ES2Utils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                throw new NotSupportedException();
            }

            //// Get the attribute locations
            //mPositionLoc = glGetAttribLocation(mProgram, "a_position");
            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord");
            mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord");

            //// Get the sampler location
            //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
            mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture");
            //// Get the offset location
            //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset");
            mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset");
            //// Load the texture
            //mTextureID = CreateMipMappedTexture2D();
            mTextureID = ES2Utils2.CreateMipMappedTexture2D();

            //// Check Anisotropy limits
            //glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &mMaxAnisotropy);
            GL.GetFloat((GetPName)(ExtTextureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY), out mMaxAnisotropy);
            //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.ClearColor(0, 0, 0, 0);
            isGLInit = true;
            this.EnableAnimationTimer = true;
        }
Ejemplo n.º 3
0
        protected override void OnInitGLProgram(object sender, EventArgs handler)
        {
            //--------------------------------------------------------------------------
            string vs = @"
                attribute vec4 a_position;
                attribute vec2 a_texCoord;
                varying vec2 v_texCoord;
                void main()
                {
                    gl_Position = a_position;
                    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);
                      }
                ";

            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");

            // Get the sampler location
            mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture");

            //// Load the texture
            mTexture = ES2Utils2.CreateSimpleTexture2D();
            GL.ClearColor(0, 0, 0, 0);
            //================================================================================
        }
Ejemplo n.º 4
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);
            //================================================================================
        }
Ejemplo n.º 5
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            string vs = @"
                uniform float u_offset;
                attribute vec4 a_position;
                attribute vec2 a_texCoord;
                varying vec2 v_texCoord;
                void main()
                {
                    gl_Position = a_position;
                    gl_Position.x += u_offset;
                     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);
                 }
            ";

            mProgram = ES2Utils.CompileProgram(vs, fs);
            if (mProgram == 0)
            {
                //error
                throw new NotSupportedException();
            }
            //mProgram = CompileProgram(vs, fs);
            //if (!mProgram)
            //{
            //    return false;
            //}

            //// Get the attribute locations
            //mPositionLoc = glGetAttribLocation(mProgram, "a_position");
            //mTexCoordLoc = glGetAttribLocation(mProgram, "a_texCoord");
            mPositionLoc = GL.GetAttribLocation(mProgram, "a_position");
            mTexCoordLoc = GL.GetAttribLocation(mProgram, "a_texCoord");
            //// Get the sampler location
            //mSamplerLoc = glGetUniformLocation(mProgram, "s_texture");
            mSamplerLoc = GL.GetUniformLocation(mProgram, "s_texture");
            //// Get the offset location
            //mOffsetLoc = glGetUniformLocation(mProgram, "u_offset");
            mOffsetLoc = GL.GetUniformLocation(mProgram, "u_offset");
            //// Load the texture
            mTexture = ES2Utils2.CreateMipMappedTexture2D();
            //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.ClearColor(0, 0, 0, 0);
            isGLInit = true;
            this.EnableAnimationTimer = true;

            //create vbo array


            float[] vertices = new float[] {
                -0.3f, 0.3f, 0.0f, 1.0f,   // Position 0
                -1.0f, -1.0f,              // TexCoord 0
                -0.3f, -0.3f, 0.0f, 1.0f,  // Position 1
                -1.0f, 2.0f,               // TexCoord 1
                0.3f, -0.3f, 0.0f, 1.0f,   // Position 2
                2.0f, 2.0f,                // TexCoord 2
                0.3f, 0.3f, 0.0f, 1.0f,    // Position 3
                2.0f, -1.0f                // TexCoord 3
            };
            //GLushort indices[] = { 0, 1, 2, 0, 2, 3 };

            ushort[] indices = new ushort[] { 0, 1, 2, 0, 2, 3 };
            vbo2 = new PixelFarm.DrawingGL.VertexBufferObject2();
            vbo2.CreateBuffers(vertices, indices);
        }