Esempio n. 1
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);
        }
Esempio n. 2
0
        public void BeginBatch(SpriteAtlas atlas)
        {
            current = atlas;

            if (vao == 0)
            {
                program = ShaderManager.Get("sprite.shader");

                vao = GL.GenVertexArray();
                GL.GenBuffers(2, vbo);

                GL.BindVertexArray(vao);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vbo[0]);

                int vertex = program.GetAttribLocation("vertex");
                int uv = program.GetAttribLocation("uv");
                int position = program.GetAttribLocation("position");
                int size = program.GetAttribLocation("size");
                int rotation = program.GetAttribLocation("rotation");
                int color = program.GetAttribLocation("color");

                int stride = BlittableValueType.StrideOf(new SpriteRenderData());

                int offset = 0;

                GL.EnableVertexAttribArray(vertex);
                GL.VertexAttribPointer(vertex, 3, VertexAttribPointerType.Float, false, stride, offset);

                offset += Vector3.SizeInBytes;

                if(uv != -1)
                {
                    GL.EnableVertexAttribArray(uv);
                    GL.VertexAttribPointer(uv, 2, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector2.SizeInBytes;

                if(position != -1)
                {
                    GL.EnableVertexAttribArray(position);
                    GL.VertexAttribPointer(position, 3, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector3.SizeInBytes;

                if(size != -1)
                {
                    GL.EnableVertexAttribArray(size);
                    GL.VertexAttribPointer(size, 2, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector2.SizeInBytes;

                if(rotation != -1)
                {
                    GL.EnableVertexAttribArray(rotation);
                    GL.VertexAttribPointer(rotation, 1, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += sizeof(float);

                if (color != -1)
                {
                    GL.EnableVertexAttribArray(color);
                    GL.VertexAttribPointer(color, 4, VertexAttribPointerType.Float, false, stride, offset);
                }

                offset += Vector4.SizeInBytes;

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, vbo[1]);

                GL.BindVertexArray(0);
            }
        }