コード例 #1
0
ファイル: GLFont.cs プロジェクト: RcSepp/global_view
        protected override void DrawString(float x, float y, float w, string text, System.Drawing.Size backbufferSize, Color4 color)
        {
            // Fonts look best when they are drawn on integer positions (so they don't have to be interpolated over multiple pixels)
            float linestart = x = (float)(int)x;

            y = (float)(int)y;

            // Bind texture and save the size of a pixel in the texture's coordinate system
            fontshader.Bind();
            GL.Uniform4(fontshader_coloruniform, color);
            Common.meshQuad.Bind(fontshader, texture);

            /*if(sdr.InvTexSizeUniform)
             *      gl.uniform2f(sdr.InvTexSizeUniform, 1.0 / texture.image.width, 1.0 / texture.image.height);*/

            for (int i = 0; i < text.Length; ++i)
            {
                char chr = text[i];
                if (chr == '\n')
                {
                    x  = linestart;
                    y += (float)lineHeight;
                }
                if (!char.IsControl(chr))
                {
                    Vector2 charsize = new Vector2((float)charBounds[(int)chr].Width, (float)charBounds[(int)chr].Height);

                    // Transform texture quad texture coordinates to select the letter
                    Matrix3 texcoordtrans = Matrix3.Identity;
                    texcoordtrans *= GLTextFont.Matrix3_CreateScale(charsize.X / texture.width, (charsize.Y - 2.0f) / texture.height);
                    texcoordtrans *= GLTextFont.Matrix3_CreateTranslation(((float)charBounds[(int)chr].X - 0.5f) / texture.width, ((float)charBounds[(int)chr].Y - 0.5f) / texture.height);
                    GL.UniformMatrix3(fontshader.defparams.textransform, false, ref texcoordtrans);

                    /*// Save character bounds so that characters can be clamped to avoid bleeding over of neighboring characters
                     * if(sdr.texboundsUniform)
                     *      gl.uniform1fv(sdr.texboundsUniform, [charpos[0] / texture.image.width, (charpos[0] + charsize[0]) / texture.image.width,
                     *              charpos[1] / texture.image.height, (charpos[1] + charsize[1]) / texture.image.height]);*/

                    // Transform texture quad vertices to position the letter
                    Matrix4 trans = Matrix4.Identity;
                    trans *= Matrix4.CreateScale(2.0f * charsize.X / backbufferSize.Width, (2.0f * charsize.Y - 4.0f) / backbufferSize.Height, 1.0f);
                    trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (x + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (y - 0.25f + charsize.Y) / backbufferSize.Height, w);
                    GL.UniformMatrix4(fontshader.defparams.worldviewproj, false, ref trans);

                    Common.meshQuad.Draw();
                    x += charsize.X;
                }
                else
                {
                    x += blankWidth;
                }
            }
        }
コード例 #2
0
ファイル: GLFont.cs プロジェクト: RcSepp/global_view
        protected override void DrawString(float x, float y, float w, string strnumber, System.Drawing.Size backbufferSize, Color4 color)
        {
            // Fonts look best when they are drawn on integer positions (so they don't have to be interpolated over multiple pixels)
            x = (float)(int)x;
            y = (float)(int)y;

            // Bind texture and save the size of a pixel in the texture's coordinate system
            fontshader.Bind();
            GL.Uniform4(fontshader_coloruniform, color);
            meshquad.Bind(fontshader, texture);

            /*if(sdr.InvTexSizeUniform)
             *      gl.uniform2f(sdr.InvTexSizeUniform, 1.0 / texture.image.width, 1.0 / texture.image.height);*/

            for (int i = 0; i < strnumber.Length; ++i)
            {
                int     digit      = strnumber[i] - '0';
                Vector2 digit_pos  = new Vector2(fontdef.charpos_x[digit], fontdef.charpos_y[0]);
                Vector2 digit_size = new Vector2(fontdef.charpos_x[digit + 1] - fontdef.charpos_x[digit], fontdef.charpos_y[1] - fontdef.charpos_y[0]);

                // Transform texture quad texture coordinates to select the letter
                Matrix3 texcoordtrans = Matrix3.Identity;
                //texcoordtrans *= Matrix3_CreateScale(digit_size.X / texture.width, digit_size.Y / texture.height);
                texcoordtrans *= GLTextFont.Matrix3_CreateScale(digit_size.X / texture.width, (digit_size.Y - 2.0f) / texture.height);
                texcoordtrans *= Matrix3_CreateTranslation(digit_pos.X / texture.width, digit_pos.Y / texture.height);
                GL.UniformMatrix3(fontshader.defparams.textransform, false, ref texcoordtrans);

                /*// Save digit bounds so that digits can be clamped to avoid bleeding over of neighboring digits
                 * if(sdr.texboundsUniform)
                 *      gl.uniform1fv(sdr.texboundsUniform, [digit_pos[0] / texture.image.width, (digit_pos[0] + digit_size[0]) / texture.image.width,
                 *              digit_pos[1] / texture.image.height, (digit_pos[1] + digit_size[1]) / texture.image.height]);*/

                if (fixedwidth != 0)
                {
                    digit_size.X = fixedwidth;
                }

                // Transform texture quad vertices to position the letter
                Matrix4 trans = Matrix4.Identity;
                trans *= Matrix4.CreateScale(2.0f * digit_size.X / backbufferSize.Width, (2.0f * digit_size.Y - 4.0f) / backbufferSize.Height, 1.0f);
                trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (x + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (y + texture.height) / backbufferSize.Height, w);
                GL.UniformMatrix4(fontshader.defparams.worldviewproj, false, ref trans);

                meshquad.Draw();
                x += digit_size.X;
            }
        }
