Esempio n. 1
0
 public void RenderOnScreen(ShaderProgram shader)
 {
     shader.Enable();
     shader.SendUniform("ScreenSize", ref size);
     shader.SendUniform("MSAA_Samples", MSAA);
     Texture.Bind();
     batch.Render();
     Texture.UnBind();
     shader.Disable();
 }
Esempio n. 2
0
        public void Draw(ShaderProgram shader)
        {
            if (text == string.Empty)
                return;

            if(dirty)
            {
                dirty = false;

                Upload();
            }

            if (indices == null || vertices == null)
                return;

            Font.Texture.Bind();

            GL.BindVertexArray(vao);

            if (mustDescribe)
            {
                int stride = BlittableValueType.StrideOf(vertices);

                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);

                // Vertex
                int vertexLocation = shader.GetAttribLocation("vertex");
                if(vertexLocation > -1)
                {
                    GL.EnableVertexAttribArray(vertexLocation);
                    GL.VertexAttribPointer(vertexLocation, 2, VertexAttribPointerType.Float, false, stride, 0);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vertex: " + vertexLocation);
                }

                // TCoord
                int uvLocation = shader.GetAttribLocation("uv");
                if(uvLocation > -1)
                {
                    GL.EnableVertexAttribArray(uvLocation);
                    GL.VertexAttribPointer(uvLocation, 2, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for uv: " + uvLocation);
                }
                // Color
                int colorLocation = shader.GetAttribLocation("vColor");
                if(colorLocation > -1)
                {
                    GL.EnableVertexAttribArray(colorLocation);
                    GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vColor: " + colorLocation);
                }
                // BorderColor
                int borderLocation = shader.GetAttribLocation("vBorderColor");
                if (borderLocation > -1)
                {
                    GL.EnableVertexAttribArray(borderLocation);
                    GL.VertexAttribPointer(borderLocation, 4, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2 + Vector4.SizeInBytes);
                }
                else
                {
                    Console.WriteLine("Bad attribute location for vBorderColor: " + borderLocation);
                }
                // Settings
                /*int settingsLocation = shader.GetAttribLocation("vSettings");
                GL.EnableVertexAttribArray(settingsLocation);
                GL.VertexAttribPointer(settingsLocation, 3, VertexAttribPointerType.Float, false, stride, Vector2.SizeInBytes * 2 + Vector4.SizeInBytes * 2);*/

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, ebo);

                mustDescribe = false;
            }

            //float smooth = (1f - (fontsize / 150f)) * 0.5f * this.weight * this.smooth;

            if (smooth < 0f)
                smooth = 0f;
            else if (smooth > 0.5f)
                smooth = 0.5f;

            //float weight = Hatzap.Utilities.MathHelper.Lerp(0f, 2f, 1f - (fontsize / 100f * this.weight));
            //float weight = (float)Math.Pow(1.5f - (fontsize / 150f), this.weight) * this.weight * 0.75f;

            /*if (weight < 0.75f)
                weight = 0.75f;*/

            CalculatedWeight = weight;

            Vector4 settings = new Vector4(fontsize, weight, border, smooth);

            shader.SendUniform("Settings", ref settings);

            GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero);

            GL.BindVertexArray(0);
        }