Fidchells_eye's picture

GL Text on screen

I am looking for a simple method of displaying text.

I was planning on using my earlier c++ version and converting it over but don't know what some of the functions are called.

I am planning on using Textprinter as a substitute if need be, but can't find it in OpenTK.Compatibility. Was the it renamed as something else?

Code:

protected int CreateBitmapFont(string fontName, int fontSize) //create font for openGL
{
//use stuff in OpenTK.Fonts??;
int basef = 0;

HFONT hFont; // the windows font <<-----------------------Needs C# version

//char *cfontname;
basef = GL.GenLists(96);
//WideCharToMultiByte(CP_UTF8, WC_DEFAULTCHAR, fontName, -1, *cfontname, sizeof(*cfontname), NULL, NULL);
//wcstombs();
string temp = fontName.ToLower();
if (temp == "symbol")
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, <<-----------------------Needs C# version
SYMBOL_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
fontName);
}
else
{
hFont = CreateFont(fontSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, <<-----------------------Needs C# version
ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY, FF_DONTCARE | DEFAULT_PITCH,
fontName);
}

if (!hFont)
return 0;

SelectObject(hDC, hFont); <<-----------------------Needs C# version
wglUseFontBitmaps(hDC, 32, 96, basef); <<-----------------------Needs C# version

return basef;
}

protected void RenderFont(int xPos, int yPos, int basef, string str) //create font for openGL
{
if ((basef == 0))
return;

GL.RasterPos2(xPos, yPos);
GL.PushAttrib(AttribMask.ListBit);
GL.ListBase(basef - 32);
GL.CallLists( (int)(str.Length * 2), ListNameType.UnsignedByte,IntPtr.Zero);
GL.PopAttrib();
}
protected void ReleaseFont(int basef) //remove font from memory
{
if (basef != 0)
GL.DeleteLists(basef, 96);
}


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
migueltk's picture

Do not complicate your life, use QuickFont

Fidchells_eye's picture

Thank you.

Just got to figure out how to flip text.