예제 #1
0
        /// <summary>
        /// Helper method to reduce lines of code related to simple font drawing.
        /// Calls Begin(), then LoadVBOs(), then DrawVBOs(), then End()
        /// </summary>
        public void Draw()
        {
            GL.UseProgram(InstanceSharedState.ShaderVariables.ShaderProgram);
            if (_useDefaultBlendFunction)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            }
            GL.UniformMatrix4(InstanceSharedState.ShaderVariables.MVPUniformLocation, false, ref _projectionMatrix);

            GL.Uniform1(InstanceSharedState.ShaderVariables.SamplerLocation, 0);
            GL.ActiveTexture(InstanceSharedState.DefaultTextureUnit);

            int start = 0;

            _vertexArrayObject.Bind();
            GL.Disable(EnableCap.IndexArray); //disable index array if any
            foreach (var primitive in _glFontDrawingPimitives)
            {
                var font = primitive.Font;
                if (font != null)
                {
                    GL.ActiveTexture(QFontSharedState.DefaultTextureUnit);
                    // Use DrawArrays - first draw drop shadows, then draw actual font primitive
                    if (primitive.ShadowVertexRepr.Count > 0)
                    {
                        //int index = primitive.Font.FontData.CalculateMaxHeight();
                        GL.BindTexture(TextureTarget.Texture2D, font.dropShadowFont.FontData.Pages[0].GLTexID);
                        GL.DrawArrays(PrimitiveType.Triangles, start, primitive.ShadowVertexRepr.Count);
                        start += primitive.ShadowVertexRepr.Count;
                    }
                    GL.BindTexture(TextureTarget.Texture2D, font.Pages[0].GLTexID);
                    GL.DrawArrays(PrimitiveType.Triangles, start, primitive.CurrentVertexRepr.Count);
                }
                else
                {
                    int i = 0;
                }

                start += primitive.CurrentVertexRepr.Count;
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
예제 #2
0
        /// <summary>
        /// Draws the text stored in this drawing
        /// </summary>
        public void Draw()
        {
            GL.UseProgram(InstanceSharedState.ShaderVariables.ShaderProgram);
            if (_useDefaultBlendFunction)
            {
                GL.Enable(EnableCap.Blend);
#if OPENGL_ES
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
#else
                GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
#endif
            }
            GL.UniformMatrix4(InstanceSharedState.ShaderVariables.ProjectionMatrixUniformLocation, false, ref _projectionMatrix);

            GL.Uniform1(InstanceSharedState.ShaderVariables.SamplerLocation, 0);
            GL.ActiveTexture(InstanceSharedState.DefaultTextureUnit);

            int start = 0;
            VertexArrayObject.Bind();
            foreach (var primitive in _glFontDrawingPrimitives)
            {
                GL.UniformMatrix4(InstanceSharedState.ShaderVariables.ModelViewMatrixUniformLocation, false, ref primitive.ModelViewMatrix);
                var dpt = PrimitiveType.Triangles;
                GL.ActiveTexture(SharedState.DefaultTextureUnit);

                // Use DrawArrays - first draw drop shadows, then draw actual font primitive
                if (primitive.ShadowVertexRepr.Count > 0)
                {
                    //int index = primitive.Font.FontData.CalculateMaxHeight();
                    GL.BindTexture(TextureTarget.Texture2D, primitive.Font.FontData.DropShadowFont.FontData.Pages[0].TextureID);
                    GL.DrawArrays(dpt, start, primitive.ShadowVertexRepr.Count);
                    start += primitive.ShadowVertexRepr.Count;
                }

                GL.BindTexture(TextureTarget.Texture2D, primitive.Font.FontData.Pages[0].TextureID);
                GL.DrawArrays(dpt, start, primitive.CurrentVertexRepr.Count);
                start += primitive.CurrentVertexRepr.Count;
            }

#if !OPENGL_ES
            GL.BindVertexArray(0);
#endif
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }