Exemple #1
0
        // This gets called when the drawing surface is ready
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            GL.BlendFunc(All.SrcAlpha, All.OneMinusSrcAlpha);
            GL.Enable(All.Blend);

            LoadShaders();

            texture = GLSupport.LoadTextureFromAssets("f_spot_rgb.etc1");

            // Run the render loop
            Run();
        }
Exemple #2
0
        bool LoadShaders()
        {
            int vertShader, fragShader;

            // Create shader program.
            program = GL.CreateProgram();

            // Create and compile vertex shader.
            var vertShaderPathname = "Shader.vsh";

            if (!GLSupport.CompileShader(ShaderType.VertexShader, vertShaderPathname, out vertShader))
            {
                System.Diagnostics.Debug.WriteLine("Failed to compile vertex shader");
                return(false);
            }

            // Create and compile fragment shader.
            var fragShaderPathname = "Shader.fsh";

            if (!GLSupport.CompileShader(ShaderType.FragmentShader, fragShaderPathname, out fragShader))
            {
                System.Diagnostics.Debug.WriteLine("Failed to compile fragment shader");
                return(false);
            }

            // Attach vertex shader to program.
            GL.AttachShader(program, vertShader);

            // Attach fragment shader to program.
            GL.AttachShader(program, fragShader);

            // Bind attribute locations.
            // This needs to be done prior to linking.
            GL.BindAttribLocation(program, ATTRIB_VERTEX, "position");
            GL.BindAttribLocation(program, ATTRIB_TEXTURECOORD, "a_TexCoordinate");

            // Link program.
            if (!GLSupport.LinkProgram(program))
            {
                System.Diagnostics.Debug.WriteLine("Failed to link program: {0:x}", program);

                if (vertShader != 0)
                {
                    GL.DeleteShader(vertShader);
                }

                if (fragShader != 0)
                {
                    GL.DeleteShader(fragShader);
                }

                if (program != 0)
                {
                    GL.DeleteProgram(program);
                    program = 0;
                }

                return(false);
            }

            // Get uniform locations.
                        #if __IOS__
            uniforms [UNIFORM_TRANSLATE] = GL.GetUniformLocation(program, "translate");
            uniforms [UNIFORM_TEXTURE]   = GL.GetUniformLocation(program, "u_Texture");
                        #elif __ANDROID__
            uniforms [UNIFORM_TRANSLATE] = GL.GetUniformLocation(program, new StringBuilder("translate"));
            uniforms [UNIFORM_TEXTURE]   = GL.GetUniformLocation(program, new StringBuilder("u_Texture"));
                        #endif

            // Release vertex and fragment shaders.
            if (vertShader != 0)
            {
                GL.DetachShader(program, vertShader);
                GL.DeleteShader(vertShader);
            }

            if (fragShader != 0)
            {
                GL.DetachShader(program, fragShader);
                GL.DeleteShader(fragShader);
            }

            return(true);
        }