Ejemplo n.º 1
0
        override protected void CreatePrograms()
        {
            if (_program == null)
            {
                string programName = BlurProgram.GetProgramName(false);
                _program = (BlurProgram)SparrowSharpApp.GetProgram(programName);
                if (_program == null)
                {
                    _program = new BlurProgram(false);
                    SparrowSharpApp.RegisterProgram(programName, _program);
                }
            }

            if (_tintedProgram == null)
            {
                string programName = BlurProgram.GetProgramName(true);
                _tintedProgram = (BlurProgram)SparrowSharpApp.GetProgram(programName);

                if (_tintedProgram == null)
                {
                    _tintedProgram = new BlurProgram(true);
                    SparrowSharpApp.RegisterProgram(programName, _tintedProgram);
                }
            }

            VertexPosID = _program.APosition;
            TexCoordsID = _program.ATexCoords;
        }
        // This gets called on each frame render
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            base.OnRenderFrame(e);

            SparrowSharpApp.Step(e.Time);

            SwapBuffers();
        }
 private void HandleRenderFrame(object sender, FrameEventArgs e)
 {
     SparrowSharpApp.Step(e.Time);
     // add game logic, input handling
     if (Keyboard[Key.Escape])
     {
         Exit();
     }
     SwapBuffers();
 }
        // This gets called when the drawing surface is ready (=on startup and when the app regains focus)
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            MakeCurrent();

            if (SparrowSharpApp.Root == null)
            {
                SparrowSharpApp.Start((uint)Size.Width, (uint)Size.Height, _rootClass);
            }
            // Run the render loop
            Run();
        }
Ejemplo n.º 5
0
        public void TestForOpenGLErrors()
        {
            Quad q1 = new Quad();

            testRoot.AddChild(q1);
            SparrowSharpApp.Step(15);
            Quad q2 = new Quad();

            q2.Alpha = 0.6f;
            testRoot.AddChild(q2);
            SparrowSharpApp.Step(15);

            Assert.IsFalse(RenderSupport.HasOpenGLError);
        }
Ejemplo n.º 6
0
 override protected void CreatePrograms()
 {
     if (_program == null)
     {
         string programName = "_test_emptyFilterProgram";
         _program = SparrowSharpApp.GetProgram(programName);
         if (_program == null)
         {
             _program = new Program(FragmentFilter.StandardVertexShader(), FragmentFilter.StandardFragmentShader());
             SparrowSharpApp.RegisterProgram(programName, _program);
         }
     }
     VertexPosID = _program.Attributes["aPosition"];
     TexCoordsID = _program.Attributes["aTexCoords"];
 }
        private void HandleLoad(object sender, EventArgs e)
        {
            // setup settings, load textures, sounds
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Dither);
            GL.Enable(EnableCap.Blend);

            FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                Console.WriteLine("Framebuffer error: " + status);
            }
            SparrowSharpApp.NativeWindow = this;
            SparrowSharpApp.Start((uint)Width, (uint)Height, _rootClass);
        }
Ejemplo n.º 8
0
        public void TestRoot()
        {
            SparrowSharpApp.Start(12, 12, typeof(Sprite));

            Sprite root       = new Sprite();
            Sprite child      = new Sprite();
            Sprite grandChild = new Sprite();

            root.AddChild(child);
            child.AddChild(grandChild);

            Assert.AreEqual(root, grandChild.Root, "Wrong root " + grandChild.Root);

            SparrowSharpApp.Stage.AddChild(root);

            Assert.AreEqual(SparrowSharpApp.Stage, grandChild.Root, "Wrong root " + grandChild.Root);

            SparrowSharpApp.Stage.RemoveAllChildren();
            SparrowSharpApp.Destroy();
        }
