ravi.joshi53's picture

"Parameter is not valid" when using QFontBuilderConfiguration.TransformToCurrentOrthogProjection option

Hi,

I am trying to flip the text written using QuickFont. I have successfully flipped the entire game window by changing GL.Ortho values but QuickFont is not flipped. When I tried QFontBuilderConfiguration.TransformToCurrentOrthogProjection option, It shows me "System.ArgumentException Parameter is not valid" exception. Following is my code-

class Program : GameWindow
{
    //4:3
    const float LeftX = 0.0f;
    const float RightX = 16.0f;
    const float BottomY = 12.0f;
    const float TopY = 0.0f;
    const float FarZ = 1.0f;
    const float NearZ = -1.0f;
 
    QFont font;
 
    public Program()
        : base(800, 600, GraphicsMode.Default, "QuickFont Test")
    {
        VSync = VSyncMode.On;
        this.WindowBorder = WindowBorder.Fixed;
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        QFontBuilderConfiguration fontBuilderConfiguration = new QFontBuilderConfiguration();
        fontBuilderConfiguration.TransformToCurrentOrthogProjection = true;
 
        font = new QFont("Fonts/HappySans.ttf", 30, fontBuilderConfiguration);
 
        QFontRenderOptions fontRenderOptions = new QFontRenderOptions();
        fontRenderOptions.TransformToViewport = new TransformViewport(0, 0, RightX, BottomY);
        font.PushOptions(fontRenderOptions);
 
        GL.ClearColor(Color.AliceBlue);
        GL.Disable(EnableCap.DepthTest);
    }
 
    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);
 
        GL.Viewport(0, 0, Width, Height);
        GL.MatrixMode(MatrixMode.Projection);
        GL.LoadIdentity();
        GL.Ortho(RightX, LeftX, TopY, BottomY, FarZ, NearZ);
    }
 
    protected override void OnUpdateFrame(FrameEventArgs e)
    {
        base.OnUpdateFrame(e);
 
        if (Keyboard[OpenTK.Input.Key.Escape])
        {
            this.Exit();
        }
    }
 
    protected override void OnRenderFrame(FrameEventArgs e)
    {
        base.OnRenderFrame(e);
 
        GL.Clear(ClearBufferMask.ColorBufferBit);
        GL.MatrixMode(MatrixMode.Modelview);
        GL.LoadIdentity();
 
        GL.Begin(PrimitiveType.Triangles);
        GL.PushMatrix();
        GL.Color4(Color4.YellowGreen);
        GL.Vertex2(LeftX, TopY);
        GL.Vertex2(RightX, TopY);
        GL.Vertex2((LeftX + RightX) / 2, BottomY);
        GL.PopMatrix();
        GL.End();
 
        QFont.Begin();
        GL.PushMatrix();
        font.Print("QuickFont Test", QFontAlignment.Centre, new Vector2(RightX / 2, BottomY / 2));
        GL.PopMatrix();
        QFont.End();
 
        GL.Disable(EnableCap.Texture2D);
 
        SwapBuffers();
    }
}

I wanted to flip the text like this -