public void End() { // apply the custom effect if there is one if (_effect != null) { _effect.CurrentTechnique.Passes [0].Apply(); if (graphicsDevice.Textures._textures.Count > 0) { foreach (EffectParameter ep in _effect._textureMappings) { // if user didn't inform the texture index, we can't bind it if (ep.UserInedx == -1) { continue; } Texture tex = graphicsDevice.Textures [ep.UserInedx]; // Need to support multiple passes as well GL.ActiveTexture((TextureUnit)((int)TextureUnit.Texture0 + ep.UserInedx)); GL.BindTexture(TextureTarget.Texture2D, tex._textureId); GL.Uniform1(ep.UniformLocation, ep.UserInedx); } } } // Disable Blending by default = BlendState.Opaque //GL.Disable (EnableCap.Blend); // set the blend mode // if (_blendState == BlendState.NonPremultiplied) { // GL.BlendFunc (BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // GL.Enable (EnableCap.Blend); // } // // if (_blendState == BlendState.AlphaBlend) { // GL.BlendFunc (BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha); // GL.Enable (EnableCap.Blend); // } // // if (_blendState == BlendState.Additive) { // GL.BlendFunc (BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); // GL.Enable (EnableCap.Blend); // } graphicsDevice.BlendState = _blendState; graphicsDevice.SetGraphicsStates(); // set camera GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); // Switch on the flags. switch (this.graphicsDevice.PresentationParameters.DisplayOrientation) { case DisplayOrientation.LandscapeLeft: { GL.Rotate(-90, 0, 0, 1); GL.Ortho(0, this.graphicsDevice.Viewport.Height, this.graphicsDevice.Viewport.Width, 0, -1, 1); break; } case DisplayOrientation.LandscapeRight: { GL.Rotate(90, 0, 0, 1); GL.Ortho(0, this.graphicsDevice.Viewport.Height, this.graphicsDevice.Viewport.Width, 0, -1, 1); break; } case DisplayOrientation.PortraitUpsideDown: { GL.Rotate(180, 0, 0, 1); GL.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1); break; } default: { GL.Ortho(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1); break; } } // Enable Scissor Tests if necessary if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL.Enable(EnableCap.ScissorTest); } GL.MatrixMode(MatrixMode.Modelview); GL.Viewport(0, 0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height); // Enable Scissor Tests if necessary if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height); } GL.LoadMatrix(ref _matrix.M11); // Initialize OpenGL states (ideally move this to initialize somewhere else) GLStateManager.SetDepthStencilState(_depthStencilState); //GL.Disable (EnableCap.DepthTest); GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)All.BlendSrc); GL.Enable(EnableCap.Texture2D); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.ColorArray); GL.EnableClientState(ArrayCap.TextureCoordArray); // Enable Culling for better performance GL.Enable(EnableCap.CullFace); GL.FrontFace(FrontFaceDirection.Cw); GL.Color4(1.0f, 1.0f, 1.0f, 1.0f); _batcher.DrawBatch(_sortMode, _samplerState); // Disable Scissor Tests if necessary if (this.graphicsDevice.RasterizerState.ScissorTestEnable) { GL.Disable(EnableCap.ScissorTest); } // clear out the textures graphicsDevice.Textures._textures.Clear(); // unbinds shader if (_effect != null) { GL.UseProgram(0); _effect = null; } spriteEffect.CurrentTechnique.Passes [0].Apply(); }