Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese font seams doesn't work #41

Closed
zengxiuhao opened this issue Jul 5, 2018 · 9 comments
Closed

Chinese font seams doesn't work #41

zengxiuhao opened this issue Jul 5, 2018 · 9 comments

Comments

@zengxiuhao
Copy link

zengxiuhao commented Jul 5, 2018

thank you for your quickfont library!It makes me easier to complete the task.
Nowadays,I copy Sh0rti's code for test. It can normally display opentk window.
but when I modify the text by chinese character.It does't work, the window display the background color.
how can I do to display chinese character in opentk window?

@zengxiuhao zengxiuhao changed the title Chinese font seams does't work Chinese font seams doesn't work Jul 5, 2018
@zengxiuhao
Copy link
Author

zengxiuhao commented Jul 5, 2018

` using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using QuickFont;
using QuickFont.Configuration;

namespace DX.SpaceLineTrack.Test
{
static class Program
{
public static void Main(string[] args)
{
new Window().Run(60, 60);
}
}

class Window : GameWindow
{
    private QFont _myFont;
    private QFontDrawing _drawing;
    private Matrix4 _projectionMatrix;

    private QFontRenderOptions _qFontRenderOptions;

   

    public Window() : base(1280, 720)
    {

    }

    protected override void OnLoad(EventArgs e)
    {
        GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
        _projectionMatrix = Matrix4.CreateOrthographicOffCenter(ClientRectangle.X, ClientRectangle.Width, ClientRectangle.Y, ClientRectangle.Height, -1000.0f, 1000.0f);
        _myFont = new QFont(@"C:\Users\zxh\Desktop\test\Main\bin\Debug\Font\楷体_GB2312.ttf", 32, new QFontBuilderConfiguration(true));


        _qFontRenderOptions = new QFontRenderOptions() { Colour = System.Drawing.Color.White };
        _drawing = new QFontDrawing();
    }

    protected override void OnRenderFrame(FrameEventArgs e)
    {
        GL.Clear(ClearBufferMask.ColorBufferBit);
        GL.ClearColor(Color4.CornflowerBlue);

        _drawing.DrawingPrimitives.Clear();
        _drawing.ProjectionMatrix = _projectionMatrix;
        _drawing.Print(_myFont, "this is 我的第一个程序", new Vector3(0,0,0), QFontAlignment.Left, _qFontRenderOptions);

        _drawing.DrawingPrimitives[0].ModelViewMatrix =Matrix4.CreateScale(1.0f)* Matrix4.CreateRotationX(MathHelper.DegreesToRadians(0))*Matrix4.CreateTranslation(new Vector3(400, 400, -0));
        _drawing.RefreshBuffers();
        _drawing.Draw();

        this.SwapBuffers();
    }
}

}`

@zengxiuhao
Copy link
Author

this is my code.It only displays "This is" .

@opcon
Copy link
Owner

opcon commented Jul 6, 2018

Hi @zengxiuhao,

QuickFont works by loading font characters into a texture, and then draws the characters from that texture.

This means that we need to load every character we want to use into the font texture before we can use it.

There are 2 solutions to this:

  1. If you know exactly which characters you need, you can preload them at the start. This is how QuickFont currently works; see the BuildCharacterSet function

    private static string BuildCharacterSet(CharacterSet set)
    and other related variables in the QFontBuilderConfiguration class.
    This means that it loads every possible character used by a program in advance - it does not support loading new characters on the fly.
    This works okay for the Latin alphabet, but as soon as you need to use other character sets, or unicode characters, the amount of characters you need to preload becomes huge, and it's not feasible to do it this way.

  2. The other option is to load new characters into the font texture whenever they are seen for the first time, rather than all at once initially. This means that if we try to draw the string "Hello", our font texture will now contain the characters H, e, l, and o.
    This solution is much more general, and should be preferred over Solution 1, however it is harder to implement.

At the moment, QuickFont only supports Solution 1, which means that all characters used in the program need to be preloaded.
It should be possible to support Solution 2 as well, however I do not have time at the moment to implement it myself. I am happy to help and give advice to you (or someone else) if you decide to implement it!

@zengxiuhao
Copy link
Author

Hi!opcon .Recently,I have a problem where the text don't display clearly in the Opentk's window.
But in the previous code this page ,it can show me clearly.I don't know how to resolve it . can you give me some advise?

@zengxiuhao
Copy link
Author

This is my project picture.
http://i4.bvimg.com/655055/dd471a153329454c.jpg

Another is text demo
http://i4.bvimg.com/655055/2c4eec57bfa1503e.jpg

@zengxiuhao
Copy link
Author

contras with text demo in previous code,my project calculate the modelview matrix by scale matrix * rotate matrix*translate.the font project matrix was replaced by camera's view matrix *project matrix.

@zengxiuhao
Copy link
Author

    public  void DrawTexts(Matrix4 pViewMatrix,Matrix4 pProjectMatrix)
    {
        // calculate the ProjectionMatrix
        _drawing.ProjectionMatrix = pViewMatrix * pProjectMatrix;
        this.RefreshBuffers();
        _drawing.Draw();
    }

@opcon
Copy link
Owner

opcon commented Aug 13, 2018

Hi @zengxiuhao,

I'm sorry, but I don't have enough information to help you solve this problem.
It could be that you are drawing the font at a specific size, but then displaying it at a different size (by scaling it), which could make it blurry.

One fix could be increasing the font size when you create the font itself - although this will take more memory.

If you are able to upload a minimal working example of this issue that I can compile locally, I can take a deeper look into it.

Cheers

@opcon
Copy link
Owner

opcon commented Apr 24, 2019

Closing as no further input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants