Ejemplo n.º 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();
            int width, height = 0;

            // load the etc1
            texture = GLSupport.LoadETC1TextureFromAssets("f_spot.etc1", out width, out height);
            // load the alpha
            alpha = GLSupport.LoadAlphaTextureFromAssets("f_spot.alpha", width, height);

            // Run the render loop
            Run();
        }
Ejemplo n.º 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.
            uniforms [UNIFORM_TRANSLATE] = GL.GetUniformLocation(program, new StringBuilder("translate"));
            uniforms [UNIFORM_TEXTURE]   = GL.GetUniformLocation(program, new StringBuilder("u_Texture"));
            uniforms [UNIFORM_ALPHA]     = GL.GetUniformLocation(program, new StringBuilder("u_Alpha"));

            // 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);
        }