Search code examples
c#fontsopentk

OpenTK Text always white


I'm doing a 2D application in C# with OpenTK, to render the text I use the QuickFont library. My problem is that when I want to change the colour of the labels of my points, they don't change at all, they are always with colour white, and I don't know why.

Here is my code:

Color _labelColor = Color.Green; // For example
//... More code ...//
QFont.Begin();
_pointLabel = new QFont(new Font("Tahoma", 5f, FontStyle.Regular));
_pointLabel.Options.Colour = _labelColor; // Here is correct, it's Green
QFont.End();               

foreach (MyPoint p in _points)
{
    if (p.Visible)
    {
        // Draw labels only for visible points
        _pointLabel.Print(p.Label, new Vector2(p.X, p.Y));
    }
}

I want that the colour of my labels change with the var _labelColor, but it doesn't work. The colour of labels is always WHITE, even if I force to be green or another colour.

I think that this part of my code is correct, but I think that I need to configurate the OpenTK camera properly first, but I don't know how to do it.

To add information, if it helps, I'm working with normal textures and also sprite textures.

Any help will be very apreciated.

Sorry for my English.


Solution

  • I've found the answer, the problem was that I was loading the texture wrong, so I don't know why I can't set a color for the font.

    My load texture function right now is as follow:

    private int LoadTexture(Image img)
    {
        Bitmap bmp = new Bitmap(img);
        int id_textura = GL.GenTexture();
        GL.BindTexture(TextureTarget.Texture2D, id_textura);
    
        BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
    
        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);
    
        bmp.UnlockBits(bmp_data);
    
        // We haven't uploaded mipmaps, so disable mipmapping (otherwise the texture will not appear).
        // On newer video cards, we can use GL.GenerateMipmaps() or GL.Ext.GenerateMipmaps() to create
        // mipmaps automatically. In that case, use TextureMinFilter.LinearMipmapLinear to enable them.
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
    
        return id_textura;
    }
    

    The code that I wrote in my question is correct. I hope it helps to anyone.

    Sorry for my English.