コード例 #3
0
ファイル: GLFont.cs プロジェクト: RcSepp/global_view
        protected override void DrawString(float x, float y, float w, string text, System.Drawing.Size backbufferSize, Color4 color)
        {
            // Fonts look best when they are drawn on integer positions (so they don't have to be interpolated over multiple pixels)
            float linestart = x = (float)(int)x;

            y = (float)(int)y;

            // Bind texture and save the size of a pixel in the texture's coordinate system
            fontshader.Bind();
            GL.Uniform4(fontshader_coloruniform, color);
            meshquad.Bind(fontshader, texture);

            /*if(sdr.InvTexSizeUniform)
             *      gl.uniform2f(sdr.InvTexSizeUniform, 1.0 / texture.image.width, 1.0 / texture.image.height);*/

            for (int i = 0; i < text.Length; ++i)
            {
                char chr = text[i];
                if (chr == '\n')
                {
                    x  = linestart;
                    y += charsize.Y;
                }
                if (chr != ' ')
                {
                    Vector2 charpos;
                    switch (chr)
                    {
                    case '-': charpos = new Vector2((float)(0 * charsize.X), (float)(3 * charsize.Y)); break;

                    case '/': charpos = new Vector2((float)(1 * charsize.X), (float)(3 * charsize.Y)); break;

                    case ':': charpos = new Vector2((float)(2 * charsize.X), (float)(3 * charsize.Y)); break;

                    case '>': charpos = new Vector2((float)(3 * charsize.X), (float)(3 * charsize.Y)); break;

                    case '(': charpos = new Vector2((float)(4 * charsize.X), (float)(3 * charsize.Y)); break;

                    case ')': charpos = new Vector2((float)(5 * charsize.X), (float)(3 * charsize.Y)); break;

                    case '%': charpos = new Vector2((float)(6 * charsize.X), (float)(3 * charsize.Y)); break;

                    case '.': charpos = new Vector2((float)(7 * charsize.X), (float)(3 * charsize.Y)); break;

                    default:
                        if (char.IsNumber(chr))
                        {
                            charpos = new Vector2((float)(chr - '0') * charsize.X, (float)(2 * charsize.Y));                             // Character is digit
                        }
                        else
                        {
                            charpos = new Vector2((float)(char.ToLower(chr) - 'a') * charsize.X, (float)(char.IsUpper(chr) ? 0 : 1) * charsize.Y);                             // Character is letter
                        }
                        break;
                    }

                    // Transform texture quad texture coordinates to select the letter
                    Matrix3 texcoordtrans = Matrix3.Identity;
                    //texcoordtrans *= Matrix3_CreateScale(charsize.X / texture.width, charsize.Y / texture.height);
                    texcoordtrans *= GLTextFont.Matrix3_CreateScale(charsize.X / texture.width, (charsize.Y - 2.0f) / texture.height);
                    texcoordtrans *= Matrix3_CreateTranslation((charpos.X - 0.5f) / texture.width, (charpos.Y - 0.5f) / texture.height);
                    GL.UniformMatrix3(fontshader.defparams.textransform, false, ref texcoordtrans);

                    /*// Save character bounds so that characters can be clamped to avoid bleeding over of neighboring characters
                     * if(sdr.texboundsUniform)
                     *      gl.uniform1fv(sdr.texboundsUniform, [charpos[0] / texture.image.width, (charpos[0] + charsize[0]) / texture.image.width,
                     *              charpos[1] / texture.image.height, (charpos[1] + charsize[1]) / texture.image.height]);*/

                    // Transform texture quad vertices to position the letter
                    Matrix4 trans = Matrix4.Identity;
                    trans *= Matrix4.CreateScale(2.0f * charsize.X / backbufferSize.Width, (2.0f * charsize.Y - 4.0f) / backbufferSize.Height, 1.0f);
                    trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (x + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (y + charsize.Y) / backbufferSize.Height, w);
                    GL.UniformMatrix4(fontshader.defparams.worldviewproj, false, ref trans);

                    meshquad.Draw();
                }
                x += charsize.X;
            }
        }