Ejemplo n.º 9
0
        override protected void CreatePrograms()
        {
            if (_shaderProgram == null)
            {
                _shaderProgram = SparrowSharpApp.GetProgram(ColorMatrixProgram);

                if (_shaderProgram == null)
                {
                    _shaderProgram = new Program(FragmentFilter.StandardVertexShader(), GetFragmentShader());

                    SparrowSharpApp.RegisterProgram(ColorMatrixProgram, _shaderProgram);
                }

                VertexPosID = _shaderProgram.Attributes["aPosition"];
                TexCoordsID = _shaderProgram.Attributes["aTexCoords"];

                _uColorMatrix = _shaderProgram.Uniforms["uColorMatrix"];
                _uColorOffset = _shaderProgram.Uniforms["uColorOffset"];
                _uMvpMatrix   = _shaderProgram.Uniforms["uMvpMatrix"];
            }
        }
 public OpenGLViewController(string nibName, NSBundle bundle) : base(nibName, bundle)
 {
     _onLoadedAction = (width, height) => SparrowSharpApp.Start(width, height, typeof(Benchmark));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Activates the optimal shader program for the current settings; alpha and matrix uniforms are
        /// passed to the program right away, and the texture (if available) is bound.
        /// Parameters:
        /// mvpMatrix: The modelview-projection matrix used for rendering. Any vertex will be multiplied with this matrix.
        /// premultipliedAlpha:  Indicates if the color values of texture and vertices use premultiplied alpha.
        /// alpha: The alpha value with which every vertex color will be multiplied.
        /// useTinting: Set to true if you dont use textures or want to use alpha.
        /// texture: The texture that's projected onto the quad, or 'null' if there is none.
        /// </summary>
        public void PrepareToDraw(Matrix mvpMatrix, bool premultipliedAlpha, float alpha, bool useTinting, Texture texture = null)
        {
            bool hasTexture = texture != null;

            string programName;

            if (hasTexture)
            {
                programName = useTinting ? "SparrowAlphaTextureProgram" : "SparrowTextureProgram";
            }
            else
            {
                programName = "SparrowQuadProgram";
            }

            if (_currentProgram == null || _currentProgram != SparrowSharpApp.GetProgram(programName))
            {
                if (SparrowSharpApp.Programs.ContainsKey(programName))
                {
                    _currentProgram = SparrowSharpApp.GetProgram(programName);
                }
                else
                {
                    string vertexShader   = VertexShaderString(hasTexture, useTinting);
                    string fragmentShader = FragmentShaderString(hasTexture, useTinting);
                    _currentProgram = new Program(vertexShader, fragmentShader);
                    SparrowSharpApp.RegisterProgram(programName, _currentProgram);
                }

                _aPosition = _currentProgram.Attributes["aPosition"];

                if (_currentProgram.Attributes.ContainsKey("aColor"))
                {
                    _aColor = _currentProgram.Attributes["aColor"];
                }
                if (_currentProgram.Attributes.ContainsKey("aTexCoords"))
                {
                    _aTexCoords = _currentProgram.Attributes["aTexCoords"];
                }

                _uMvpMatrix = _currentProgram.Uniforms["uMvpMatrix"];

                if (_currentProgram.Uniforms.ContainsKey("uAlpha"))
                {
                    _uAlpha = _currentProgram.Uniforms["uAlpha"];
                }
            }

            Matrix4 glkMvpMatrix = mvpMatrix.ConvertToMatrix4();

            GL.UseProgram(_currentProgram.Name);
            GL.UniformMatrix4(_uMvpMatrix, false, ref glkMvpMatrix); // TODO check; was glUniformMatrix4fv(_uMvpMatrix, 1, NO, glkMvpMatrix.m);

            if (useTinting)
            {
                if (premultipliedAlpha)
                {
                    GL.Uniform4(_uAlpha, alpha, alpha, alpha, alpha);
                }
                else
                {
                    GL.Uniform4(_uAlpha, 1.0f, 1.0f, 1.0f, alpha);
                }
            }

            if (hasTexture)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, texture.Name);
            }
        }
 protected void TearDown()
 {
     testRoot.RemoveAllChildren();
     SparrowSharpApp.Destroy();
 }
 protected void SetUp()
 {
     SparrowSharpApp.Start(12, 12, typeof(Sprite));
     testRoot = new Sprite();
     SparrowSharpApp.Stage.AddChild(testRoot);
 }