Closed zengxiuhao closed 5 years ago
` 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();
}
}
}`
this is my code.It only displays "This is" .
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 https://github.com/opcon/QuickFont/blob/5331e5cdc113ee78d1aaa2f85ff86f21b9036a1c/QuickFont.Shared/Configuration/QFontBuilderConfiguration.cs#L232 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!
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?
This is my project picture. http://i4.bvimg.com/655055/dd471a153329454c.jpg
Another is text demo http://i4.bvimg.com/655055/2c4eec57bfa1503e.jpg
contras with text demo in previous code,my project calculate the modelview matrix by scale matrix rotate matrixtranslate.the font project matrix was replaced by camera's view matrix *project matrix.
public void DrawTexts(Matrix4 pViewMatrix,Matrix4 pProjectMatrix)
{
// calculate the ProjectionMatrix
_drawing.ProjectionMatrix = pViewMatrix * pProjectMatrix;
this.RefreshBuffers();
_drawing.Draw();
}
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
Closing as no further input
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?