Esempio n. 1
0
        /// <summary>Renders a static frustrum based background</summary>
        /// <param name="data">The background to render</param>
        /// <param name="alpha">The alpha level</param>
        /// <param name="scale">The scale</param>
        private void RenderStaticBackgroundRetained(StaticBackground data, float alpha, float scale)
        {
            Texture t = data.Texture;

            if (data.Texture != null && renderer.currentHost.LoadTexture(ref t, OpenGlTextureWrapMode.RepeatClamp))
            {
                renderer.LastBoundTexture = t.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp];
                if (alpha == 1.0f)
                {
                    GL.Disable(EnableCap.Blend);
                }
                else
                {
                    GL.Enable(EnableCap.Blend);
                }

                if (data.VAO == null)
                {
                    data.CreateVAO(renderer.DefaultShader.VertexLayout, renderer);
                }

                renderer.DefaultShader.Activate();
                renderer.ResetShader(renderer.DefaultShader);

                // matrix
                renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix);
                renderer.DefaultShader.SetCurrentModelViewMatrix(Matrix4D.Scale(scale) * renderer.CurrentViewMatrix);

                // fog
                if (renderer.OptionFog)
                {
                    renderer.DefaultShader.SetIsFog(true);
                    renderer.DefaultShader.SetFog(renderer.Fog);
                }

                // texture
                GL.BindTexture(TextureTarget.Texture2D, t.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name);
                renderer.LastBoundTexture = null;

                // alpha test
                renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);

                // blend mode
                renderer.DefaultShader.SetOpacity(alpha);

                // render polygon
                VertexArrayObject VAO = (VertexArrayObject)data.VAO;
                VAO.Bind();
                renderer.lastVAO = VAO.handle;
                for (int i = 0; i + 11 < 32 * 12; i += 12)
                {
                    VAO.Draw(PrimitiveType.Triangles, i, 12);
                }
                renderer.RestoreBlendFunc();
            }
        }
Esempio n. 2
0
        /// <summary>Renders a static frustrum based background</summary>
        /// <param name="data">The background to render</param>
        /// <param name="alpha">The alpha level</param>
        /// <param name="scale">The scale</param>
        private void RenderStaticBackground(StaticBackground data, float alpha, float scale)
        {
            if (data.Texture != null && renderer.currentHost.LoadTexture(data.Texture, OpenGlTextureWrapMode.RepeatClamp))
            {
                GL.Enable(EnableCap.Texture2D);

                if (alpha == 1.0f)
                {
                    GL.Disable(EnableCap.Blend);
                }
                else
                {
                    GL.Enable(EnableCap.Blend);
                }

                if (data.VAO == null)
                {
                    data.CreateVAO();
                }

                renderer.DefaultShader.Activate();
                renderer.ResetShader(renderer.DefaultShader);

                // matrix
                renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix);
                renderer.DefaultShader.SetCurrentModelViewMatrix(Matrix4D.Scale(scale) * renderer.CurrentViewMatrix);

                // fog
                if (renderer.OptionFog)
                {
                    renderer.DefaultShader.SetIsFog(true);
                    renderer.DefaultShader.SetFogStart(renderer.Fog.Start);
                    renderer.DefaultShader.SetFogEnd(renderer.Fog.End);
                    renderer.DefaultShader.SetFogColor(new Color4(renderer.Fog.Color.R, renderer.Fog.Color.G, renderer.Fog.Color.B, 255));
                }

                // texture
                renderer.DefaultShader.SetIsTexture(true);
                renderer.DefaultShader.SetTexture(0);
                GL.BindTexture(TextureTarget.Texture2D, data.Texture.OpenGlTextures[(int)OpenGlTextureWrapMode.RepeatClamp].Name);

                // alpha test
                renderer.SetAlphaFunc(AlphaFunction.Greater, 0.0f);

                // blend mode
                renderer.DefaultShader.SetOpacity(alpha);

                // render polygon
                VertexArrayObject VAO = (VertexArrayObject)data.VAO;
                VAO.Bind();

                for (int i = 0; i + 9 < 32 * 10; i += 10)
                {
                    VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Quads, i, 4);
                    VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Triangles, i + 4, 3);
                    VAO.Draw(renderer.DefaultShader.VertexLayout, PrimitiveType.Triangles, i + 7, 3);
                }

                VAO.UnBind();

                GL.BindTexture(TextureTarget.Texture2D, 0);
                renderer.DefaultShader.Deactivate();

                GL.Disable(EnableCap.Texture2D);
                renderer.RestoreBlendFunc();
            }
        }